diff --git a/src/CompHash.cc b/src/CompHash.cc index 4a93675a28..3a35282f48 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -333,10 +333,9 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, } -HashKey* CompositeHash::ComputeHash(const Val* v, bool type_check) const +HashKey* CompositeHash::ComputeHash(const Val& argv, bool type_check) const { - if ( ! v ) - reporter->InternalError("null value given to CompositeHash::ComputeHash"); + auto v = &argv; if ( is_singleton ) return ComputeSingletonHash(v, type_check); @@ -350,7 +349,7 @@ HashKey* CompositeHash::ComputeHash(const Val* v, bool type_check) const // be okay; the only thing is that the ListVal unref's it. Val* ncv = (Val*) v; lv.Append({NewRef{}, ncv}); - HashKey* hk = ComputeHash(&lv, type_check); + HashKey* hk = ComputeHash(lv, type_check); return hk; } diff --git a/src/CompHash.h b/src/CompHash.h index 849245b9db..27eb547e92 100644 --- a/src/CompHash.h +++ b/src/CompHash.h @@ -14,8 +14,12 @@ public: ~CompositeHash(); // Compute the hash corresponding to the given index val, - // or 0 if it fails to typecheck. - HashKey* ComputeHash(const Val* v, bool type_check) const; + // or nullptr if it fails to typecheck. + HashKey* ComputeHash(const Val& v, bool type_check) const; + + [[deprecated("Remove in v4.1. Pass a Val& instead.")]] + HashKey* ComputeHash(const Val* v, bool type_check) const + { return ComputeHash(*v, type_check); } // Given a hash key, recover the values used to create it. IntrusivePtr RecoverVals(const HashKey* k) const; diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index 5c822f7fe5..6846485503 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -739,14 +739,14 @@ bool BloomFilterVal::Typify(IntrusivePtr arg_type) void BloomFilterVal::Add(const Val* val) { - HashKey* key = hash->ComputeHash(val, true); + HashKey* key = hash->ComputeHash(*val, true); bloom_filter->Add(key); delete key; } size_t BloomFilterVal::Count(const Val* val) const { - HashKey* key = hash->ComputeHash(val, true); + HashKey* key = hash->ComputeHash(*val, true); size_t cnt = bloom_filter->Count(key); delete key; return cnt; @@ -900,7 +900,7 @@ bool CardinalityVal::Typify(IntrusivePtr arg_type) void CardinalityVal::Add(const Val* val) { - HashKey* key = hash->ComputeHash(val, true); + HashKey* key = hash->ComputeHash(*val, true); c->AddElement(key->Hash()); delete key; } diff --git a/src/Stmt.cc b/src/Stmt.cc index 9bc48835c3..09a8d299f8 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -719,7 +719,7 @@ SwitchStmt::~SwitchStmt() bool SwitchStmt::AddCaseLabelValueMapping(const Val* v, int idx) { - HashKey* hk = comp_hash->ComputeHash(v, true); + HashKey* hk = comp_hash->ComputeHash(*v, true); if ( ! hk ) { @@ -763,7 +763,7 @@ std::pair SwitchStmt::FindCaseLabelMatch(const Val* v) const // Find matching expression cases. if ( case_label_value_map.Length() ) { - HashKey* hk = comp_hash->ComputeHash(v, true); + HashKey* hk = comp_hash->ComputeHash(*v, true); if ( ! hk ) { diff --git a/src/Val.cc b/src/Val.cc index 9e293a51b9..6ba6c29db4 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1508,7 +1508,7 @@ void TableVal::CheckExpireAttr(attr_tag at) bool TableVal::Assign(IntrusivePtr index, IntrusivePtr new_val) { - HashKey* k = ComputeHash(index.get()); + HashKey* k = ComputeHash(*index); if ( ! k ) { index->Error("index type doesn't match table", table_type->Indices()); @@ -1910,7 +1910,7 @@ IntrusivePtr TableVal::Lookup(Val* index, bool use_default_val) if ( tbl->Length() > 0 ) { - HashKey* k = ComputeHash(index); + HashKey* k = ComputeHash(*index); if ( k ) { TableEntryVal* v = AsTable()->Lookup(k); @@ -1985,7 +1985,7 @@ bool TableVal::UpdateTimestamp(Val* index) v = (TableEntryVal*) subnets->Lookup(index); else { - HashKey* k = ComputeHash(index); + HashKey* k = ComputeHash(*index); if ( ! k ) return false; @@ -2070,7 +2070,7 @@ void TableVal::CallChangeFunc(const Val* index, Val* old_value, OnChangeType tpe IntrusivePtr TableVal::Delete(const Val* index) { - HashKey* k = ComputeHash(index); + HashKey* k = ComputeHash(*index); TableEntryVal* v = k ? AsNonConstTable()->RemoveEntry(k) : nullptr; IntrusivePtr va; @@ -2594,7 +2594,7 @@ unsigned int TableVal::MemoryAllocation() const + table_hash->MemoryAllocation(); } -HashKey* TableVal::ComputeHash(const Val* index) const +HashKey* TableVal::ComputeHash(const Val& index) const { return table_hash->ComputeHash(index, true); } diff --git a/src/Val.h b/src/Val.h index a552ec0e53..f5f567e06b 100644 --- a/src/Val.h +++ b/src/Val.h @@ -892,7 +892,11 @@ public: timer = nullptr; } - HashKey* ComputeHash(const Val* index) const; + HashKey* ComputeHash(const Val& index) const; + + [[deprecated("Remove in v4.1. Pass a Val& instead.")]] + HashKey* ComputeHash(const Val* index) const + { return ComputeHash(*index); } notifier::Modifiable* Modifiable() override { return this; } diff --git a/src/file_analysis/AnalyzerSet.cc b/src/file_analysis/AnalyzerSet.cc index b2ca39f954..01361339e7 100644 --- a/src/file_analysis/AnalyzerSet.cc +++ b/src/file_analysis/AnalyzerSet.cc @@ -163,11 +163,11 @@ bool AnalyzerSet::RemoveMod::Perform(AnalyzerSet* set) HashKey* AnalyzerSet::GetKey(const file_analysis::Tag& t, RecordVal* args) const { - ListVal* lv = new ListVal(TYPE_ANY); + auto lv = make_intrusive(TYPE_ANY); lv->Append(t.AsVal()); lv->Append({NewRef{}, args}); - HashKey* key = analyzer_hash->ComputeHash(lv, true); - Unref(lv); + HashKey* key = analyzer_hash->ComputeHash(*lv, true); + if ( ! key ) reporter->InternalError("AnalyzerArgs type mismatch"); diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 049d81d359..ee3e803f59 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1248,7 +1248,7 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) oldval = stream->tab->Lookup(idxval, false); } - HashKey* k = stream->tab->ComputeHash(idxval); + HashKey* k = stream->tab->ComputeHash(*idxval); if ( ! k ) reporter->InternalError("could not hash"); diff --git a/src/probabilistic/Topk.cc b/src/probabilistic/Topk.cc index f0c55c2e64..12515505a5 100644 --- a/src/probabilistic/Topk.cc +++ b/src/probabilistic/Topk.cc @@ -29,7 +29,7 @@ void TopkVal::Typify(IntrusivePtr t) HashKey* TopkVal::GetHash(Val* v) const { - HashKey* key = hash->ComputeHash(v, true); + HashKey* key = hash->ComputeHash(*v, true); assert(key); return key; }