From 687d0a38a85bf080001317ef91b11bfb2c942801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Fri, 13 Jul 2018 14:51:50 +0200 Subject: [PATCH] Add helpers for invoking some of the VM instance methods --- include/evmc/helpers.h | 54 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 include/evmc/helpers.h diff --git a/include/evmc/helpers.h b/include/evmc/helpers.h new file mode 100644 index 0000000..66c7907 --- /dev/null +++ b/include/evmc/helpers.h @@ -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 + +/** + * 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); +} + +/** @} */