Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/1.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Sep 15, 2018
2 parents 0795c39 + d7e94ca commit 1db59b4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions libevm/EVMC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace eth
EVM::EVM(evmc_instance* _instance) noexcept : m_instance(_instance)
{
assert(m_instance != nullptr);
assert(m_instance->abi_version == EVMC_ABI_VERSION);
assert(evmc_is_abi_compatible(m_instance));

// Set the options.
for (auto& pair : evmcOptions())
Expand All @@ -32,7 +32,7 @@ EVM::Result EVM::execute(ExtVMFace& _ext, int64_t gas)
toEvmC(_ext.caller), _ext.data.data(), _ext.data.size(), toEvmC(_ext.value),
toEvmC(0x0_cppui256)};
return EVM::Result{
m_instance->execute(m_instance, &_ext, mode, &msg, _ext.code.data(), _ext.code.size())};
evmc_execute(m_instance, &_ext, mode, &msg, _ext.code.data(), _ext.code.size())};
}

owning_bytes_ref EVMC::exec(u256& io_gas, ExtVMFace& _ext, const OnOpFunc& _onOp)
Expand Down
6 changes: 3 additions & 3 deletions libevm/EVMC.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ class EVM
public:
explicit EVM(evmc_instance* _instance) noexcept;

~EVM() { m_instance->destroy(m_instance); }
~EVM() { evmc_destroy(m_instance); }

EVM(EVM const&) = delete;
EVM& operator=(EVM) = delete;

char const* name() const noexcept { return m_instance->name; }
char const* name() const noexcept { return evmc_vm_name(m_instance); }

char const* version() const noexcept { return m_instance->version; }
char const* version() const noexcept { return evmc_vm_version(m_instance); }

class Result
{
Expand Down
19 changes: 15 additions & 4 deletions libevm/VMFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,16 @@ void setVMKind(const std::string& _name)
}
}

// If not match for predefined VM names, try loading it as an EVMC VM DLL.
// If no match for predefined VM names, try loading it as an EVMC VM DLL.
g_kind = VMKind::DLL;

// Release previous instance
g_evmcDll.reset();

evmc_loader_error_code ec;
g_evmcDll.reset(new EVMC{evmc_load_and_create(_name.c_str(), &ec)});
evmc_instance *instance = evmc_load_and_create(_name.c_str(), &ec);
assert(ec == EVMC_LOADER_SUCCESS || instance == nullptr);

switch (ec)
{
case EVMC_LOADER_SUCCESS:
Expand All @@ -83,12 +90,16 @@ void setVMKind(const std::string& _name)
case EVMC_LOADER_SYMBOL_NOT_FOUND:
BOOST_THROW_EXCEPTION(std::system_error(std::make_error_code(std::errc::invalid_seek),
"loading " + _name + " failed: EVMC create function not found"));
case EVMC_LOADER_ABI_VERSION_MISMATCH:
BOOST_THROW_EXCEPTION(std::system_error(std::make_error_code(std::errc::invalid_argument),
"loading " + _name + " failed: EVMC ABI version mismatch"));
default:
BOOST_THROW_EXCEPTION(
std::system_error(std::error_code(static_cast<int>(ec), std::generic_category()),
"loading " + _name + " failed"));
}
g_kind = VMKind::DLL;

g_evmcDll.reset(new EVMC{instance});

cnote << "Loaded EVMC module: " << g_evmcDll->name() << " " << g_evmcDll->version() << " ("
<< _name << ")";
Expand Down Expand Up @@ -178,8 +189,8 @@ VMPtr VMFactory::create(VMKind _kind)
case VMKind::Interpreter:
return {new EVMC{evmc_create_interpreter()}, default_delete};
case VMKind::DLL:
// Return "fake" owning pointer to global EVMC DLL VM.
assert(g_evmcDll != nullptr);
// Return "fake" owning pointer to global EVMC DLL VM.
return {g_evmcDll.get(), null_delete};
case VMKind::Legacy:
default:
Expand Down

0 comments on commit 1db59b4

Please sign in to comment.