From 38a20190f42e34f4c0cda7d55703528005412fad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Wed, 27 Nov 2019 17:37:26 +0100 Subject: [PATCH] test: Use evmc::VM directly The evmc::VM works as a RAII wrapper similarly to unique_ptr, so there is no point in using additional unique_ptr. --- test/EVMHost.cpp | 19 ++++++++----------- test/EVMHost.h | 6 +++--- test/tools/ossfuzz/abiV2ProtoFuzzer.cpp | 2 +- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/test/EVMHost.cpp b/test/EVMHost.cpp index 64ef1c5e5..a925cf325 100644 --- a/test/EVMHost.cpp +++ b/test/EVMHost.cpp @@ -35,22 +35,19 @@ using namespace dev; using namespace dev::test; -evmc::VM* EVMHost::getVM(string const& _path) +evmc::VM& EVMHost::getVM(string const& _path) { - static unique_ptr theVM; + static evmc::VM theVM; if (!theVM && !_path.empty()) { evmc_loader_error_code errorCode = {}; - evmc_vm* vm = evmc_load_and_configure(_path.c_str(), &errorCode); + auto vm = evmc::VM{evmc_load_and_configure(_path.c_str(), &errorCode)}; if (vm && errorCode == EVMC_LOADER_SUCCESS) { - if (evmc_vm_has_capability(vm, EVMC_CAPABILITY_EVM1)) - theVM = make_unique(vm); + if (vm.get_capabilities() & EVMC_CAPABILITY_EVM1) + theVM = std::move(vm); else - { - evmc_destroy(vm); cerr << "VM loaded does not support EVM1" << endl; - } } else { @@ -60,10 +57,10 @@ evmc::VM* EVMHost::getVM(string const& _path) cerr << endl; } } - return theVM.get(); + return theVM; } -EVMHost::EVMHost(langutil::EVMVersion _evmVersion, evmc::VM* _vm): +EVMHost::EVMHost(langutil::EVMVersion _evmVersion, evmc::VM& _vm): m_vm(_vm), m_evmVersion(_evmVersion) { @@ -192,7 +189,7 @@ evmc::result EVMHost::call(evmc_message const& _message) noexcept evmc::address currentAddress = m_currentAddress; m_currentAddress = message.destination; - evmc::result result = m_vm->execute(*this, m_evmRevision, message, code.data(), code.size()); + evmc::result result = m_vm.execute(*this, m_evmRevision, message, code.data(), code.size()); m_currentAddress = currentAddress; if (message.kind == EVMC_CREATE) diff --git a/test/EVMHost.h b/test/EVMHost.h index a0adb67bc..15d069d72 100644 --- a/test/EVMHost.h +++ b/test/EVMHost.h @@ -40,9 +40,9 @@ public: /// Tries to dynamically load libevmone. @returns nullptr on failure. /// The path has to be provided for the first successful run and will be ignored /// afterwards. - static evmc::VM* getVM(std::string const& _path = {}); + static evmc::VM& getVM(std::string const& _path = {}); - explicit EVMHost(langutil::EVMVersion _evmVersion, evmc::VM* _vm = getVM()); + explicit EVMHost(langutil::EVMVersion _evmVersion, evmc::VM& _vm = getVM()); struct Account { @@ -179,7 +179,7 @@ private: /// @note The return value is only valid as long as @a _data is alive! static evmc::result resultWithGas(evmc_message const& _message, bytes const& _data) noexcept; - evmc::VM* m_vm = nullptr; + evmc::VM& m_vm; // EVM version requested by the testing tool langutil::EVMVersion m_evmVersion; // EVM version requested from EVMC (matches the above) diff --git a/test/tools/ossfuzz/abiV2ProtoFuzzer.cpp b/test/tools/ossfuzz/abiV2ProtoFuzzer.cpp index 9d7308299..07e062b8f 100644 --- a/test/tools/ossfuzz/abiV2ProtoFuzzer.cpp +++ b/test/tools/ossfuzz/abiV2ProtoFuzzer.cpp @@ -142,7 +142,7 @@ DEFINE_PROTO_FUZZER(Contract const& _input) // We target the default EVM which is the latest langutil::EVMVersion version = {}; - EVMHost hostContext(version, &evmone); + EVMHost hostContext(version, evmone); // Deploy contract and signal failure if deploy failed evmc::result createResult = deployContract(hostContext, byteCode);