mirror of
https://github.com/anope/anope.git
synced 2026-07-02 14:13:12 +02:00
This Serialize::Destroy method isn't actually needed anymore. Fixes weirdness from a few Serializable items we had on the stack. Added a comment about why operator< in Reference fails.
This commit is contained in:
+11
-4
@@ -121,10 +121,17 @@ class Reference : public ReferenceBase
|
||||
return NULL;
|
||||
}
|
||||
|
||||
inline bool operator<(const Reference<T> &other) const
|
||||
{
|
||||
return this < &other;
|
||||
}
|
||||
/** Note that we can't have an operator< that returns this->ref < other.ref
|
||||
* because this function is used to sort objects in containers (such as set
|
||||
* or map), and if the references themselves can change if the object they
|
||||
* refer to is invalidated or changed, then this screws with the order that
|
||||
* the objects would be in the container without properly adjusting the
|
||||
* container, resulting in weird stuff.
|
||||
*
|
||||
* As such, we don't allow storing references in containers that require
|
||||
* operator<, because they would not be able to compare what the references
|
||||
* actually referred to.
|
||||
*/
|
||||
|
||||
inline bool operator==(const Reference<T> &other)
|
||||
{
|
||||
|
||||
@@ -83,11 +83,6 @@ class CoreExport Serializable : public virtual Base
|
||||
/* Unique ID (per type, not globally) for this object */
|
||||
unsigned int id;
|
||||
|
||||
/* Destroys this object. This is effectively the same thing as
|
||||
* delete, however it properly cleans up after this object.
|
||||
*/
|
||||
void Destroy();
|
||||
|
||||
/** Marks the object as potentially being updated "soon".
|
||||
*/
|
||||
void QueueUpdate();
|
||||
|
||||
@@ -185,7 +185,7 @@ class DBSQL : public Module, public Pipe
|
||||
void OnSerializableDestruct(Serializable *obj) anope_override
|
||||
{
|
||||
Serialize::Type *s_type = obj->GetSerializableType();
|
||||
if (s_type)
|
||||
if (s_type && obj->id > 0)
|
||||
this->RunBackground("DELETE FROM `" + this->prefix + s_type->GetName() + "` WHERE `id` = " + stringify(obj->id));
|
||||
this->updated_items.erase(obj);
|
||||
}
|
||||
|
||||
@@ -156,7 +156,8 @@ class DBMySQL : public Module, public Pipe
|
||||
Serialize::Type *s_type = obj->GetSerializableType();
|
||||
if (s_type)
|
||||
{
|
||||
this->RunQuery("DELETE FROM `" + this->prefix + s_type->GetName() + "` WHERE `id` = " + stringify(obj->id));
|
||||
if (obj->id > 0)
|
||||
this->RunQuery("DELETE FROM `" + this->prefix + s_type->GetName() + "` WHERE `id` = " + stringify(obj->id));
|
||||
s_type->objects.erase(obj->id);
|
||||
}
|
||||
this->updated_items.erase(obj);
|
||||
|
||||
+2
-10
@@ -67,6 +67,8 @@ Serializable::Serializable(const Serializable &other) : last_commit(NULL), last_
|
||||
|
||||
Serializable::~Serializable()
|
||||
{
|
||||
FOREACH_MOD(I_OnSerializableDestruct, OnSerializableDestruct(this));
|
||||
|
||||
SerializableItems->erase(this->s_iter);
|
||||
delete last_commit;
|
||||
}
|
||||
@@ -76,16 +78,6 @@ Serializable &Serializable::operator=(const Serializable &)
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Serializable::Destroy()
|
||||
{
|
||||
if (!this)
|
||||
return;
|
||||
|
||||
FOREACH_MOD(I_OnSerializableDestruct, OnSerializableDestruct(this));
|
||||
|
||||
delete this;
|
||||
}
|
||||
|
||||
void Serializable::QueueUpdate()
|
||||
{
|
||||
/* Schedule updater */
|
||||
|
||||
Reference in New Issue
Block a user