Skip to content

Commit

Permalink
cpp: Rename evmc::vm to evmc::VM
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Aug 22, 2019
1 parent bb45c2b commit 62fb8af
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning].

### Changed

- The `evmc::vm` renamed to `evmc::VM` in C++ API.
[[#252](https://github.com/ethereum/evmc/pull/252)]
- Previously deprecated `helpers.hpp` header file has been removed.
[[#410](https://github.com/ethereum/evmc/pull/410)]

Expand Down
20 changes: 10 additions & 10 deletions include/evmc/evmc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,39 +338,39 @@ class result : private evmc_result
///
/// This is a RAII wrapper for evmc_instance and objects of this type
/// automatically destroys the VM instance.
class vm
class VM
{
public:
vm() noexcept = default;
VM() noexcept = default;

/// Converting constructor from evmc_instance.
explicit vm(evmc_instance* instance) noexcept : m_instance{instance} {}
explicit VM(evmc_instance* instance) noexcept : m_instance{instance} {}

/// Destructor responsible for automatically destroying the VM instance.
~vm() noexcept
~VM() noexcept
{
if (m_instance)
m_instance->destroy(m_instance);
}

vm(const vm&) = delete;
vm& operator=(const vm&) = delete;
VM(const VM&) = delete;
VM& operator=(const VM&) = delete;

/// Move constructor.
vm(vm&& other) noexcept : m_instance{other.m_instance} { other.m_instance = nullptr; }
VM(VM&& other) noexcept : m_instance{other.m_instance} { other.m_instance = nullptr; }

/// Move assignment operator.
vm& operator=(vm&& other) noexcept
VM& operator=(VM&& other) noexcept
{
this->~vm();
this->~VM();
m_instance = other.m_instance;
other.m_instance = nullptr;
return *this;
}

/// The constructor that captures a VM instance and configures the instance
/// with provided list of options.
vm(evmc_instance* instance,
VM(evmc_instance* instance,
std::initializer_list<std::pair<const char*, const char*>> options) noexcept
: m_instance{instance}
{
Expand Down
18 changes: 9 additions & 9 deletions test/unittests/test_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ TEST(cpp, result)

TEST(cpp, vm)
{
auto vm = evmc::vm{evmc_create_example_vm()};
auto vm = evmc::VM{evmc_create_example_vm()};
EXPECT_TRUE(vm.is_abi_compatible());

auto r = vm.set_option("verbose", "3");
Expand All @@ -277,13 +277,13 @@ TEST(cpp, vm_set_option)
nullptr, nullptr, nullptr, nullptr};
raw_instance.destroy = [](evmc_instance*) {};

auto vm = evmc::vm{&raw_instance};
auto vm = evmc::VM{&raw_instance};
EXPECT_EQ(vm.set_option("1", "2"), EVMC_SET_OPTION_INVALID_NAME);
}

TEST(cpp, vm_null)
{
evmc::vm vm;
evmc::VM vm;
EXPECT_FALSE(vm);
EXPECT_TRUE(!vm);
}
Expand All @@ -300,25 +300,25 @@ TEST(cpp, vm_move)
auto v1 = template_instance;
auto v2 = template_instance;

auto vm1 = evmc::vm{&v1};
auto vm1 = evmc::VM{&v1};
EXPECT_TRUE(vm1);
vm1 = evmc::vm{&v2};
vm1 = evmc::VM{&v2};
EXPECT_TRUE(vm1);
}
EXPECT_EQ(destroy_counter, 2);
{
auto v1 = template_instance;

auto vm1 = evmc::vm{&v1};
auto vm1 = evmc::VM{&v1};
EXPECT_TRUE(vm1);
vm1 = evmc::vm{};
vm1 = evmc::VM{};
EXPECT_FALSE(vm1);
}
EXPECT_EQ(destroy_counter, 3);
{
auto v1 = template_instance;

auto vm1 = evmc::vm{&v1};
auto vm1 = evmc::VM{&v1};
EXPECT_TRUE(vm1);
auto vm2 = std::move(vm1);
EXPECT_TRUE(vm2);
Expand All @@ -333,7 +333,7 @@ TEST(cpp, vm_move)
// Moving to itself will destroy the VM and reset the evmc::vm.
auto v1 = template_instance;

auto vm1 = evmc::vm{&v1};
auto vm1 = evmc::VM{&v1};
auto& vm1_ref = vm1;
vm1 = std::move(vm1_ref);
EXPECT_EQ(destroy_counter, 5); // Already destroyed.
Expand Down
4 changes: 2 additions & 2 deletions test/vmtester/vmtester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#include <memory>

evmc_instance* evmc_vm_test::vm;
evmc::vm evmc_vm_test::owned_vm;
evmc::VM evmc_vm_test::owned_vm;

void evmc_vm_test::init_vm(evmc_instance* owned_vm_instance) noexcept
{
vm = owned_vm_instance;
owned_vm = evmc::vm{owned_vm_instance};
owned_vm = evmc::VM{owned_vm_instance};
}

class cli_parser
Expand Down
2 changes: 1 addition & 1 deletion test/vmtester/vmtester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class evmc_vm_test : public ::testing::Test
static evmc_instance* vm;

/// The C++ RAII wrapper of the loaded VM instance.
static evmc::vm owned_vm;
static evmc::VM owned_vm;

void SetUp() override { ASSERT_TRUE(vm != nullptr) << "VM instance not loaded"; }
};

0 comments on commit 62fb8af

Please sign in to comment.