Change naming convention for "create" function

Now should be prefixed with "evmc_create_".
This commit is contained in:
Paweł Bylica 2018-04-17 11:02:00 +02:00
parent 630d8be405
commit c5c34599b9
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
5 changed files with 25 additions and 12 deletions

View File

@ -5,8 +5,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
/// Prototype from examplevm.c #include "examplevm/examplevm.h"
struct evmc_instance* examplevm_create(void);
struct evmc_uint256be balance(struct evmc_context* context, struct evmc_uint256be balance(struct evmc_context* context,
const struct evmc_address* address) const struct evmc_address* address)
@ -139,7 +139,7 @@ static const struct evmc_context_fn_table ctx_fn_table = {
/// Example how the API is supposed to be used. /// Example how the API is supposed to be used.
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
struct evmc_instance* jit = examplevm_create(); struct evmc_instance* jit = evmc_create_examplevm();
if (jit->abi_version != EVMC_ABI_VERSION) if (jit->abi_version != EVMC_ABI_VERSION)
return 1; // Incompatible ABI version. return 1; // Incompatible ABI version.

View File

@ -1,4 +1,4 @@
#include <evmc.h> #include "examplevm.h"
#include <limits.h> #include <limits.h>
#include <stdio.h> #include <stdio.h>
@ -109,7 +109,7 @@ static struct evmc_result execute(struct evmc_instance* instance, struct evmc_co
return ret; return ret;
} }
struct evmc_instance* examplevm_create() struct evmc_instance* evmc_create_examplevm()
{ {
struct evmc_instance init = { struct evmc_instance init = {
.abi_version = EVMC_ABI_VERSION, .abi_version = EVMC_ABI_VERSION,

View File

@ -0,0 +1,13 @@
/* EVMC: Ethereum Client-VM Connector API.
* Copyright 2018 Pawel Bylica.
* Licensed under the MIT License. See the LICENSE file.
*/
#pragma once
#include <evmc.h>
/**
* Creates EVMC Example VM.
*/
struct evmc_instance* evmc_create_examplevm(void);

View File

@ -576,11 +576,11 @@ struct evmc_instance
/// Example of a function creating an instance of an example EVM implementation. /// Example of a function creating an instance of an example EVM implementation.
/// ///
/// Each EVM implementation MUST provide a function returning an EVM instance. /// Each EVM implementation MUST provide a function returning an EVM instance.
/// The function SHOULD be named `<vm-name>_create(void)`. /// The function SHOULD be named `evmc_create_<vm-name>(void)`.
/// ///
/// @return EVM instance or NULL indicating instance creation failure. /// @return EVM instance or NULL indicating instance creation failure.
/// ///
/// struct evmc_instance* examplevm_create(void); /// struct evmc_instance* evmc_create_examplevm(void);
#if __cplusplus #if __cplusplus

View File

@ -26,12 +26,12 @@ namespace
{ {
boost::function<evmc_create_fn> create_fn; boost::function<evmc_create_fn> create_fn;
bool ends_with(const std::string& str, const std::string& ending) bool starts_with(const std::string& str, const std::string& prefix)
{ {
if (str.size() < ending.size()) if (str.size() < prefix.size())
return false; return false;
return std::equal(ending.rbegin(), ending.rend(), str.rbegin()); return std::equal(prefix.begin(), prefix.end(), str.begin());
} }
std::unique_ptr<evmc_instance, evmc_destroy_fn> create_vm() std::unique_ptr<evmc_instance, evmc_destroy_fn> create_vm()
@ -79,10 +79,10 @@ int main(int argc, char* argv[])
auto symbols = dll::library_info{vm_path}.symbols(); auto symbols = dll::library_info{vm_path}.symbols();
auto it = std::find_if(symbols.begin(), symbols.end(), auto it = std::find_if(symbols.begin(), symbols.end(),
[](const std::string& symbol) { return ends_with(symbol, "_create"); }); [](const std::string& symbol) { return starts_with(symbol, "evmc_create_"); });
if (it == symbols.end()) if (it == symbols.end())
{ {
std::cerr << "EVMC create function not found it " << vm_path.string() << "\n"; std::cerr << "EVMC create function not found in " << vm_path.string() << "\n";
return 2; return 2;
} }
const std::string& create_fn_name = *it; const std::string& create_fn_name = *it;