From 3c86a6b93487d9fa321b2a45ca58c5020e374524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Wed, 29 Aug 2018 23:00:11 +0200 Subject: [PATCH] Return result from call_fn This changes the evmc_call_fn signature to return evmc_result object instead of getting result as an output parameter. --- bindings/go/evmc/host.go | 4 ++-- examples/capi.c | 7 +++---- include/evmc/evmc.h | 14 +++++--------- test/vmtester/mock_context.cpp | 6 ++++-- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/bindings/go/evmc/host.go b/bindings/go/evmc/host.go index 47f4f63..f3b804b 100644 --- a/bindings/go/evmc/host.go +++ b/bindings/go/evmc/host.go @@ -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 } diff --git a/examples/capi.c b/examples/capi.c index 55383bc..8b23226 100644 --- a/examples/capi.c +++ b/examples/capi.c @@ -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) diff --git a/include/evmc/evmc.h b/include/evmc/evmc.h index e0c3ce5..bd81912 100644 --- a/include/evmc/evmc.h +++ b/include/evmc/evmc.h @@ -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. diff --git a/test/vmtester/mock_context.cpp b/test/vmtester/mock_context.cpp index bc59548..eb12f0e 100644 --- a/test/vmtester/mock_context.cpp +++ b/test/vmtester/mock_context.cpp @@ -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)