From a883362c149770873c52fa017bb9a1678e737410 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 17 May 2012 02:03:22 -0400 Subject: Fixed not always calling operator bool() in dynamic_reference, which would mess up service references and do weird things --- include/base.h | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/base.h b/include/base.h index cc0e84bf9..9ea0dc630 100644 --- a/include/base.h +++ b/include/base.h @@ -53,18 +53,20 @@ class dynamic_reference : public dynamic_reference_base dynamic_reference(const dynamic_reference &other) : dynamic_reference_base(other), ref(other.ref) { - if (*this) + if (operator bool()) ref->AddReference(this); } virtual ~dynamic_reference() { - if (*this) - { + if (operator bool()) ref->DelReference(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. + */ virtual operator bool() { if (!this->invalid) @@ -72,31 +74,36 @@ class dynamic_reference : public dynamic_reference_base return false; } - virtual inline operator T*() const + inline operator T*() { - if (!this->invalid) + if (operator bool()) return this->ref; return NULL; } - virtual inline T* operator->() + inline T* operator->() { - if (!this->invalid) + if (operator bool()) return this->ref; return NULL; } - virtual inline void operator=(T *newref) + inline void operator=(T *newref) { - if (*this) + if (operator bool()) this->ref->DelReference(this); this->ref = newref; this->invalid = false; - if (*this) + if (operator bool()) this->ref->AddReference(this); } - virtual inline bool operator==(const dynamic_reference &other) const + inline bool operator<(const dynamic_reference &other) const + { + return this < &other; + } + + inline bool operator==(const dynamic_reference &other) { if (!this->invalid) return this->ref == other; -- cgit