diff options
-rw-r--r-- | include/serialize.h | 6 | ||||
-rw-r--r-- | src/serialize.cpp | 9 |
2 files changed, 12 insertions, 3 deletions
diff --git a/include/serialize.h b/include/serialize.h index 496110fda..f83c9bfd3 100644 --- a/include/serialize.h +++ b/include/serialize.h @@ -60,9 +60,9 @@ class CoreExport Serializable : public virtual Base * constructed before other objects are if it isn't. */ static std::list<Serializable *> *SerializableItems; + friend class Serialize::Type; /* The type of item this object is */ Serialize::Type *s_type; - private: /* Iterator into serializable_items */ std::list<Serializable *>::iterator s_iter; /* The hash of the last serialized form of this object commited to the database */ @@ -109,7 +109,7 @@ class CoreExport Serializable : public virtual Base * of class that inherits from Serialiable. Used for unserializing objects * of this type, as it requires a function pointer to a static member function. */ -class CoreExport Serialize::Type +class CoreExport Serialize::Type : public Base { typedef Serializable* (*unserialize_func)(Serializable *obj, Serialize::Data &); @@ -188,7 +188,7 @@ class Serialize::Checker { Anope::string name; T obj; - mutable Serialize::Type *type; + mutable ::Reference<Serialize::Type> type; inline void Check() const { diff --git a/src/serialize.cpp b/src/serialize.cpp index 521704df4..570463dc3 100644 --- a/src/serialize.cpp +++ b/src/serialize.cpp @@ -124,6 +124,15 @@ Type::Type(const Anope::string &n, unserialize_func f, Module *o) : name(n), un Type::~Type() { + /* null the type of existing serializable objects of this type */ + for (std::list<Serializable *>::iterator it = Serializable::SerializableItems->begin(); it != Serializable::SerializableItems->end(); ++it) + { + Serializable *s = *it; + + if (s->s_type == this) + s->s_type = NULL; + } + std::vector<Anope::string>::iterator it = std::find(TypeOrder.begin(), TypeOrder.end(), this->name); if (it != TypeOrder.end()) TypeOrder.erase(it); |