Skip to content

Commit

Permalink
cpp: Deprecate helpers.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Jul 22, 2019
1 parent 02cfbe2 commit 106f3cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
14 changes: 12 additions & 2 deletions include/evmc/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,47 @@
#include <functional>

/// The comparator for std::map<evmc_address, ...>.
EVMC_DEPRECATED
inline bool operator<(const evmc_address& a, const evmc_address& b)
{
return std::memcmp(a.bytes, b.bytes, sizeof(a.bytes)) < 0;
}

/// The comparator for std::map<evmc_bytes32, ...>.
EVMC_DEPRECATED
inline bool operator<(const evmc_bytes32& a, const evmc_bytes32& b)
{
return std::memcmp(a.bytes, b.bytes, sizeof(a.bytes)) < 0;
}

/// The comparator for equality.
EVMC_DEPRECATED
inline bool operator==(const evmc_address& a, const evmc_address& b)
{
return std::memcmp(a.bytes, b.bytes, sizeof(a.bytes)) == 0;
}

/// The comparator for equality.
EVMC_DEPRECATED
inline bool operator==(const evmc_bytes32& a, const evmc_bytes32& b)
{
return std::memcmp(a.bytes, b.bytes, sizeof(a.bytes)) == 0;
}

/// Check if the address is zero (all bytes are zeros).
EVMC_DEPRECATED
inline bool is_zero(const evmc_address& address) noexcept
{
return address == evmc_address{};
constexpr auto zero = evmc_address{};
return std::memcmp(address.bytes, zero.bytes, sizeof(zero.bytes)) == 0;
}

/// Check if the hash is zero (all bytes are zeros).
EVMC_DEPRECATED
inline bool is_zero(const evmc_bytes32& x) noexcept
{
return x == evmc_bytes32{};
constexpr auto zero = evmc_bytes32{};
return std::memcmp(x.bytes, zero.bytes, sizeof(zero.bytes)) == 0;
}

/// Parameters for the fnv1a hash function, specialized by the hash result size (size_t).
Expand Down Expand Up @@ -101,6 +109,7 @@ template <>
struct hash<evmc_address>
{
/// Hash operator using FNV1a.
EVMC_DEPRECATED
size_t operator()(const evmc_address& s) const noexcept
{
return fnv1a(s.bytes, sizeof(s.bytes));
Expand All @@ -112,6 +121,7 @@ template <>
struct hash<evmc_bytes32>
{
/// Hash operator using FNV1a.
EVMC_DEPRECATED
size_t operator()(const evmc_bytes32& s) const noexcept
{
return fnv1a(s.bytes, sizeof(s.bytes));
Expand Down
22 changes: 0 additions & 22 deletions test/unittests/test_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// Licensed under the Apache License, Version 2.0.

#include <evmc/helpers.h>
#include <evmc/helpers.hpp>

#include <gtest/gtest.h>

Expand All @@ -27,27 +26,6 @@ static constexpr size_t optionalDataSize =
static_assert(optionalDataSize >= sizeof(evmc_result_optional_storage),
"evmc_result's optional data space is too small");


TEST(helpers, fnv1a)
{
const uint8_t text[] = {'E', 'V', 'M', 'C'};
const auto h = fnv1a(text, sizeof(text));
EXPECT_EQ(h, sizeof(size_t) == 8 ? 0x15e05d6d22fed89a : 0xffaa6a9a);
}

TEST(helpers, is_zero)
{
auto a = evmc_address{};
EXPECT_TRUE(is_zero(a));
a.bytes[0] = 1;
EXPECT_FALSE(is_zero(a));

auto b = evmc_bytes32{};
EXPECT_TRUE(is_zero(b));
b.bytes[0] = 1;
EXPECT_FALSE(is_zero(b));
}

TEST(helpers, release_result)
{
auto r1 = evmc_result{};
Expand Down

0 comments on commit 106f3cb

Please sign in to comment.