Add helpers for invoking some of the VM instance methods

This commit is contained in:
Paweł Bylica 2018-07-13 14:51:50 +02:00
parent 2e2b7f0e81
commit 687d0a38a8
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
1 changed files with 54 additions and 0 deletions

54
include/evmc/helpers.h Normal file
View File

@ -0,0 +1,54 @@
/* EVMC: Ethereum Client-VM Connector API.
* Copyright 2018 Pawel Bylica.
* Licensed under the MIT License. See the LICENSE file.
*/
/**
* EVMC Helpers
*
* A collection of helper functions for invoking a VM instance methods.
* These are convenient for languages where invoking function pointers
* is "ugly" or impossible (such as Go).
*
* @defgroup helpers EVMC Helpers
* @{
*/
#pragma once
#include <evmc/evmc.h>
/**
* Destroys the VM instance.
*
* @see evmc_destroy_fn
*/
static inline void evmc_destroy(struct evmc_instance* instance)
{
instance->destroy(instance);
}
/**
* Sets the option for the VM instance, if the feature is supported by the VM.
*
* @see evmc_set_option_fn
*/
static inline int evmc_set_option(struct evmc_instance* instance,
char const* name,
char const* value)
{
if (instance->set_option)
return instance->set_option(instance, name, value);
return 0;
}
/**
* Releases the resources allocated to the execution result.
*
* @see evmc_release_result_fn
*/
static inline void evmc_release_result(struct evmc_result* result)
{
result->release(result);
}
/** @} */