From 575337b44978922dc680b197a6881eb3be2214f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 22 Dec 2016 12:10:31 +0100 Subject: [PATCH] EVM-C: pass callback argument explicitly by pointer We try to avoid C ABI complex rules like passing structs by value to increase portability. --- examples/capi.c | 22 +++++++++++----------- include/evm.h | 10 +++++----- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/capi.c b/examples/capi.c index 0afdd43..f87e408 100644 --- a/examples/capi.c +++ b/examples/capi.c @@ -16,16 +16,16 @@ struct evm_uint160be address(struct evm_env* env) return ret; } -union evm_variant query(struct evm_env* env, - enum evm_query_key key, - union evm_variant arg) { +static union evm_variant query(struct evm_env* env, + enum evm_query_key key, + const union evm_variant* arg) { union evm_variant result; printf("EVM-C: QUERY %d\n", key); switch (key) { case EVM_GAS_LIMIT: result.int64 = 314; break; case EVM_BALANCE: - result.uint256be = balance(env, arg.address); + result.uint256be = balance(env, arg->address); break; case EVM_ADDRESS: @@ -37,20 +37,20 @@ union evm_variant query(struct evm_env* env, return result; } -void update(struct evm_env* env, - enum evm_update_key key, - union evm_variant arg1, - union evm_variant arg2) +static void update(struct evm_env* env, + enum evm_update_key key, + const union evm_variant* arg1, + const union evm_variant* arg2) { printf("EVM-C: UPDATE %d\n", key); } -int64_t call( +static int64_t call( struct evm_env* _opaqueEnv, enum evm_call_kind _kind, int64_t _gas, - struct evm_uint160be _address, - struct evm_uint256be _value, + const struct evm_uint160be* _address, + const struct evm_uint256be* _value, uint8_t const* _inputData, size_t _inputSize, uint8_t* _outputData, diff --git a/include/evm.h b/include/evm.h index 94e123c..b97096f 100644 --- a/include/evm.h +++ b/include/evm.h @@ -231,7 +231,7 @@ union evm_variant { /// typedef union evm_variant (*evm_query_fn)(struct evm_env* env, enum evm_query_key key, - union evm_variant arg); + const union evm_variant* arg); /// The update callback key. enum evm_update_key { @@ -269,8 +269,8 @@ enum evm_update_key { /// @param arg2 n/a typedef void (*evm_update_fn)(struct evm_env* env, enum evm_update_key key, - union evm_variant arg1, - union evm_variant arg2); + const union evm_variant* arg1, + const union evm_variant* arg2); /// The kind of call-like instruction. enum evm_call_kind { @@ -308,8 +308,8 @@ typedef int64_t (*evm_call_fn)( struct evm_env* env, enum evm_call_kind kind, int64_t gas, - struct evm_uint160be address, - struct evm_uint256be value, + const struct evm_uint160be* address, + const struct evm_uint256be* value, uint8_t const* input, size_t input_size, uint8_t* output,