]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/base.cpp
Move some local-only fields to LocalUser
[user/henk/code/inspircd.git] / src / base.cpp
index 389f3915a06fb96bfb8becc30f107d4664030c2b..bf42327544dd925b6b951ed03fe226ec2d998478 100644 (file)
@@ -41,14 +41,35 @@ CullResult::CullResult()
 {
 }
 
-refcountbase::refcountbase() : refcount(0)
+// This trick detects heap allocations of refcountbase objects
+static void* last_heap = NULL;
+static const unsigned int top_bit = 1 << (8*sizeof(unsigned int) - 1);
+
+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()
+{
+       if (this == last_heap)
+               refcount = 0;
+       else
+               refcount = top_bit;
 }
 
 refcountbase::~refcountbase()
 {
-       if (refcount && ServerInstance && ServerInstance->Logs)
-               ServerInstance->Logs->Log("CULLLIST", DEBUG, "refcountbase::~ @%p with refcount %d",
+       if ((refcount & ~top_bit) && ServerInstance && ServerInstance->Logs)
+               ServerInstance->Logs->Log("CULLLIST", DEBUG, "refcountbase::~ @%p with refcount %x",
                        (void*)this, refcount);
 }
 
@@ -270,3 +291,18 @@ void StringExtItem::free(void* item)
 {
        delete static_cast<std::string*>(item);
 }
+
+ModuleException::ModuleException(const std::string &message, Module* who)
+       : CoreException(message, who ? who->ModuleSourceFile : "A Module")
+{
+}
+
+ModuleRef::ModuleRef(Module* v) : value(v)
+{
+       if (value) inc(value);
+}
+
+ModuleRef::~ModuleRef()
+{
+       if (value) dec(value);
+}