From f5256c59dd7d9d2af9aaf5854b2bd39b87c7aafe Mon Sep 17 00:00:00 2001 From: Michael Wetherell Date: Sat, 15 Jul 2006 20:54:07 +0000 Subject: [PATCH] Handle reentrance in the first part of wxClassInfo::Register() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40108 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/object.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/common/object.cpp b/src/common/object.cpp index 1c74d57dbd..0fb4fae976 100644 --- a/src/common/object.cpp +++ b/src/common/object.cpp @@ -205,13 +205,29 @@ 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; } + // reentrance guard - see note above + static int entry = 0; + wxASSERT_MSG(++entry == 1, _T("wxClassInfo::Register() reentrance")); + // 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 +242,8 @@ void wxClassInfo::Register() ); sm_classTable->Put(m_className, (wxObject *)this); + + --entry; } void wxClassInfo::Unregister()