Return size_t from get_code_size() directly

This commit is contained in:
Paweł Bylica 2018-09-09 10:00:15 +02:00
parent 67441020a4
commit b0d0bc035b
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
4 changed files with 12 additions and 28 deletions

View File

@ -75,8 +75,8 @@ static inline void go_exported_functions_type_checks()
uint256be = getBalance(context, address);
evmc_get_code_size_fn get_code_size_fn = NULL;
bool_flag = get_code_size_fn(&size, context, address);
bool_flag = getCodeSize(&size, context, address);
size = get_code_size_fn(context, address);
size = getCodeSize(context, address);
evmc_get_code_hash_fn get_code_hash_fn = NULL;
bool_flag = get_code_hash_fn(&bytes32, context, address);

View File

@ -74,7 +74,7 @@ type HostContext interface {
GetStorage(addr common.Address, key common.Hash) common.Hash
SetStorage(addr common.Address, key common.Hash, value common.Hash) StorageStatus
GetBalance(addr common.Address) common.Hash
GetCodeSize(addr common.Address) (int, error)
GetCodeSize(addr common.Address) int
GetCodeHash(addr common.Address) (common.Hash, error)
GetCode(addr common.Address) []byte
Selfdestruct(addr common.Address, beneficiary common.Address)
@ -116,15 +116,10 @@ func getBalance(pCtx unsafe.Pointer, pAddr *C.evmc_address) C.evmc_uint256be {
}
//export getCodeSize
func getCodeSize(pResult *C.size_t, pCtx unsafe.Pointer, pAddr *C.evmc_address) C.bool {
func getCodeSize(pCtx unsafe.Pointer, pAddr *C.evmc_address) C.size_t {
idx := int((*C.struct_extended_context)(pCtx).index)
ctx := getHostContext(idx)
codeSize, err := ctx.GetCodeSize(goAddress(*pAddr))
if err != nil {
return false
}
*pResult = C.size_t(codeSize)
return true
return C.size_t(ctx.GetCodeSize(goAddress(*pAddr)))
}
//export getCodeHash

View File

@ -71,16 +71,13 @@ static evmc_uint256be get_balance(evmc_context* context, const evmc_address* add
return {};
}
static bool get_code_size(size_t* result, evmc_context* context, const evmc_address* address)
static size_t get_code_size(evmc_context* context, const evmc_address* address)
{
example_host_context* host = static_cast<example_host_context*>(context);
auto it = host->accounts.find(*address);
if (it != host->accounts.end())
{
*result = it->second.code_size;
return true;
}
return false;
return it->second.code_size;
return 0;
}
static bool get_code_hash(evmc_bytes32* result, evmc_context* context, const evmc_address* address)

View File

@ -498,19 +498,11 @@ typedef evmc_uint256be (*evmc_get_balance_fn)(struct evmc_context* context,
* This callback function is used by a VM to get the size of the code stored
* in the account at the given address.
*
* @param[out] result The pointer to the place where to put the result code size.
* The pointed memory is only modified when the function returns true.
* The pointer MUST NOT be null.
* @param context The pointer to the Host execution context.
* @param address The address of the account.
* @return If the account exists the size of its code is put at the location
* pointed by @p result and true is returned.
* If the account does not exist false is returned without
* modifying the memory pointed by @p result.
* @param context The pointer to the Host execution context.
* @param address The address of the account.
* @return The size of the code in the account or 0 if the account does not exist.
*/
typedef bool (*evmc_get_code_size_fn)(size_t* result,
struct evmc_context* context,
const evmc_address* address);
typedef size_t (*evmc_get_code_size_fn)(struct evmc_context* context, const evmc_address* address);
/**
* Get code size callback function.