From 1e53ea1f860a8fef65b25f79b534e95603d09094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 29 Apr 2019 15:16:57 +0200 Subject: [PATCH] cpp: Disallow implicit conversion result -> evmc_result This was breaking RAII of evmc::result --- include/evmc/evmc.hpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/include/evmc/evmc.hpp b/include/evmc/evmc.hpp index 4e820b0..2210bae 100644 --- a/include/evmc/evmc.hpp +++ b/include/evmc/evmc.hpp @@ -17,9 +17,15 @@ namespace evmc /// /// This is a RAII wrapper for evmc_result and objects of this type /// automatically release attached resources. -class result : public evmc_result +class result : private evmc_result { public: + using evmc_result::create_address; + using evmc_result::gas_left; + using evmc_result::output_data; + using evmc_result::output_size; + using evmc_result::status_code; + /// Converting constructor from raw evmc_result. explicit result(evmc_result const& res) noexcept : evmc_result{res} {} @@ -45,6 +51,15 @@ public: std::swap(*this, other); return *this; } + + /// Returns the raw copy of evmc_result, + /// releases the ownership of the resources and invalidates this object. + evmc_result raw() noexcept + { + auto out = evmc_result{}; + std::swap(out, *this); + return out; + } }; /// @copybrief evmc_instance @@ -302,7 +317,7 @@ inline void selfdestruct(evmc_context* h, } inline evmc_result call(evmc_context* h, const evmc_message* msg) noexcept { - return static_cast(h)->call(*msg); + return static_cast(h)->call(*msg).raw(); } inline evmc_tx_context get_tx_context(evmc_context* h) noexcept {