state-holding fix: track unique identifiers for Func's in CompHash's, not Func's themselves

This commit is contained in:
Vern Paxson 2022-04-16 16:17:57 -07:00
parent 0235541a95
commit 323b919eef
4 changed files with 45 additions and 31 deletions

View file

@ -4,7 +4,7 @@
#include <memory>
#include "zeek/IntrusivePtr.h"
#include "zeek/Func.h"
#include "zeek/Type.h"
namespace zeek
@ -61,6 +61,18 @@ protected:
bool EnsureTypeReserve(HashKey& hk, const Val* v, Type* bt, bool type_check) const;
// The following are for allowing hashing of function values.
// These can occur, for example, in sets of predicates that get
// iterated over. We use pointers in order to keep storage
// lower for the common case of these not being needed.
std::unique_ptr<std::unordered_map<const Func*, uint32_t>> func_to_func_id;
std::unique_ptr<std::vector<FuncPtr>> func_id_to_func;
void BuildFuncMappings()
{
func_to_func_id = std::make_unique<std::unordered_map<const Func*, uint32_t>>();
func_id_to_func = std::make_unique<std::vector<FuncPtr>>();
}
TypeListPtr type;
bool is_singleton = false; // if just one type in index
};