Merge pull request #109 from ethereum/call-return-result

Return result from call_fn
This commit is contained in:
Alex Beregszaszi 2018-08-30 12:24:54 +01:00 committed by GitHub
commit cd7ccf8906
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 17 deletions

View File

@ -208,7 +208,7 @@ func emitLog(pCtx unsafe.Pointer, pAddr *C.struct_evmc_address, pData unsafe.Poi
}
//export call
func call(pResult *C.struct_evmc_result, pCtx unsafe.Pointer, msg *C.struct_evmc_message) {
func call(pCtx unsafe.Pointer, msg *C.struct_evmc_message) C.struct_evmc_result {
idx := int((*C.struct_extended_context)(pCtx).index)
ctx := getHostContext(idx)
@ -234,5 +234,5 @@ func call(pResult *C.struct_evmc_result, pCtx unsafe.Pointer, msg *C.struct_evmc
result.release = (C.evmc_release_result_fn)(C.evmc_go_free_result_output)
}
*pResult = result
return result
}

View File

@ -118,13 +118,12 @@ static void selfdestruct(struct evmc_context* context,
printf("\n");
}
static void call(struct evmc_result* result,
struct evmc_context* context,
const struct evmc_message* msg)
static struct evmc_result call(struct evmc_context* context, const struct evmc_message* msg)
{
(void)context;
printf("EVM-C: CALL (depth: %d)\n", msg->depth);
result->status_code = EVMC_FAILURE;
struct evmc_result result = {.status_code = EVMC_FAILURE};
return result;
}
static void get_tx_context(struct evmc_tx_context* result, struct evmc_context* context)

View File

@ -574,16 +574,12 @@ typedef void (*evmc_emit_log_fn)(struct evmc_context* context,
/**
* Pointer to the callback function supporting EVM calls.
*
* @param[out] result The result of the call. The result object is not
* initialized by the EVM, the Client MUST correctly
* initialize all expected fields of the structure.
* @param context The pointer to the Host execution context.
* @see ::evmc_context.
* @param msg Call parameters. @see ::evmc_message.
* @param context The pointer to the Host execution context.
* @param msg The call parameters.
* @return The result of the call.
*/
typedef void (*evmc_call_fn)(struct evmc_result* result,
struct evmc_context* context,
const struct evmc_message* msg);
typedef struct evmc_result (*evmc_call_fn)(struct evmc_context* context,
const struct evmc_message* msg);
/**
* The context interface.

View File

@ -88,11 +88,13 @@ static void selfdestruct(evmc_context* context,
(void)beneficiary;
}
static void call(evmc_result* result, evmc_context* context, const evmc_message* msg)
static evmc_result call(evmc_context* context, const evmc_message* msg)
{
(void)context;
(void)msg;
result->status_code = EVMC_FAILURE;
evmc_result result{};
result.status_code = EVMC_FAILURE;
return result;
}
static void get_tx_context(evmc_tx_context* result, evmc_context* context)

View File

@ -45,10 +45,14 @@ TEST_F(evmc_vm_test, execute)
// Validate some constraints
if (result.status_code != EVMC_SUCCESS && result.status_code != EVMC_REVERT)
{
EXPECT_EQ(result.gas_left, 0);
}
if (result.output_data == NULL)
{
EXPECT_EQ(result.output_size, 0);
}
if (result.release)
result.release(&result);