mirror of
https://github.com/status-im/evmc.git
synced 2025-02-23 08:28:15 +00:00
EVM-C: Attach result_release function to the result itself
This commit is contained in:
parent
6f88571130
commit
8b9867c971
@ -93,6 +93,6 @@ int main(int argc, char *argv[]) {
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
intf.release_result(&result);
|
result.release(&result);
|
||||||
intf.destroy(jit);
|
intf.destroy(jit);
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,10 @@ int evm_set_option(struct evm_instance* evm,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void evm_release_result(struct evm_result const* result)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
static struct evm_result evm_execute(struct evm_instance* instance,
|
static struct evm_result evm_execute(struct evm_instance* instance,
|
||||||
struct evm_env* env,
|
struct evm_env* env,
|
||||||
enum evm_mode mode,
|
enum evm_mode mode,
|
||||||
@ -57,16 +61,13 @@ static struct evm_result evm_execute(struct evm_instance* instance,
|
|||||||
|
|
||||||
// Execute code and refer to callbacks: instance->query_fn()
|
// Execute code and refer to callbacks: instance->query_fn()
|
||||||
|
|
||||||
|
ret.release = evm_release_result;
|
||||||
ret.code = EVM_FAILURE;
|
ret.code = EVM_FAILURE;
|
||||||
ret.gas_left = 0;
|
ret.gas_left = 0;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void evm_release_result(struct evm_result const* result)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
struct evm_interface examplevm_get_interface()
|
struct evm_interface examplevm_get_interface()
|
||||||
{
|
{
|
||||||
struct evm_interface intf;
|
struct evm_interface intf;
|
||||||
@ -75,7 +76,6 @@ struct evm_interface examplevm_get_interface()
|
|||||||
intf.create = evm_create;
|
intf.create = evm_create;
|
||||||
intf.destroy = evm_destroy;
|
intf.destroy = evm_destroy;
|
||||||
intf.execute = evm_execute;
|
intf.execute = evm_execute;
|
||||||
intf.release_result = evm_release_result;
|
|
||||||
intf.set_option = evm_set_option;
|
intf.set_option = evm_set_option;
|
||||||
return intf;
|
return intf;
|
||||||
}
|
}
|
@ -55,6 +55,18 @@ enum evm_result_code {
|
|||||||
EVM_STACK_UNDERFLOW = 6,
|
EVM_STACK_UNDERFLOW = 6,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct evm_result;
|
||||||
|
|
||||||
|
/// Releases resources assigned to an execution result.
|
||||||
|
///
|
||||||
|
/// This function releases memory (and other resources, if any) assigned to the
|
||||||
|
/// specified execution result making the result object invalid.
|
||||||
|
///
|
||||||
|
/// @param result The execution result which resource are to be released. The
|
||||||
|
/// result itself it not modified by this function, but becomes
|
||||||
|
/// invalid and user should discard it as well.
|
||||||
|
typedef void (*evm_release_result_fn)(struct evm_result const* result);
|
||||||
|
|
||||||
/// The EVM code execution result.
|
/// The EVM code execution result.
|
||||||
struct evm_result {
|
struct evm_result {
|
||||||
/// The execution result code.
|
/// The execution result code.
|
||||||
@ -83,6 +95,13 @@ struct evm_result {
|
|||||||
/// The error message explaining the result code.
|
/// The error message explaining the result code.
|
||||||
char const* error_message;
|
char const* error_message;
|
||||||
|
|
||||||
|
/// The pointer to the result release implementation.
|
||||||
|
///
|
||||||
|
/// This function pointer must be set by the VM implementation and works
|
||||||
|
/// similary to C++ virtual destructor. Attaching the releaser to the result
|
||||||
|
/// itself allows VM composition.
|
||||||
|
evm_release_result_fn release;
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -370,15 +389,6 @@ typedef struct evm_result (*evm_execute_fn)(struct evm_instance* instance,
|
|||||||
size_t input_size,
|
size_t input_size,
|
||||||
struct evm_uint256be value);
|
struct evm_uint256be value);
|
||||||
|
|
||||||
/// Releases resources assigned to an execution result.
|
|
||||||
///
|
|
||||||
/// This function releases memory (and other resources, if any) assigned to the
|
|
||||||
/// specified execution result making the result object invalid.
|
|
||||||
///
|
|
||||||
/// @param result The execution result which resource are to be released. The
|
|
||||||
/// result itself it not modified by this function, but becomes
|
|
||||||
/// invalid and user should discard it as well.
|
|
||||||
typedef void (*evm_release_result_fn)(struct evm_result const* result);
|
|
||||||
|
|
||||||
/// Status of a code in VM. Useful for JIT-like implementations.
|
/// Status of a code in VM. Useful for JIT-like implementations.
|
||||||
enum evm_code_status {
|
enum evm_code_status {
|
||||||
@ -427,9 +437,6 @@ struct evm_interface {
|
|||||||
/// Pointer to function execuing a code in a VM.
|
/// Pointer to function execuing a code in a VM.
|
||||||
evm_execute_fn execute;
|
evm_execute_fn execute;
|
||||||
|
|
||||||
/// Pointer to function releasing an execution result.
|
|
||||||
evm_release_result_fn release_result;
|
|
||||||
|
|
||||||
/// Optional pointer to function returning a status of a code.
|
/// Optional pointer to function returning a status of a code.
|
||||||
///
|
///
|
||||||
/// If the VM does not support this feature the pointer can be NULL.
|
/// If the VM does not support this feature the pointer can be NULL.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user