diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-10-25 20:03:55 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-10-25 20:03:55 +0000 |
commit | fa2cdd0bb89330cfd9a6c49c4705da2a3cb02834 (patch) | |
tree | 558ff9feb41839be63b2a58168dc9623ecd3a283 /src/base.cpp | |
parent | 5c05313b6e979968d25a57d04da320a0c1be1b6c (diff) |
Force heap allocation of refcountbase, create usecountbase for non-allocation reference counting
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11978 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/base.cpp')
-rw-r--r-- | src/base.cpp | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/src/base.cpp b/src/base.cpp index bf4232754..8e81f7b73 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -43,7 +43,6 @@ CullResult::CullResult() // 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) { @@ -58,21 +57,26 @@ void refcountbase::operator delete(void* obj) ::operator delete(obj); } -refcountbase::refcountbase() +refcountbase::refcountbase() : refcount(0) { - if (this == last_heap) - refcount = 0; - else - refcount = top_bit; + if (this != last_heap) + throw CoreException("Reference allocate on the stack!"); } refcountbase::~refcountbase() { - if ((refcount & ~top_bit) && ServerInstance && ServerInstance->Logs) - ServerInstance->Logs->Log("CULLLIST", DEBUG, "refcountbase::~ @%p with refcount %x", + 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) { } @@ -297,12 +301,3 @@ ModuleException::ModuleException(const std::string &message, Module* who) { } -ModuleRef::ModuleRef(Module* v) : value(v) -{ - if (value) inc(value); -} - -ModuleRef::~ModuleRef() -{ - if (value) dec(value); -} |