Add evmc_is_abi_compatible helper

This commit is contained in:
Alex Beregszaszi 2018-08-20 14:46:31 +01:00
parent 58a8d2295d
commit 3fe4f28867
3 changed files with 12 additions and 3 deletions

View File

@ -167,8 +167,8 @@ static const struct evmc_context_fn_table ctx_fn_table = {
int main()
{
struct evmc_instance* vm = evmc_create_examplevm();
if (vm->abi_version != EVMC_ABI_VERSION)
return 1; // Incompatible ABI version.
if (!evmc_is_abi_compatible(vm))
return 1;
const uint8_t code[] = "Place some EVM bytecode here";
const size_t code_size = sizeof(code);

View File

@ -17,6 +17,14 @@
#include <evmc/evmc.h>
/**
* Returns true if the instance has a compatible ABI version.
*/
static inline int evmc_is_abi_compatible(struct evmc_instance *instance)
{
return instance->abi_version == EVMC_ABI_VERSION;
}
/**
* Destroys the VM instance.
*

View File

@ -5,6 +5,7 @@
#include <evmc/loader.h>
#include <evmc/evmc.h>
#include <evmc/helpers.h>
#include <stdint.h>
#include <string.h>
@ -137,7 +138,7 @@ struct evmc_instance* evmc_load_and_create(const char* filename, enum evmc_loade
return NULL;
}
if (instance->abi_version != EVMC_ABI_VERSION)
if (!evmc_is_abi_compatible(instance))
{
*error_code = EVMC_LOADER_ABI_VERSION_MISMATCH;
return NULL;