diff --git a/src/ID.h b/src/ID.h index a1cbe494d3..9c9a842c39 100644 --- a/src/ID.h +++ b/src/ID.h @@ -70,10 +70,6 @@ public: bool IsRedefinable() const { return FindAttr(ATTR_REDEF) != 0; } - // Returns true if ID is one of those internal globally unique IDs - // to which MutableVals are bound (there name start with a '#'). - bool IsInternalGlobal() const { return name && name[0] == '#'; } - void SetAttrs(Attributes* attr); void AddAttrs(Attributes* attr); void RemoveAttr(attr_tag a); diff --git a/src/StateAccess.cc b/src/StateAccess.cc index 7d7c397981..b580215271 100644 --- a/src/StateAccess.cc +++ b/src/StateAccess.cc @@ -14,8 +14,8 @@ notifier::Registry::~Registry() void notifier::Registry::Register(Modifiable* m, notifier::Notifier* notifier) { - DBG_LOG(DBG_NOTIFIERS, "registering modifiable %p for notifier %s", - m, notifier->Name()); + DBG_LOG(DBG_NOTIFIERS, "registering modifiable %p for notifier %p", + m, notifier); registrations.insert({m, notifier}); ++m->notifiers; @@ -23,16 +23,16 @@ void notifier::Registry::Register(Modifiable* m, notifier::Notifier* notifier) void notifier::Registry::Unregister(Modifiable* m, notifier::Notifier* notifier) { - DBG_LOG(DBG_NOTIFIERS, "unregistering modifiable %p from notifier %s", - m, notifier->Name()); + DBG_LOG(DBG_NOTIFIERS, "unregistering modifiable %p from notifier %p", + m, notifier); auto x = registrations.equal_range(m); for ( auto i = x.first; i != x.second; i++ ) { if ( i->second == notifier ) { - registrations.erase(i); --i->first->notifiers; + registrations.erase(i); break; } } @@ -40,9 +40,14 @@ void notifier::Registry::Unregister(Modifiable* m, notifier::Notifier* notifier) void notifier::Registry::Unregister(Modifiable* m) { + DBG_LOG(DBG_NOTIFIERS, "unregistering modifiable %p from all notifiers", + m); + auto x = registrations.equal_range(m); for ( auto i = x.first; i != x.second; i++ ) - Unregister(m, i->second); + --i->first->notifiers; + + registrations.erase(x.first, x.second); } void notifier::Registry::Modified(Modifiable* m) @@ -54,8 +59,8 @@ void notifier::Registry::Modified(Modifiable* m) i->second->Modified(m); } -const char* notifier::Notifier::Name() const +notifier::Modifiable::~Modifiable() { - return fmt("%p", this); + if ( notifiers ) + registry.Unregister(this); } - diff --git a/src/StateAccess.h b/src/StateAccess.h index 91a7fa6186..b769e320c0 100644 --- a/src/StateAccess.h +++ b/src/StateAccess.h @@ -18,6 +18,7 @@ #include #include "util.h" +#include "DebugLogger.h" namespace notifier { @@ -25,11 +26,18 @@ class Modifiable; class Notifier { public: - virtual ~Notifier() { } + Notifier() + { + DBG_LOG(DBG_NOTIFIERS, "creating notifier %p", this); + } - // Called afger a change has been performed. + virtual ~Notifier() + { + DBG_LOG(DBG_NOTIFIERS, "destroying notifier %p", this); + } + + // Called after a change has been performed. virtual void Modified(Modifiable* m) = 0; - virtual const char* Name() const; // for debugging }; // Singleton class. @@ -67,12 +75,7 @@ protected: friend class Registry; Modifiable() {} - ~Modifiable() - { - if ( notifiers ) - registry.Unregister(this); - - }; + virtual ~Modifiable(); void Modified() { diff --git a/src/Stats.cc b/src/Stats.cc index 1d2a2c8ad8..9489f12f93 100644 --- a/src/Stats.cc +++ b/src/Stats.cc @@ -255,7 +255,7 @@ void ProfileLogger::Log() while ( (id = globals->NextEntry(c)) ) // We don't show/count internal globals as they are always // contained in some other global user-visible container. - if ( id->HasVal() && ! id->IsInternalGlobal() ) + if ( id->HasVal() ) { Val* v = id->ID_Val(); diff --git a/src/Trigger.cc b/src/Trigger.cc index c1295b8218..8de5dff5bd 100644 --- a/src/Trigger.cc +++ b/src/Trigger.cc @@ -385,7 +385,7 @@ void Trigger::Register(ID* id) notifier::registry.Register(id, this); Ref(id); - objs.push_back(id); + objs.push_back({id, id}); } void Trigger::Register(Val* val) @@ -397,13 +397,18 @@ void Trigger::Register(Val* val) notifier::registry.Register(val->Modifiable(), this); Ref(val); - objs.push_back(val); + objs.emplace_back(val, val->Modifiable()); } void Trigger::UnregisterAll() { + DBG_LOG(DBG_NOTIFIERS, "%s: unregistering all", Name()); + for ( auto o : objs ) - Unref(o); // this will unregister with the registry as well + { + notifier::registry.Unregister(o.second, this); + Unref(o.first); + } objs.clear(); } diff --git a/src/Trigger.h b/src/Trigger.h index fe7d425a72..3004d30732 100644 --- a/src/Trigger.h +++ b/src/Trigger.h @@ -64,7 +64,7 @@ public: void Modified(notifier::Modifiable* m) override { QueueTrigger(this); } - const char* Name() const override; + const char* Name() const; static void QueueTrigger(Trigger* trigger); @@ -102,7 +102,7 @@ private: bool delayed; // true if a function call is currently being delayed bool disabled; - std::vector objs; + std::vector> objs; typedef map ValCache; ValCache cache; diff --git a/src/Type.h b/src/Type.h index a97f7360c8..bc8d673443 100644 --- a/src/Type.h +++ b/src/Type.h @@ -693,10 +693,6 @@ bool is_atomic_type(const BroType* t); // True if the given type tag corresponds to a function type. #define IsFunc(t) (t == TYPE_FUNC) -// True if the given type tag corresponds to mutable type. -#define IsMutable(t) \ - (t == TYPE_RECORD || t == TYPE_TABLE || t == TYPE_VECTOR) - // True if the given type type is a vector. #define IsVector(t) (t == TYPE_VECTOR) diff --git a/src/Val.cc b/src/Val.cc index bea9ce4038..0d6f5838ca 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -349,10 +349,6 @@ void Val::ValDescribeReST(ODesc* d) const } } -MutableVal::~MutableVal() - { - } - IntervalVal::IntervalVal(double quantity, double units) : Val(quantity * units, TYPE_INTERVAL) { diff --git a/src/Val.h b/src/Val.h index d98c352f6d..48bbd50cfc 100644 --- a/src/Val.h +++ b/src/Val.h @@ -49,7 +49,6 @@ class RecordVal; class ListVal; class StringVal; class EnumVal; -class MutableVal; class VectorVal; @@ -320,11 +319,6 @@ public: CONST_CONVERTER(TYPE_STRING, StringVal*, AsStringVal) CONST_CONVERTER(TYPE_VECTOR, VectorVal*, AsVectorVal) - bool IsMutableVal() const - { - return IsMutable(type->Tag()); - } - void Describe(ODesc* d) const override; virtual void DescribeReST(ODesc* d) const; @@ -486,14 +480,6 @@ private: extern ValManager* val_mgr; -class MutableVal : public Val { -protected: - explicit MutableVal(BroType* t) : Val(t) {} - - MutableVal() {} - ~MutableVal() override; -}; - #define Microseconds 1e-6 #define Milliseconds 1e-3 #define Seconds 1.0 diff --git a/src/bro.bif b/src/bro.bif index 47b713e4e1..e143cf16e8 100644 --- a/src/bro.bif +++ b/src/bro.bif @@ -1819,7 +1819,7 @@ function global_sizes%(%): var_sizes ID* id; while ( (id = globals->NextEntry(c)) ) - if ( id->HasVal() && ! id->IsInternalGlobal() ) + if ( id->HasVal() ) { Val* id_name = new StringVal(id->Name()); Val* id_size = val_mgr->GetCount(id->ID_Val()->MemoryAllocation()); @@ -1847,9 +1847,6 @@ function global_ids%(%): id_table ID* id; while ( (id = globals->NextEntry(c)) ) { - if ( id->IsInternalGlobal() ) - continue; - RecordVal* rec = new RecordVal(script_id); rec->Assign(0, new StringVal(type_name(id->Type()->Tag()))); rec->Assign(1, val_mgr->GetBool(id->IsExport())); diff --git a/src/input/readers/config/Config.cc b/src/input/readers/config/Config.cc index eca276281c..7c1708babd 100644 --- a/src/input/readers/config/Config.cc +++ b/src/input/readers/config/Config.cc @@ -33,7 +33,7 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend) while ( auto id = globals->NextEntry(c) ) { - if ( id->IsInternalGlobal() || ! id->IsOption() ) + if ( ! id->IsOption() ) continue; if ( id->Type()->Tag() == TYPE_RECORD ||