Skip to content

Commit

Permalink
Merge pull request #293 from ethereum/cpp_result_release_raw
Browse files Browse the repository at this point in the history
cpp: Rename result::raw() to result::release_raw()
  • Loading branch information
chfast committed May 21, 2019
2 parents 8423fac + 3ffadec commit 37a5b8a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [6.3.0] - unreleased

- Changed: [[#293](https://github.com/ethereum/evmc/pull/293)]
In C++ API `evmc::result::raw()` renamed to `evmc::result::release_raw()`.
- Fixed:
[[#261](https://github.com/ethereum/evmc/issues/261),
[#263](https://github.com/ethereum/evmc/pull/263)]
Expand Down
14 changes: 10 additions & 4 deletions include/evmc/evmc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,15 @@ class result : private evmc_result
return *this;
}

/// Returns the raw copy of evmc_result,
/// releases the ownership of the resources and invalidates this object.
evmc_result raw() noexcept
/// Releases the ownership and returns the raw copy of evmc_result.
///
/// This method drops the ownership of the result
/// (result's resources are not going to be released when this object is destructed).
/// It is the caller's responsibility having the returned copy of the result to release it.
/// This object MUST NOT be used after this method is invoked.
///
/// @return The copy of this object converted to raw evmc_result.
evmc_result release_raw() noexcept
{
const auto out = evmc_result{*this}; // Copy data.
this->release = nullptr; // Disable releasing of this object.
Expand Down Expand Up @@ -321,7 +327,7 @@ inline void selfdestruct(evmc_context* h,
}
inline evmc_result call(evmc_context* h, const evmc_message* msg) noexcept
{
return static_cast<Host*>(h)->call(*msg).raw();
return static_cast<Host*>(h)->call(*msg).release_raw();
}
inline evmc_tx_context get_tx_context(evmc_context* h) noexcept
{
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/test_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ TEST(cpp, result_raii)
EXPECT_EQ(raii_result.gas_left, 0);
raii_result.gas_left = -1;

auto raw_result2 = raii_result.raw();
auto raw_result2 = raii_result.release_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);
Expand Down

0 comments on commit 37a5b8a

Please sign in to comment.