From cffc8fa13c3d8242efda60d568eb8ce69b6d8235 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Sat, 3 Apr 2021 09:46:22 -0700 Subject: [PATCH 1/3] Move IntrusivePtr relational operators to zeek namespace Otherwise some cases relying on argument-dependent lookup (ADL) fail. --- src/IntrusivePtr.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/IntrusivePtr.h b/src/IntrusivePtr.h index ec08fd0143..ce44f5e441 100644 --- a/src/IntrusivePtr.h +++ b/src/IntrusivePtr.h @@ -198,8 +198,6 @@ IntrusivePtr cast_intrusive(IntrusivePtr p) noexcept return {AdoptRef{}, static_cast(p.release())}; } -} // namespace zeek - // -- comparison to nullptr ---------------------------------------------------- /** @@ -292,3 +290,5 @@ auto operator!=(const zeek::IntrusivePtr& x, const zeek::IntrusivePtr& y) { return x.get() != y.get(); } + +} // namespace zeek From 583310f6dd0f40cf886045d00b504ef72005adfc Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Sat, 3 Apr 2021 09:49:43 -0700 Subject: [PATCH 2/3] Add std::hash specialization for IntrusivePtr --- src/IntrusivePtr.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/IntrusivePtr.h b/src/IntrusivePtr.h index ce44f5e441..7ad37031c8 100644 --- a/src/IntrusivePtr.h +++ b/src/IntrusivePtr.h @@ -4,6 +4,7 @@ #include #include +#include namespace zeek { @@ -292,3 +293,13 @@ auto operator!=(const zeek::IntrusivePtr& x, const zeek::IntrusivePtr& y) } } // 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()); } +}; +} From c0b8fc4d60d3026e4cf32f5c5c691517070742bd Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Sat, 3 Apr 2021 09:51:18 -0700 Subject: [PATCH 3/3] Change TableVal::ToMap() to return ValPtr-indexed maps --- src/Val.cc | 6 +++--- src/Val.h | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) 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);