diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/base.h | 42 | ||||
-rw-r--r-- | include/channels.h | 2 | ||||
-rw-r--r-- | include/dns.h | 6 | ||||
-rw-r--r-- | include/extensible.h | 1 | ||||
-rw-r--r-- | include/hashcomp.h | 10 | ||||
-rw-r--r-- | include/inspsocket.h | 2 | ||||
-rw-r--r-- | include/mode.h | 2 | ||||
-rw-r--r-- | include/modules.h | 6 | ||||
-rw-r--r-- | include/users.h | 2 |
9 files changed, 48 insertions, 25 deletions
diff --git a/include/base.h b/include/base.h index ed03eeac5..624e2174f 100644 --- a/include/base.h +++ b/include/base.h @@ -18,11 +18,17 @@ #include <deque> #include <string> -/** The base class for all inspircd classes. - * Wherever possible, all classes you create should inherit from this, - * giving them the ability to be passed to various core functions - * as 'anonymous' classes. -*/ +/** Dummy class to help enforce culls being parent-called up to classbase */ +class CullResult +{ + CullResult(); + friend class classbase; +}; + +/** The base class for all inspircd classes with a well-defined lifetime. + * Classes that inherit from this may be destroyed through GlobalCulls, + * and may rely on cull() being called prior to their deletion. + */ class CoreExport classbase { public: @@ -33,23 +39,39 @@ class CoreExport classbase * * @return true to allow the delete, or false to halt the delete */ - virtual bool cull(); + virtual CullResult cull(); virtual ~classbase(); + private: + // uncopyable + classbase(const classbase&); + void operator=(const classbase&); }; /** The base class for inspircd classes that support reference counting. * Any objects that do not have a well-defined lifetime should inherit from - * this + * this, and should be assigned to a reference<type> object to establish their + * lifetime. + * + * Reference objects should not hold circular references back to themselves, + * even indirectly; this will cause a memory leak because the count will never + * drop to zero. + * + * Using a normal pointer for the object is recommended if you can assure that + * at least one reference<> will remain as long as that pointer is used; this + * will avoid the slight overhead of changing the reference count. */ -class CoreExport refcountbase : public classbase +class CoreExport refcountbase { unsigned int refcount; public: refcountbase(); - virtual bool cull(); virtual ~refcountbase(); inline unsigned int GetReferenceCount() const { return refcount; } friend class reference_base; + private: + // uncopyable + refcountbase(const refcountbase&); + void operator=(const refcountbase&); }; class CoreExport reference_base @@ -81,7 +103,7 @@ class reference : public reference_base if (value) { int rc = dec(value); - if (rc == 0 && value->cull()) + if (rc == 0) delete value; } } diff --git a/include/channels.h b/include/channels.h index 1ded25a73..7728bb55b 100644 --- a/include/channels.h +++ b/include/channels.h @@ -36,7 +36,7 @@ struct ModResult; /** Holds an entry for a ban list, exemption list, or invite list. * This class contains a single element in a channel list, such as a banlist. */ -class HostItem : public classbase +class HostItem { public: /** Time the item was added diff --git a/include/dns.h b/include/dns.h index 76a69b6e4..1b9ce59a4 100644 --- a/include/dns.h +++ b/include/dns.h @@ -40,7 +40,7 @@ class Module; /** * Result status, used internally */ -class CoreExport DNSResult : public classbase +class CoreExport DNSResult { public: /** Result ID @@ -72,7 +72,7 @@ typedef std::pair<unsigned char*, std::string> DNSInfo; /** Cached item stored in the query cache. */ -class CoreExport CachedQuery : public classbase +class CoreExport CachedQuery { public: /** The cached result data, an IP or hostname @@ -181,7 +181,7 @@ enum ForceProtocol * can occur by calling virtual methods, one is a success situation, and the other * an error situation. */ -class CoreExport Resolver : public Extensible +class CoreExport Resolver { protected: /** diff --git a/include/extensible.h b/include/extensible.h index ff7bce477..ca9c44546 100644 --- a/include/extensible.h +++ b/include/extensible.h @@ -72,6 +72,7 @@ class CoreExport Extensible : public classbase */ inline const ExtensibleStore& GetExtList() const { return extensions; } + virtual CullResult cull(); virtual ~Extensible(); void doUnhookExtensions(const std::vector<ExtensionItem*>& toRemove); }; diff --git a/include/hashcomp.h b/include/hashcomp.h index 6cbc14850..5392c6ae5 100644 --- a/include/hashcomp.h +++ b/include/hashcomp.h @@ -204,7 +204,7 @@ namespace irc * std::string, or a const char* const* array, using overloaded * constructors. */ - class CoreExport stringjoiner : public classbase + class CoreExport stringjoiner { private: @@ -248,7 +248,7 @@ namespace irc * It can then reproduce this list, clamped to a maximum of MAXMODES * values per line. */ - class CoreExport modestacker : public classbase + class CoreExport modestacker { private: /** The mode sequence and its parameters @@ -335,7 +335,7 @@ namespace irc * list will be ":item". This is to allow for parsing 'source' fields * from data. */ - class CoreExport tokenstream : public classbase + class CoreExport tokenstream { private: @@ -394,7 +394,7 @@ namespace irc * the next token, until none remain, at which point the method returns * an empty string. */ - class CoreExport sepstream : public classbase + class CoreExport sepstream { private: /** Original string. @@ -467,7 +467,7 @@ namespace irc * start or end < 0) then GetToken() will return the first element * of the pair of numbers. */ - class CoreExport portparser : public classbase + class CoreExport portparser { private: diff --git a/include/inspsocket.h b/include/inspsocket.h index 84716eae6..3e5c75235 100644 --- a/include/inspsocket.h +++ b/include/inspsocket.h @@ -146,7 +146,7 @@ class CoreExport StreamSocket : public EventHandler */ virtual void Close(); /** This ensures that close is called prior to destructor */ - virtual bool cull(); + virtual CullResult cull(); }; /** * BufferedSocket is an extendable socket class which modules diff --git a/include/mode.h b/include/mode.h index 81858a823..b63e5e6a9 100644 --- a/include/mode.h +++ b/include/mode.h @@ -172,7 +172,7 @@ class CoreExport ModeHandler : public classbase * @param type Type of the mode (MODETYPE_USER or MODETYPE_CHANNEL) */ ModeHandler(Module* me, const std::string& name, char modeletter, ParamSpec params, ModeType type); - virtual bool cull(); + virtual CullResult cull(); virtual ~ModeHandler(); /** * Returns true if the mode is a list mode diff --git a/include/modules.h b/include/modules.h index ef6f5c251..96506f598 100644 --- a/include/modules.h +++ b/include/modules.h @@ -230,7 +230,7 @@ do { \ * error when attempting to load a module compiled against a different API_VERSION. */ template<int api> -class CoreExport VersionBase : public classbase +class CoreExport VersionBase { public: /** Module description @@ -349,7 +349,7 @@ class ConfigReader; * its methods will be called when irc server events occur. class inherited from module must be * instantiated by the ModuleFactory class (see relevent section) for the module to be initialised. */ -class CoreExport Module : public Extensible +class CoreExport Module : public classbase { public: /** File that this module was loaded from @@ -369,7 +369,7 @@ class CoreExport Module : public Extensible /** Clean up prior to destruction * If you override, you must call this AFTER your module's cleanup */ - virtual bool cull(); + virtual CullResult cull(); /** Default destructor. * destroys a module class diff --git a/include/users.h b/include/users.h index ed672450e..0ce9f59ab 100644 --- a/include/users.h +++ b/include/users.h @@ -848,7 +848,7 @@ class CoreExport User : public StreamSocket /** Default destructor */ virtual ~User(); - virtual bool cull(); + virtual CullResult cull(); }; /** Derived from Resolver, and performs user forward/reverse lookups. |