mirror of https://github.com/status-im/evmc.git
loader: Make error_code in evmc_load_and_create() optional
This commit is contained in:
parent
9510206aa1
commit
81db59cede
|
@ -212,22 +212,29 @@ struct evmc_instance* evmc_load_and_create(const char* filename,
|
||||||
if (!create_fn)
|
if (!create_fn)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
enum evmc_loader_error_code ec = EVMC_LOADER_SUCCESS;
|
||||||
|
|
||||||
struct evmc_instance* instance = create_fn();
|
struct evmc_instance* instance = create_fn();
|
||||||
if (!instance)
|
if (!instance)
|
||||||
{
|
{
|
||||||
*error_code = set_error(EVMC_LOADER_INSTANCE_CREATION_FAILURE,
|
ec = set_error(EVMC_LOADER_INSTANCE_CREATION_FAILURE,
|
||||||
"creating EVMC instance of %s has failed", filename);
|
"creating EVMC instance of %s has failed", filename);
|
||||||
return NULL;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!evmc_is_abi_compatible(instance))
|
if (!evmc_is_abi_compatible(instance))
|
||||||
{
|
{
|
||||||
|
ec = set_error(EVMC_LOADER_ABI_VERSION_MISMATCH,
|
||||||
|
"EVMC ABI version %d of %s mismatches the expected version %d",
|
||||||
|
instance->abi_version, filename, EVMC_ABI_VERSION);
|
||||||
evmc_destroy(instance);
|
evmc_destroy(instance);
|
||||||
*error_code = set_error(EVMC_LOADER_ABI_VERSION_MISMATCH,
|
instance = NULL;
|
||||||
"EVMC ABI version %d of %s mismatches the expected version %d",
|
goto exit;
|
||||||
instance->abi_version, filename, EVMC_ABI_VERSION);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exit:
|
||||||
|
if (error_code)
|
||||||
|
*error_code = ec;
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
|
@ -301,6 +301,11 @@ TEST_F(loader, load_and_create_failure)
|
||||||
EXPECT_TRUE(vm == nullptr);
|
EXPECT_TRUE(vm == nullptr);
|
||||||
EXPECT_EQ(ec, EVMC_LOADER_INSTANCE_CREATION_FAILURE);
|
EXPECT_EQ(ec, EVMC_LOADER_INSTANCE_CREATION_FAILURE);
|
||||||
EXPECT_STREQ(evmc_last_error_msg(), "creating EVMC instance of failure.vm has failed");
|
EXPECT_STREQ(evmc_last_error_msg(), "creating EVMC instance of failure.vm has failed");
|
||||||
|
EXPECT_TRUE(evmc_last_error_msg() == nullptr);
|
||||||
|
|
||||||
|
vm = evmc_load_and_create(evmc_test_library_path, nullptr);
|
||||||
|
EXPECT_TRUE(vm == nullptr);
|
||||||
|
EXPECT_STREQ(evmc_last_error_msg(), "creating EVMC instance of failure.vm has failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(loader, load_and_create_abi_mismatch)
|
TEST_F(loader, load_and_create_abi_mismatch)
|
||||||
|
@ -315,5 +320,11 @@ TEST_F(loader, load_and_create_abi_mismatch)
|
||||||
"EVMC ABI version 1985 of abi1985.vm mismatches the expected version " +
|
"EVMC ABI version 1985 of abi1985.vm mismatches the expected version " +
|
||||||
std::to_string(EVMC_ABI_VERSION);
|
std::to_string(EVMC_ABI_VERSION);
|
||||||
EXPECT_EQ(evmc_last_error_msg(), expected_error_msg);
|
EXPECT_EQ(evmc_last_error_msg(), expected_error_msg);
|
||||||
|
EXPECT_TRUE(evmc_last_error_msg() == nullptr);
|
||||||
|
EXPECT_EQ(destroy_count, create_count);
|
||||||
|
|
||||||
|
vm = evmc_load_and_create(evmc_test_library_path, nullptr);
|
||||||
|
EXPECT_TRUE(vm == nullptr);
|
||||||
|
EXPECT_EQ(evmc_last_error_msg(), expected_error_msg);
|
||||||
EXPECT_EQ(destroy_count, create_count);
|
EXPECT_EQ(destroy_count, create_count);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue