From 60c666a6123bd767d41a3ae96efc40750e978177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 14 May 2019 16:06:56 +0200 Subject: [PATCH 1/9] cpp: Add unit test for evmc::result RAII --- test/unittests/test_cpp.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/unittests/test_cpp.cpp b/test/unittests/test_cpp.cpp index 9f7c525..2a0afce 100644 --- a/test/unittests/test_cpp.cpp +++ b/test/unittests/test_cpp.cpp @@ -120,3 +120,40 @@ TEST(cpp, host_call) example_host_destroy_context(host_context); } + +TEST(cpp, result_raii) +{ + static auto release_called = 0; + release_called = 0; + auto release_fn = [](const evmc_result*) noexcept { ++release_called; }; + + { + auto raw_result = evmc_result{}; + raw_result.status_code = EVMC_INTERNAL_ERROR; + raw_result.release = release_fn; + + auto raii_result = evmc::result{raw_result}; + EXPECT_EQ(raii_result.status_code, EVMC_INTERNAL_ERROR); + EXPECT_EQ(raii_result.gas_left, 0); + raii_result.gas_left = -1; + + auto raw_result2 = raii_result.raw(); + EXPECT_EQ(raw_result2.status_code, EVMC_INTERNAL_ERROR); + EXPECT_EQ(raw_result.status_code, EVMC_INTERNAL_ERROR); + EXPECT_EQ(raw_result2.gas_left, -1); + EXPECT_EQ(raw_result.gas_left, 0); + EXPECT_EQ(raw_result2.release, release_fn); + EXPECT_EQ(raw_result.release, release_fn); + } + EXPECT_EQ(release_called, 0); + + { + auto raw_result = evmc_result{}; + raw_result.status_code = EVMC_INTERNAL_ERROR; + raw_result.release = release_fn; + + auto raii_result = evmc::result{raw_result}; + EXPECT_EQ(raii_result.status_code, EVMC_INTERNAL_ERROR); + } + EXPECT_EQ(release_called, 1); +} From 577340763c06807f06f7e65539cf2687678b5138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 14 May 2019 10:30:31 +0200 Subject: [PATCH 2/9] cpp: Include to show MSVC compilation error This is related to misuse of `std::swap`. We should not use explicit template arguments, because this disabled SFINAE and forces instantiation of all overloads. --- test/unittests/test_cpp.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/unittests/test_cpp.cpp b/test/unittests/test_cpp.cpp index 2a0afce..798caa9 100644 --- a/test/unittests/test_cpp.cpp +++ b/test/unittests/test_cpp.cpp @@ -2,6 +2,10 @@ // Copyright 2018-2019 The EVMC Authors. // Licensed under the Apache License, Version 2.0. +// The vector is not used here, but including it was causing compilation issues +// previously related to using explicit template argument (SFINAE disabled). +#include + #include "../../examples/example_host.h" #include "../../examples/example_vm.h" From 660f192722dc1fffa244bcf65945a1795b7367fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 14 May 2019 11:14:30 +0200 Subject: [PATCH 3/9] cpp: Fix misuse of std::swap We should not use explicit template arguments, because this disabled SFINAE and forces instantiation of all overloads. --- include/evmc/evmc.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/evmc/evmc.hpp b/include/evmc/evmc.hpp index 2210bae..1ae2d12 100644 --- a/include/evmc/evmc.hpp +++ b/include/evmc/evmc.hpp @@ -56,8 +56,8 @@ public: /// releases the ownership of the resources and invalidates this object. evmc_result raw() noexcept { - auto out = evmc_result{}; - std::swap(out, *this); + const auto out = evmc_result{*this}; // Copy data. + this->release = nullptr; // Disable releasing of this object. return out; } }; From 9685f2802226c03714c0bef734486d16642cdb1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 14 May 2019 11:17:55 +0200 Subject: [PATCH 4/9] changelog: Add entry about fixed compilation error in evmc::result::raw() --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb03001..37123dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [6.2.2] - unreleased + +- Fixed: [[#281](https://github.com/ethereum/evmc/pull/281)] + Compilation error of evmc::result::raw() in Visual Studio fixed. + ## [6.2.1] - 2019-04-29 - Fixed: From 3c91910f52a724f719c650e05c33ffcad9162ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 14 May 2019 11:53:47 +0200 Subject: [PATCH 5/9] cpp: Add unit test for moving evmc::result --- test/unittests/test_cpp.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/unittests/test_cpp.cpp b/test/unittests/test_cpp.cpp index 798caa9..cb813f5 100644 --- a/test/unittests/test_cpp.cpp +++ b/test/unittests/test_cpp.cpp @@ -161,3 +161,40 @@ TEST(cpp, result_raii) } EXPECT_EQ(release_called, 1); } + +TEST(cpp, result_move) +{ + static auto release_called = 0; + auto release_fn = [](const evmc_result*) noexcept { ++release_called; }; + + release_called = 0; + { + auto raw = evmc_result{}; + raw.gas_left = -1; + raw.release = release_fn; + + auto r0 = evmc::result{raw}; + EXPECT_EQ(r0.gas_left, raw.gas_left); + + auto r1 = std::move(r0); + EXPECT_EQ(r1.gas_left, raw.gas_left); + } + EXPECT_EQ(release_called, 1); + + release_called = 0; + { + auto raw1 = evmc_result{}; + raw1.gas_left = 1; + raw1.release = release_fn; + + auto raw2 = evmc_result{}; + raw2.gas_left = 1; + raw2.release = release_fn; + + auto r1 = evmc::result{raw1}; + auto r2 = evmc::result{raw2}; + + r2 = std::move(r1); + } + EXPECT_EQ(release_called, 2); +} From cea8d3a5b584e609dc406b351a5b290ddba099ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 14 May 2019 12:03:29 +0200 Subject: [PATCH 6/9] cpp: Fix evmc::result's move assignment operator --- include/evmc/evmc.hpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/include/evmc/evmc.hpp b/include/evmc/evmc.hpp index 1ae2d12..b829a15 100644 --- a/include/evmc/evmc.hpp +++ b/include/evmc/evmc.hpp @@ -39,16 +39,22 @@ public: /// Move constructor. result(result&& other) noexcept : evmc_result{other} { - // Disable releaser of the rvalue object. - other.release = nullptr; + other.release = nullptr; // Disable releasing of the rvalue object. } result(result const&) = delete; - /// Move-and-swap assignment operator. - result& operator=(result other) noexcept + /// Move assignment operator. + /// + /// The self-assigment MUST never happen. + /// + /// @param other The other result object. + /// @return The reference to the left-hand side object. + result& operator=(result&& other) noexcept { - std::swap(*this, other); + this->~result(); // Release this object. + static_cast(*this) = other; // Copy data. + other.release = nullptr; // Disable releasing of the rvalue object. return *this; } From 8ee9d4459235084dfba385e87e0f8dfb78b092c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 14 May 2019 12:13:11 +0200 Subject: [PATCH 7/9] cpp: Remove redundant deleted copy constructor of result --- include/evmc/evmc.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/evmc/evmc.hpp b/include/evmc/evmc.hpp index b829a15..24ee34a 100644 --- a/include/evmc/evmc.hpp +++ b/include/evmc/evmc.hpp @@ -42,8 +42,6 @@ public: other.release = nullptr; // Disable releasing of the rvalue object. } - result(result const&) = delete; - /// Move assignment operator. /// /// The self-assigment MUST never happen. From d9a6a8b0a9d5a467566ef2901ba043d52b91103b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 14 May 2019 12:07:17 +0200 Subject: [PATCH 8/9] changelog: Add entry about fixed evmc::result --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37123dd..b57d400 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,9 @@ ## [6.2.2] - unreleased - Fixed: [[#281](https://github.com/ethereum/evmc/pull/281)] - Compilation error of evmc::result::raw() in Visual Studio fixed. + Compilation error of `evmc::result::raw()` in Visual Studio fixed. +- Fixed: [[#282](https://github.com/ethereum/evmc/pull/282)] + The `evmc::result`'s move assignment operator fixed. ## [6.2.1] - 2019-04-29 From 14d70e4478788cc41a309f944ea7dd12ee8b6d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 16 May 2019 08:49:49 +0200 Subject: [PATCH 9/9] EVMC 6.2.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bump version: 6.2.1 → 6.2.2 --- .bumpversion.cfg | 2 +- CHANGELOG.md | 2 +- CMakeLists.txt | 2 +- bindings/rust/evmc-sys/Cargo.toml | 2 +- bindings/rust/evmc-vm/Cargo.toml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 7610455..cae1b86 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 6.2.1 +current_version = 6.2.2 tag = True sign_tags = True tag_message = EVMC {new_version} diff --git a/CHANGELOG.md b/CHANGELOG.md index b57d400..341a128 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## [6.2.2] - unreleased +## [6.2.2] - 2019-05-16 - Fixed: [[#281](https://github.com/ethereum/evmc/pull/281)] Compilation error of `evmc::result::raw()` in Visual Studio fixed. diff --git a/CMakeLists.txt b/CMakeLists.txt index 216915a..9dcfcee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,7 @@ endif() cable_configure_toolchain(DEFAULT cxx11-pic) project(evmc) -set(PROJECT_VERSION 6.2.1) +set(PROJECT_VERSION 6.2.2) cable_set_build_type(DEFAULT Release CONFIGURATION_TYPES Debug Release) diff --git a/bindings/rust/evmc-sys/Cargo.toml b/bindings/rust/evmc-sys/Cargo.toml index 8ef7791..3cf91d5 100644 --- a/bindings/rust/evmc-sys/Cargo.toml +++ b/bindings/rust/evmc-sys/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "evmc-sys" -version = "6.2.1" +version = "6.2.2" authors = ["Alex Beregszaszi "] license = "Apache-2.0" repository = "https://github.com/ethereum/evmc" diff --git a/bindings/rust/evmc-vm/Cargo.toml b/bindings/rust/evmc-vm/Cargo.toml index c4d4e68..f8b8a6a 100644 --- a/bindings/rust/evmc-vm/Cargo.toml +++ b/bindings/rust/evmc-vm/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "evmc-vm" -version = "6.2.1" +version = "6.2.2" authors = ["Alex Beregszaszi "] license = "Apache-2.0" repository = "https://github.com/ethereum/evmc"