mirror of https://github.com/status-im/evmc.git
helpers: Handle results with null release() method
This commit is contained in:
parent
2ca88aca07
commit
3b834de095
|
@ -109,10 +109,13 @@ static inline struct evmc_result evmc_execute(struct evmc_instance* instance,
|
|||
/**
|
||||
* Releases the resources allocated to the execution result.
|
||||
*
|
||||
* @see evmc_release_result_fn
|
||||
* @param result The result object to be released. MUST NOT be NULL.
|
||||
*
|
||||
* @see evmc_result::release() evmc_release_result_fn
|
||||
*/
|
||||
static inline void evmc_release_result(struct evmc_result* result)
|
||||
{
|
||||
if (result->release)
|
||||
result->release(result);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,3 +61,19 @@ TEST(helpers, is_zero)
|
|||
b.bytes[0] = 1;
|
||||
EXPECT_FALSE(is_zero(b));
|
||||
}
|
||||
|
||||
TEST(helpers, release_result)
|
||||
{
|
||||
auto r1 = evmc_result{};
|
||||
evmc_release_result(&r1);
|
||||
|
||||
static evmc_result r2;
|
||||
static bool e;
|
||||
|
||||
e = false;
|
||||
r2 = evmc_result{};
|
||||
r2.release = [](const evmc_result* r) { e = r == &r2; };
|
||||
EXPECT_FALSE(e);
|
||||
evmc_release_result(&r2);
|
||||
EXPECT_TRUE(e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue