Skip to content

Commit

Permalink
Fixed a compile-time assertion not satisfied on Windows GCC
Browse files Browse the repository at this point in the history
In CompactTXO for some reason, sizeof(u.asU564) was not equal to the
`compact` field.  So we work around by copying data out of the compact
fielt to a temporary uint64_t for the std::hash.
  • Loading branch information
cculianu committed Jul 2, 2020
1 parent 93499a1 commit d813a77
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/TXO_Compact.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,16 @@ namespace std {
/// specialization of std::hash to be able to add struct CompactTXO to any unordered_set or unordered_map
template<> struct hash<CompactTXO> {
size_t operator()(const CompactTXO &txo) const noexcept {
static_assert (sizeof(txo.u.asU64) == sizeof(txo.u.compact),
"Unknown platform or struct packing. Expected CompactTXO.u.prevout size to be 64 bytes.");
// just return the hash of the packed asU64.
return hasher64(txo.u.asU64);
if constexpr (sizeof(txo.u.asU64) == sizeof(txo.u.compact)) {
// just return the hash of the packed asU64.
return hasher64(txo.u.asU64);
} else {
// on Windows MinGW GCC for some reason the above is false, so we do this
uint64_t buf;
static_assert(sizeof(buf) == CompactTXO::serSize());
txo.toBytesInPlace(&buf, sizeof(buf));
return hasher64(buf);
}
}
private:
hash<uint64_t> hasher64;
Expand Down

0 comments on commit d813a77

Please sign in to comment.