[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog libbase/smart_ptr.h [release_0_7_2]
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog libbase/smart_ptr.h [release_0_7_2] |
Date: |
Wed, 08 Nov 2006 09:37:46 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Branch: release_0_7_2
Changes by: Sandro Santilli <strk> 06/11/08 09:37:46
Modified files:
. : ChangeLog
libbase : smart_ptr.h
Log message:
* libbase/smart_ptr.h: added invariant testing
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&only_with_tag=release_0_7_2&r1=1.1412.2.117&r2=1.1412.2.118
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/smart_ptr.h?cvsroot=gnash&only_with_tag=release_0_7_2&r1=1.11.2.1&r2=1.11.2.2
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.1412.2.117
retrieving revision 1.1412.2.118
diff -u -b -r1.1412.2.117 -r1.1412.2.118
--- ChangeLog 8 Nov 2006 09:35:00 -0000 1.1412.2.117
+++ ChangeLog 8 Nov 2006 09:37:46 -0000 1.1412.2.118
@@ -1,5 +1,6 @@
2006-11-08 Sandro Santilli <address@hidden>
+ * libbase/smart_ptr.h: added invariant testing
* testsuite/libbase/CurlStreamTest.cpp: added missing
config.h include.
* testsuite/libbase/: Makefile.am, smart_ptrTest.cpp:
Index: libbase/smart_ptr.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/smart_ptr.h,v
retrieving revision 1.11.2.1
retrieving revision 1.11.2.2
diff -u -b -r1.11.2.1 -r1.11.2.2
--- libbase/smart_ptr.h 7 Nov 2006 16:24:03 -0000 1.11.2.1
+++ libbase/smart_ptr.h 8 Nov 2006 09:37:46 -0000 1.11.2.2
@@ -9,7 +9,7 @@
// although the nice thing about templates is that no particular
// ref-counted class is mandated.
-/* $Id: smart_ptr.h,v 1.11.2.1 2006/11/07 16:24:03 strk Exp $ */
+/* $Id: smart_ptr.h,v 1.11.2.2 2006/11/08 09:37:46 strk Exp $ */
#ifndef SMART_PTR_H
#define SMART_PTR_H
@@ -27,6 +27,7 @@
class DSOEXPORT smart_ptr
{
public:
+
smart_ptr(T* ptr)
:
m_ptr(ptr)
@@ -35,9 +36,16 @@
{
m_ptr->add_ref();
}
+ testInvariant();
+ }
+
+ smart_ptr()
+ :
+ m_ptr(NULL)
+ {
+ testInvariant();
}
- smart_ptr() : m_ptr(NULL) {}
smart_ptr(const smart_ptr<T>& s)
:
m_ptr(s.m_ptr)
@@ -46,10 +54,12 @@
{
m_ptr->add_ref();
}
+ testInvariant();
}
~smart_ptr()
{
+ testInvariant();
if (m_ptr)
{
m_ptr->drop_ref();
@@ -57,20 +67,96 @@
}
//operator bool() const { return m_ptr != NULL; }
- void operator=(const smart_ptr<T>& s) { set_ref(s.m_ptr); }
- void operator=(T* ptr) { set_ref(ptr); }
- T* operator->() const { assert(m_ptr); return m_ptr; }
- const T& operator*() const { assert(m_ptr); return *m_ptr; }
- T& operator*() { assert(m_ptr); return *m_ptr; }
- T* get_ptr() const { return m_ptr; }
- bool operator==(const smart_ptr<T>& p) const { return m_ptr ==
p.m_ptr; }
- bool operator!=(const smart_ptr<T>& p) const { return m_ptr !=
p.m_ptr; }
- bool operator==(T* p) const { return m_ptr == p; }
- bool operator!=(T* p) const { return m_ptr != p; }
+ void operator=(const smart_ptr<T>& s)
+ {
+ set_ref(s.m_ptr);
+ testInvariant();
+ }
+
+ void operator=(T* ptr)
+ {
+ set_ref(ptr);
+ testInvariant();
+ }
+
+ T* operator->() const
+ {
+ assert(m_ptr);
+ testInvariant();
+ return m_ptr;
+ }
+
+ const T& operator*() const
+ {
+ assert(m_ptr);
+ testInvariant();
+ return *m_ptr;
+ }
+
+ T& operator*()
+ {
+ assert(m_ptr);
+ testInvariant();
+ return *m_ptr;
+ }
+
+ T* get_ptr() const
+ {
+ testInvariant();
+ return m_ptr;
+ }
+
+ bool operator==(const smart_ptr<T>& p) const
+ {
+ testInvariant();
+ return m_ptr == p.m_ptr;
+ }
+
+ bool operator!=(const smart_ptr<T>& p) const
+ {
+ testInvariant();
+ return m_ptr != p.m_ptr;
+ }
+
+ bool operator==(T* p) const
+ {
+ testInvariant();
+ return m_ptr == p;
+ }
+
+ bool operator!=(T* p) const
+ {
+ testInvariant();
+ return m_ptr != p;
+ }
// Provide work-alikes for static_cast, dynamic_cast, implicit up-cast?
("gentle_cast" a la ajb?)
+ /// Check invariant of the smart pointer.
+ //
+ /// This function is called as first thing by every public
+ /// inspector function and as last thing by every mutator
+ /// function. If you build with NDEBUG defined all such
+ /// calls will be removed (in case you're worried about
+ /// overhead).
+ ///
+ /// Leaving the calls in will increase the *probability*
+ /// to detect memory corruption errors earier.
+ ///
+ /// To further improve this we might have the smart_ptr
+ /// testInvariant function call the pointed-to testInvariant
+ /// function. I dind't push it so far though (yet) :)
+ ///
+ void testInvariant() const
+ {
+ // If we have a pointer, check that it's refcount
+ // is greater then 0, as if it is not that means
+ // that someone deleted it
+ assert( m_ptr != NULL || m_ptr->get_ref_count() > 0 );
+ }
+
private:
+
void set_ref(T* ptr)
{
if (ptr != m_ptr)
@@ -86,6 +172,8 @@
m_ptr->add_ref();
}
}
+
+ testInvariant();
}
T* m_ptr;
- [Gnash-commit] gnash ChangeLog libbase/smart_ptr.h [release_0_7_2],
Sandro Santilli <=