]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/object.cpp
source id type is unsigned; minor cleanup
[wxWidgets.git] / src / common / object.cpp
index 1c74d57dbd452d4817cdd2241d580eda7bbc2eb7..0289fc2ec6d58db54a23d7c5a9f47024fef4464a 100644 (file)
@@ -205,13 +205,31 @@ wxClassInfo *wxClassInfo::FindClass(const wxChar *className)
     }
 }
 
+// This function wasn't written to be reentrant but there is a possiblity of
+// reentrance if something it does causes a shared lib to load and register
+// classes. On Solaris this happens when the wxHashTable is newed, so the first
+// part of the function has been modified to handle it, and a wxASSERT checks
+// against reentrance in the remainder of the function.
+
 void wxClassInfo::Register()
 {
     if ( !sm_classTable )
     {
-        sm_classTable = new wxHashTable(wxKEY_STRING);
+        wxHashTable *classTable = new wxHashTable(wxKEY_STRING);
+
+        // check for reentrance
+        if ( sm_classTable )
+            delete classTable;
+        else
+            sm_classTable = classTable;
     }
 
+#ifdef __WXDEBUG__
+    // reentrance guard - see note above
+    static int entry = 0;
+    wxASSERT_MSG(++entry == 1, _T("wxClassInfo::Register() reentrance"));
+#endif
+
     // Using IMPLEMENT_DYNAMIC_CLASS() macro twice (which may happen if you
     // link any object module twice mistakenly, or link twice against wx shared
     // library) will break this function because it will enter an infinite loop
@@ -226,6 +244,10 @@ void wxClassInfo::Register()
     );
 
     sm_classTable->Put(m_className, (wxObject *)this);
+
+#ifdef __WXDEBUG__
+    --entry;
+#endif
 }
 
 void wxClassInfo::Unregister()
@@ -267,6 +289,17 @@ wxObject *wxCreateDynamicObject(const wxChar *name)
 }
 
 
+// ----------------------------------------------------------------------------
+// wxObjectRefData
+// ----------------------------------------------------------------------------
+
+void wxObjectRefData::DecRef()
+{
+    if ( --m_count == 0 )
+        delete this;
+}
+
+
 // ----------------------------------------------------------------------------
 // wxObject
 // ----------------------------------------------------------------------------
@@ -288,7 +321,7 @@ void wxObject::Ref(const wxObject& clone)
     if ( clone.m_refData )
     {
         m_refData = clone.m_refData;
-        ++(m_refData->m_count);
+        m_refData->IncRef();
     }
 }
 
@@ -298,8 +331,7 @@ void wxObject::UnRef()
     {
         wxASSERT_MSG( m_refData->m_count > 0, _T("invalid ref data count") );
 
-        if ( --m_refData->m_count == 0 )
-            delete m_refData;
+        m_refData->DecRef();
         m_refData = NULL;
     }
 }