diff --git a/CHANGES b/CHANGES index 6746f8fd2e..2901486e17 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,12 @@ +4.1.0-dev.495 | 2021-04-07 11:12:13 -0700 + + * Change TableVal::ToMap() to return ValPtr-indexed maps (Jon Siwek, Corelight) + + * Add std::hash specialization for IntrusivePtr (Jon Siwek, Corelight) + + * Move IntrusivePtr relational operators to zeek namespace + + Otherwise some cases relying on argument-dependent lookup (ADL) fail. (Jon Siwek, Corelight) 4.1.0-dev.490 | 2021-04-05 14:13:48 -0700 diff --git a/VERSION b/VERSION index 46c3348727..be01695475 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.1.0-dev.490 +4.1.0-dev.495 diff --git a/src/IntrusivePtr.h b/src/IntrusivePtr.h index ec08fd0143..7ad37031c8 100644 --- a/src/IntrusivePtr.h +++ b/src/IntrusivePtr.h @@ -4,6 +4,7 @@ #include #include +#include namespace zeek { @@ -198,8 +199,6 @@ IntrusivePtr cast_intrusive(IntrusivePtr p) noexcept return {AdoptRef{}, static_cast(p.release())}; } -} // namespace zeek - // -- comparison to nullptr ---------------------------------------------------- /** @@ -292,3 +291,15 @@ auto operator!=(const zeek::IntrusivePtr& x, const zeek::IntrusivePtr& y) { return x.get() != y.get(); } + +} // namespace zeek + +// -- hashing ------------------------------------------------ + +namespace std { +template struct hash> { + // Hash of intrusive pointer is the same as hash of the raw pointer it holds. + size_t operator()(const zeek::IntrusivePtr& v) const noexcept + { return std::hash{}(v.get()); } +}; +} diff --git a/src/Val.cc b/src/Val.cc index fe7f0a4c9b..e3eb35002f 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -2311,9 +2311,9 @@ ListValPtr TableVal::ToPureListVal() const return ToListVal(tl[0]->Tag()); } -std::unordered_map TableVal::ToMap() const +std::unordered_map TableVal::ToMap() const { - std::unordered_map res; + std::unordered_map res; for ( const auto& iter : *table_val ) { @@ -2321,7 +2321,7 @@ std::unordered_map TableVal::ToMap() const auto v = iter.GetValue(); auto vl = table_hash->RecoverVals(*k); - res[vl.release()] = v->GetVal(); + res[std::move(vl)] = v->GetVal(); } return res; diff --git a/src/Val.h b/src/Val.h index ec0a5db158..4bdd1b9dbc 100644 --- a/src/Val.h +++ b/src/Val.h @@ -896,9 +896,7 @@ public: ListValPtr ToPureListVal() const; // Returns a map of index-to-value's. The value is nil for sets. - // It's up to the caller to Unref() the index Val* when done - // with it. - std::unordered_map ToMap() const; + std::unordered_map ToMap() const; void SetAttrs(detail::AttributesPtr attrs);