summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/base.h26
-rw-r--r--include/serialize.h46
-rw-r--r--modules/database/db_sql_live.cpp2
-rw-r--r--modules/extra/m_mysql.cpp2
-rw-r--r--modules/extra/m_sqlite.cpp2
-rw-r--r--src/serialize.cpp5
6 files changed, 50 insertions, 33 deletions
diff --git a/include/base.h b/include/base.h
index 6fb974ec4..3bf9eefef 100644
--- a/include/base.h
+++ b/include/base.h
@@ -73,6 +73,22 @@ class Reference : public ReferenceBase
ref->DelReference(this);
}
+ inline Reference<T>& operator=(const Reference<T> &other)
+ {
+ if (this != &other)
+ {
+ if (*this)
+ this->ref->DelReference(this);
+
+ this->ref = other.ref;
+ this->invalid = other.invalid;
+
+ if (*this)
+ this->ref->AddReference(this);
+ }
+ return *this;
+ }
+
/* We explicitly call operator bool here in several places to prevent other
* operators, such operator T*, from being called instead, which will mess
* with any class inheriting from this that overloads this operator.
@@ -105,16 +121,6 @@ class Reference : public ReferenceBase
return NULL;
}
- inline void operator=(T *newref)
- {
- if (operator bool())
- this->ref->DelReference(this);
- this->ref = newref;
- this->invalid = false;
- if (operator bool())
- this->ref->AddReference(this);
- }
-
inline bool operator<(const Reference<T> &other) const
{
return this < &other;
diff --git a/include/serialize.h b/include/serialize.h
index edbf1facf..a7ac33dfa 100644
--- a/include/serialize.h
+++ b/include/serialize.h
@@ -258,18 +258,34 @@ class Serialize::Reference : public ReferenceBase
obj->AddReference(this);
}
- Reference(const Reference<T> &other) : ref(other.ref)
+ Reference(const Reference<T> &other) : ReferenceBase(other), ref(other.ref)
{
- if (*this)
+ if (ref && !invalid)
this->ref->AddReference(this);
}
~Reference()
{
- if (*this)
+ if (ref && !invalid)
this->ref->DelReference(this);
}
+ inline Reference<T>& operator=(const Reference<T> &other)
+ {
+ if (this != &other)
+ {
+ if (ref && !invalid)
+ this->ref->DelReference(this);
+
+ this->ref = other.ref;
+ this->invalid = other.invalid;
+
+ if (ref && !invalid)
+ this->ref->AddReference(this);
+ }
+ return *this;
+ }
+
inline operator bool() const
{
if (!this->invalid)
@@ -277,25 +293,15 @@ class Serialize::Reference : public ReferenceBase
return false;
}
- inline void operator=(T *newref)
- {
- if (*this)
- this->ref->DelReference(this);
-
- this->ref = newref;
- this->invalid = false;
-
- if (newref)
- this->ref->AddReference(this);
- }
-
inline operator T*() const
{
if (!this->invalid)
{
if (this->ref)
+ // This can invalidate me
this->ref->QueueUpdate();
- return this->ref;
+ if (!this->invalid)
+ return this->ref;
}
return NULL;
}
@@ -305,8 +311,10 @@ class Serialize::Reference : public ReferenceBase
if (!this->invalid)
{
if (this->ref)
+ // This can invalidate me
this->ref->QueueUpdate();
- return this->ref;
+ if (!this->invalid)
+ return this->ref;
}
return NULL;
}
@@ -316,8 +324,10 @@ class Serialize::Reference : public ReferenceBase
if (!this->invalid)
{
if (this->ref)
+ // This can invalidate me
this->ref->QueueUpdate();
- return this->ref;
+ if (!this->invalid)
+ return this->ref;
}
return NULL;
}
diff --git a/modules/database/db_sql_live.cpp b/modules/database/db_sql_live.cpp
index 8d8836055..0461e40b9 100644
--- a/modules/database/db_sql_live.cpp
+++ b/modules/database/db_sql_live.cpp
@@ -192,8 +192,8 @@ class DBMySQL : public Module, public Pipe
std::map<unsigned int, Serializable *>::iterator it = obj->objects.find(id);
if (it != obj->objects.end())
{
- it->second->Destroy();
obj->objects.erase(it);
+ it->second->Destroy(); // This also tries to remove this object from the map
}
}
else
diff --git a/modules/extra/m_mysql.cpp b/modules/extra/m_mysql.cpp
index a8433fd38..d431ba909 100644
--- a/modules/extra/m_mysql.cpp
+++ b/modules/extra/m_mysql.cpp
@@ -372,7 +372,7 @@ std::vector<Query> MySQLService::CreateTable(const Anope::string &table, const D
if (known_cols.empty())
{
Anope::string query_text = "CREATE TABLE `" + table + "` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT,"
- " `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP";
+ " `timestamp` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP";
for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
{
known_cols.insert(it->first);
diff --git a/modules/extra/m_sqlite.cpp b/modules/extra/m_sqlite.cpp
index 5d59c3eb9..69fd16b9f 100644
--- a/modules/extra/m_sqlite.cpp
+++ b/modules/extra/m_sqlite.cpp
@@ -209,7 +209,7 @@ std::vector<Query> SQLiteService::CreateTable(const Anope::string &table, const
if (known_cols.empty())
{
- Anope::string query_text = "CREATE TABLE `" + table + "` (`id` INTEGER PRIMARY KEY, `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP";
+ Anope::string query_text = "CREATE TABLE `" + table + "` (`id` INTEGER PRIMARY KEY, `timestamp` timestamp DEFAULT CURRENT_TIMESTAMP";
for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it)
{
diff --git a/src/serialize.cpp b/src/serialize.cpp
index 0fff92fab..e03eb7ebd 100644
--- a/src/serialize.cpp
+++ b/src/serialize.cpp
@@ -88,10 +88,11 @@ void Serializable::Destroy()
void Serializable::QueueUpdate()
{
- /* Check for modifications now */
- FOREACH_MOD(I_OnSerializeCheck, OnSerializeCheck(this->GetSerializableType()));
/* Schedule updater */
FOREACH_MOD(I_OnSerializableUpdate, OnSerializableUpdate(this));
+
+ /* Check for modifications now - this can delete this object! */
+ FOREACH_MOD(I_OnSerializeCheck, OnSerializeCheck(this->GetSerializableType()));
}
bool Serializable::IsCached(Serialize::Data *data)