mirror of
https://github.com/status-im/evmc.git
synced 2025-02-23 08:28:15 +00:00
EVM-C: Move ABI version from factory to instance
This commit is contained in:
parent
c43a59ead0
commit
61d533aad7
@ -128,10 +128,10 @@ static const struct evm_host example_host = {
|
||||
/// Example how the API is supposed to be used.
|
||||
int main(int argc, char *argv[]) {
|
||||
struct evm_factory factory = examplevm_get_factory();
|
||||
if (factory.abi_version != EVM_ABI_VERSION)
|
||||
return 1; // Incompatible ABI version.
|
||||
|
||||
struct evm_instance* jit = factory.create(&example_host);
|
||||
struct evm_instance* jit = factory.create();
|
||||
if (jit->abi_version != EVM_ABI_VERSION)
|
||||
return 1; // Incompatible ABI version.
|
||||
|
||||
uint8_t const code[] = "Place some EVM bytecode here";
|
||||
const size_t code_size = sizeof(code);
|
||||
|
@ -112,17 +112,21 @@ static struct evm_result execute(struct evm_instance* instance,
|
||||
|
||||
static struct evm_instance* evm_create(const struct evm_host* host)
|
||||
{
|
||||
struct evm_instance init = {
|
||||
.abi_version = EVM_ABI_VERSION,
|
||||
.destroy = evm_destroy,
|
||||
.execute = execute,
|
||||
.set_option = evm_set_option
|
||||
};
|
||||
struct examplevm* vm = calloc(1, sizeof(struct examplevm));
|
||||
struct evm_instance* interface = &vm->instance;
|
||||
interface->destroy = evm_destroy;
|
||||
interface->execute = execute;
|
||||
interface->set_option = evm_set_option;
|
||||
memcpy(interface, &init, sizeof(init));
|
||||
vm->host = host;
|
||||
return interface;
|
||||
}
|
||||
|
||||
struct evm_factory examplevm_get_factory()
|
||||
{
|
||||
struct evm_factory factory = {EVM_ABI_VERSION, evm_create};
|
||||
struct evm_factory factory = {evm_create};
|
||||
return factory;
|
||||
}
|
||||
|
@ -437,6 +437,13 @@ typedef void (*evm_prepare_code_fn)(struct evm_instance* instance,
|
||||
///
|
||||
/// Defines the base struct of the EVM implementation.
|
||||
struct evm_instance {
|
||||
|
||||
/// EVM-C ABI version implemented by the EVM instance.
|
||||
///
|
||||
/// For future use to detect ABI incompatibilities. The EVM-C ABI version
|
||||
/// represented by this file is in ::EVM_ABI_VERSION.
|
||||
const int abi_version;
|
||||
|
||||
/// Pointer to function destroying the EVM instance.
|
||||
evm_destroy_fn destroy;
|
||||
|
||||
@ -463,11 +470,6 @@ struct evm_instance {
|
||||
///
|
||||
/// Provides ABI protection and method to create an EVM instance.
|
||||
struct evm_factory {
|
||||
/// EVM-C ABI version implemented by the EVM factory and instance.
|
||||
///
|
||||
/// For future use to detect ABI incompatibilities. The EVM-C ABI version
|
||||
/// represented by this file is in ::EVM_ABI_VERSION.
|
||||
int abi_version;
|
||||
|
||||
/// Pointer to function creating and initializing the EVM instance.
|
||||
evm_create_fn create;
|
||||
|
Loading…
x
Reference in New Issue
Block a user