X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fbase.cpp;h=8e81f7b73d09b83a16ef730339edf989c94850d6;hb=2553e4fff7a5a168ef796dcecb73c7365651c897;hp=97722744054f05272da4765e4fe8e84c876ac43c;hpb=e50d016aa23083f81dcf181f68edb81c5b23c78d;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/base.cpp b/src/base.cpp index 977227440..8e81f7b73 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -20,8 +20,7 @@ classbase::classbase() { if (ServerInstance && ServerInstance->Logs) - ServerInstance->Logs->Log("CULLLIST", DEBUG, "classbase::+%s @%p", - typeid(*this).name(), (void*)this); + ServerInstance->Logs->Log("CULLLIST", DEBUG, "classbase::+ @%p", (void*)this); } CullResult classbase::cull() @@ -35,20 +34,47 @@ CullResult classbase::cull() classbase::~classbase() { if (ServerInstance && ServerInstance->Logs) - ServerInstance->Logs->Log("CULLLIST", DEBUG, "classbase::~%s @%p", - typeid(*this).name(), (void*)this); + ServerInstance->Logs->Log("CULLLIST", DEBUG, "classbase::~ @%p", (void*)this); } CullResult::CullResult() { } +// This trick detects heap allocations of refcountbase objects +static void* last_heap = NULL; + +void* refcountbase::operator new(size_t size) +{ + last_heap = ::operator new(size); + return last_heap; +} + +void refcountbase::operator delete(void* obj) +{ + if (last_heap == obj) + last_heap = NULL; + ::operator delete(obj); +} + refcountbase::refcountbase() : refcount(0) { + if (this != last_heap) + throw CoreException("Reference allocate on the stack!"); } refcountbase::~refcountbase() { + if (refcount && ServerInstance && ServerInstance->Logs) + ServerInstance->Logs->Log("CULLLIST", DEBUG, "refcountbase::~ @%p with refcount %d", + (void*)this, refcount); +} + +usecountbase::~usecountbase() +{ + if (usecount && ServerInstance && ServerInstance->Logs) + ServerInstance->Logs->Log("CULLLIST", DEBUG, "usecountbase::~ @%p with refcount %d", + (void*)this, usecount); } ExtensionItem::ExtensionItem(const std::string& Key, Module* mod) : key(Key), owner(mod) @@ -99,12 +125,12 @@ void ExtensionManager::Register(ExtensionItem* item) types.insert(std::make_pair(item->key, item)); } -void ExtensionManager::BeginUnregister(Module* module, std::vector& list) +void ExtensionManager::BeginUnregister(Module* module, std::vector >& list) { - std::map::iterator i = types.begin(); + std::map >::iterator i = types.begin(); while (i != types.end()) { - std::map::iterator me = i++; + std::map >::iterator me = i++; ExtensionItem* item = me->second; if (item->owner == module) { @@ -116,15 +142,15 @@ void ExtensionManager::BeginUnregister(Module* module, std::vector::iterator i = types.find(name); + std::map >::iterator i = types.find(name); if (i == types.end()) return NULL; return i->second; } -void Extensible::doUnhookExtensions(const std::vector& toRemove) +void Extensible::doUnhookExtensions(const std::vector >& toRemove) { - for(std::vector::const_iterator i = toRemove.begin(); i != toRemove.end(); ++i) + for(std::vector >::const_iterator i = toRemove.begin(); i != toRemove.end(); ++i) { ExtensionItem* item = *i; ExtensibleStore::iterator e = extensions.find(item); @@ -136,17 +162,22 @@ void Extensible::doUnhookExtensions(const std::vector& toRemove) } } +static struct DummyExtensionItem : LocalExtItem +{ + DummyExtensionItem() : LocalExtItem("", NULL) {} + void free(void*) {} +} dummy; + Extensible::Extensible() { - extensions[NULL] = NULL; + extensions[&dummy] = NULL; } CullResult Extensible::cull() { for(ExtensibleStore::iterator i = extensions.begin(); i != extensions.end(); ++i) { - if (i->first) - i->first->free(i->second); + i->first->free(i->second); } extensions.clear(); return classbase::cull(); @@ -264,3 +295,9 @@ void StringExtItem::free(void* item) { delete static_cast(item); } + +ModuleException::ModuleException(const std::string &message, Module* who) + : CoreException(message, who ? who->ModuleSourceFile : "A Module") +{ +} +