diff --git a/examples/capi.c b/examples/capi.c index 4c8a9ef..fd7c802 100644 --- a/examples/capi.c +++ b/examples/capi.c @@ -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); diff --git a/include/evmc/helpers.h b/include/evmc/helpers.h index 321da2c..da0f687 100644 --- a/include/evmc/helpers.h +++ b/include/evmc/helpers.h @@ -17,6 +17,14 @@ #include +/** + * 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. * diff --git a/lib/loader/loader.c b/lib/loader/loader.c index 3156f2f..d4fa12a 100644 --- a/lib/loader/loader.c +++ b/lib/loader/loader.c @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -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;