diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 051a7f98d2..3be382b561 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -28,8 +28,6 @@ EventHandler::operator bool() const const IntrusivePtr& EventHandler::GetType(bool check_export) { - static IntrusivePtr nil; - if ( type ) return type; @@ -37,10 +35,10 @@ const IntrusivePtr& EventHandler::GetType(bool check_export) check_export); if ( ! id ) - return nil; + return FuncType::nil; if ( id->GetType()->Tag() != TYPE_FUNC ) - return nil; + return FuncType::nil; type = id->GetType(); return type; diff --git a/src/Func.h b/src/Func.h index 6b96373045..1f0665ad54 100644 --- a/src/Func.h +++ b/src/Func.h @@ -30,6 +30,8 @@ class Scope; class Func : public BroObj { public: + static inline const IntrusivePtr nil; + enum Kind { BRO_FUNC, BUILTIN_FUNC }; explicit Func(Kind arg_kind); @@ -99,10 +101,7 @@ public: uint32_t GetUniqueFuncID() const { return unique_id; } static const IntrusivePtr& GetFuncPtrByID(uint32_t id) - { - static IntrusivePtr nil; - return id >= unique_ids.size() ? nil : unique_ids[id]; - } + { return id >= unique_ids.size() ? Func::nil : unique_ids[id]; } protected: Func(); diff --git a/src/ID.h b/src/ID.h index 0cce2e4239..efd3aa655a 100644 --- a/src/ID.h +++ b/src/ID.h @@ -28,6 +28,8 @@ typedef enum { SCOPE_FUNCTION, SCOPE_MODULE, SCOPE_GLOBAL } IDScope; class ID final : public BroObj, public notifier::Modifiable { public: + static inline const IntrusivePtr nil; + ID(const char* name, IDScope arg_scope, bool arg_is_export); ~ID() override; diff --git a/src/Scope.cc b/src/Scope.cc index d6c0c343e1..9378b477df 100644 --- a/src/Scope.cc +++ b/src/Scope.cc @@ -14,7 +14,6 @@ typedef PList scope_list; static scope_list scopes; static Scope* top_scope; -static IntrusivePtr nil_id; Scope::Scope(IntrusivePtr id, attr_list* al) : scope_id(std::move(id)) @@ -64,7 +63,7 @@ const IntrusivePtr& Scope::Find(std::string_view name) const if ( entry != local.end() ) return entry->second; - return nil_id; + return ID::nil; } IntrusivePtr Scope::Remove(std::string_view name) @@ -172,7 +171,7 @@ const IntrusivePtr& lookup_ID(const char* name, const char* curr_module, return global_scope()->Find(globalname); } - return nil_id; + return ID::nil; } IntrusivePtr install_ID(const char* name, const char* module_name, diff --git a/src/Type.cc b/src/Type.cc index 02956ed517..411ee79450 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -111,8 +111,7 @@ int BroType::MatchesIndex(ListExpr* const index) const const IntrusivePtr& BroType::Yield() const { - static IntrusivePtr nil; - return nil; + return BroType::nil; } bool BroType::HasField(const char* /* field */) const diff --git a/src/Type.h b/src/Type.h index 1bb81822d5..f23ed24e6f 100644 --- a/src/Type.h +++ b/src/Type.h @@ -141,6 +141,8 @@ const int MATCHES_INDEX_VECTOR = 2; class BroType : public BroObj { public: + static inline const IntrusivePtr nil; + explicit BroType(TypeTag tag, bool base_type = false); // Performs a shallow clone operation of the Bro type. @@ -456,6 +458,8 @@ protected: class FuncType final : public BroType { public: + static inline const IntrusivePtr nil; + /** * Prototype is only currently used for events and hooks which declare * multiple signature prototypes that allow users to have handlers diff --git a/src/Val.cc b/src/Val.cc index e7a006ca67..5437122493 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1897,9 +1897,6 @@ IntrusivePtr TableVal::Default(const IntrusivePtr& index) const IntrusivePtr& TableVal::Find(const IntrusivePtr& index) { - static IntrusivePtr nil; - static IntrusivePtr exists = val_mgr->True(); - if ( subnets ) { TableEntryVal* v = (TableEntryVal*) subnets->Lookup(index.get()); @@ -1911,10 +1908,10 @@ const IntrusivePtr& TableVal::Find(const IntrusivePtr& index) if ( v->GetVal() ) return v->GetVal(); - return exists; + return val_mgr->True(); } - return nil; + return Val::nil; } const PDict* tbl = AsTable(); @@ -1935,12 +1932,12 @@ const IntrusivePtr& TableVal::Find(const IntrusivePtr& index) if ( v->GetVal() ) return v->GetVal(); - return exists; + return val_mgr->True(); } } } - return nil; + return Val::nil; } IntrusivePtr TableVal::FindOrDefault(const IntrusivePtr& index) @@ -3139,10 +3136,8 @@ bool VectorVal::AddTo(Val* val, bool /* is_first_init */) const const IntrusivePtr& VectorVal::At(unsigned int index) const { - static IntrusivePtr nil; - if ( index >= val.vector_val->size() ) - return nil; + return Val::nil; return (*val.vector_val)[index]; } diff --git a/src/Val.h b/src/Val.h index 918c307e04..d1960822b0 100644 --- a/src/Val.h +++ b/src/Val.h @@ -118,6 +118,8 @@ union BroValUnion { class Val : public BroObj { public: + static inline const IntrusivePtr nil; + Val(double d, TypeTag t) : val(d), type(base_type(t)) {}