X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b2edef6f2f587d957eabbc17364382293707340f..30fd71e65bbbada8d17a0efbafbbbb3bafb42f9f:/src/common/object.cpp diff --git a/src/common/object.cpp b/src/common/object.cpp index a9b7d22d61..2c5530169c 100644 --- a/src/common/object.cpp +++ b/src/common/object.cpp @@ -5,9 +5,9 @@ // Modified by: Ron Lee // Created: 04/01/98 // RCS-ID: $Id$ -// Copyright: (c) 1998 Julian Smart and Markus Holzem +// Copyright: (c) 1998 Julian Smart // (c) 2001 Ron Lee -// Licence: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -22,7 +22,8 @@ #endif #ifndef WX_PRECOMP -#include "wx/hash.h" + #include "wx/hash.h" + #include "wx/object.h" #endif #include @@ -43,10 +44,38 @@ #endif #endif // __WXDEBUG__ || wxUSE_DEBUG_CONTEXT +// we must disable optimizations for VC.NET because otherwise its too eager +// linker discards wxClassInfo objects in release build thus breaking many, +// many things +#if defined __VISUALC__ && __VISUALC__ >= 1300 + #pragma optimize("", off) +#endif +#if wxUSE_EXTENDED_RTTI +const wxClassInfo* wxObject::sm_classParentswxObject[] = { NULL } ; + wxObject* wxVariantToObjectConverterwxObject ( const wxxVariant &data ) +{ return data.Get() ; } + wxxVariant wxObjectToVariantConverterwxObject ( wxObject *data ) + { return wxxVariant( dynamic_cast (data) ) ; } + wxClassInfo wxObject::sm_classwxObject(sm_classParentswxObject , wxT("") , wxT("wxObject"), + (int) sizeof(wxObject), \ + (wxObjectConstructorFn) 0 , + (wxPropertyInfo*) NULL,(wxHandlerInfo*) NULL,0 , 0 , + 0 , wxVariantToObjectConverterwxObject , wxObjectToVariantConverterwxObject); + template<> void wxStringReadValue(const wxString & , wxObject * & ){assert(0) ;} + template<> void wxStringWriteValue(wxString & , wxObject* const & ){assert(0) ;} + template<> const wxTypeInfo* wxGetTypeInfo( wxObject ** ) + { static wxClassTypeInfo s_typeInfo(&wxObject::sm_classwxObject) ; return &s_typeInfo ; } +#else wxClassInfo wxObject::sm_classwxObject( wxT("wxObject"), 0, 0, (int) sizeof(wxObject), (wxObjectConstructorFn) 0 ); +#endif + +// restore optimizations +#if defined __VISUALC__ && __VISUALC__ >= 1300 + #pragma optimize("", on) +#endif wxClassInfo* wxClassInfo::sm_first = NULL; wxHashTable* wxClassInfo::sm_classTable = NULL; @@ -77,11 +106,15 @@ void wxObject::Dump(wxSTD ostream& str) #endif +#if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING && defined( new ) + #undef new +#endif + #ifdef _WX_WANT_NEW_SIZET_WXCHAR_INT -void *wxObject::operator new ( size_t size, wxChar *fileName, int lineNum ) +void *wxObject::operator new ( size_t size, const wxChar *fileName, int lineNum ) { - return wxDebugAlloc(size, fileName, lineNum, TRUE); + return wxDebugAlloc(size, (wxChar*) fileName, lineNum, TRUE); } #endif @@ -100,16 +133,16 @@ void wxObject::operator delete ( void *buf, const char *_fname, size_t _line ) #endif #ifdef _WX_WANT_DELETE_VOID_WXCHAR_INT -void wxObject::operator delete ( void *buf, wxChar *WXUNUSED(fileName), int WXUNUSED(lineNum) ) +void wxObject::operator delete ( void *buf, const wxChar *WXUNUSED(fileName), int WXUNUSED(lineNum) ) { wxDebugFree(buf); } #endif #ifdef _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT -void *wxObject::operator new[] ( size_t size, wxChar* WXUNUSED(fileName), int WXUNUSED(lineNum) ) +void *wxObject::operator new[] ( size_t size, const wxChar* fileName, int lineNum ) { - return wxDebugAlloc(size, fileName, lineNum, TRUE, TRUE); + return wxDebugAlloc(size, (wxChar*) fileName, lineNum, TRUE, TRUE); } #endif @@ -121,7 +154,7 @@ void wxObject::operator delete[] ( void *buf ) #endif #ifdef _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT -void wxObject::operator delete[] (void * buf, wxChar* WXUNUSED(fileName), int WXUNUSED(lineNum) ) +void wxObject::operator delete[] (void * buf, const wxChar* WXUNUSED(fileName), int WXUNUSED(lineNum) ) { wxDebugFree(buf, TRUE); } @@ -132,6 +165,34 @@ void wxObject::operator delete[] (void * buf, wxChar* WXUNUSED(fileName), int W // wxClassInfo // ---------------------------------------------------------------------------- +wxClassInfo::~wxClassInfo() +{ + // remove this object from the linked list of all class infos: if we don't + // do it, loading/unloading a DLL containing static wxClassInfo objects is + // not going to work + if ( this == sm_first ) + { + sm_first = m_next; + } + else + { + wxClassInfo *info = sm_first; + while (info) + { + if ( info->m_next == this ) + { + info->m_next = m_next; + break; + } + + info = info->m_next; + } + } +#if wxUSE_EXTENDED_RTTI + Unregister( m_className ) ; +#endif +} + wxClassInfo *wxClassInfo::FindClass(const wxChar *className) { if ( sm_classTable ) @@ -159,13 +220,17 @@ inline wxClassInfo *wxClassInfo::GetBaseByName(const wxChar *name) wxClassInfo *classInfo = (wxClassInfo *)sm_classTable->Get(name); - // this must be fixed, other things risk work wrongly later if you get this - wxASSERT_MSG( classInfo, - wxString::Format - ( - _T("base class '%s' is unknown to wxWindows RTTI"), - name - ) ); +#ifdef __WXDEBUG__ + // this must be fixed, other things will work wrongly later if you get this + if ( !classInfo ) + { + wxFAIL_MSG( wxString::Format + ( + _T("base class '%s' is unknown to wxWindows RTTI"), + name + ) ); + } +#endif // __WXDEBUG__ return classInfo; } @@ -184,7 +249,7 @@ void wxClassInfo::InitializeClasses() size_t nClass = 0; #endif - wxClassInfo::sm_classTable = new wxHashTable(wxKEY_STRING); + sm_classTable = new wxHashTable(wxKEY_STRING); // Index all class infos by their class name @@ -199,6 +264,7 @@ void wxClassInfo::InitializeClasses() } } +#if wxUSE_EXTENDED_RTTI == 0 // Set base pointers for each wxClassInfo for(info = sm_first; info; info = info->m_next) @@ -206,6 +272,7 @@ void wxClassInfo::InitializeClasses() info->m_baseInfo1 = GetBaseByName(info->GetBaseClassName1()); info->m_baseInfo2 = GetBaseByName(info->GetBaseClassName2()); } +#endif } void wxClassInfo::CleanUpClasses() @@ -214,7 +281,6 @@ void wxClassInfo::CleanUpClasses() wxClassInfo::sm_classTable = NULL; } - wxObject *wxCreateDynamicObject(const wxChar *name) { #if defined(__WXDEBUG__) || wxUSE_DEBUG_CONTEXT @@ -242,9 +308,18 @@ wxObject *wxCreateDynamicObject(const wxChar *name) // ---------------------------------------------------------------------------- -// wxClassInfo +// wxObject // ---------------------------------------------------------------------------- +// Initialize ref data from another object (needed for copy constructor and +// assignment operator) +void wxObject::InitFrom(const wxObject& other) +{ + m_refData = other.m_refData; + if ( m_refData ) + m_refData->m_count++; +} + void wxObject::Ref(const wxObject& clone) { #if defined(__WXDEBUG__) || wxUSE_DEBUG_CONTEXT @@ -320,17 +395,17 @@ wxObject::CloneRefData(const wxObjectRefData * WXUNUSED(data)) const // misc // ---------------------------------------------------------------------------- -#if defined(__DARWIN__) && defined(DYLIB_INIT) +#if defined(__DARWIN__) && defined(WXMAKINGDLL) extern "C" { void __initialize_Cplusplus(void); void wxWindowsDylibInit(void); }; - // Dynamic shared library (dylib) initialization routine - // required to initialize static C++ objects bacause of lazy dynamic linking - // http://developer.apple.com/techpubs/macosx/Essentials/ - // SystemOverview/Frameworks/Dynamic_Shared_Libraries.html +// Dynamic shared library (dylib) initialization routine +// required to initialize static C++ objects bacause of lazy dynamic linking +// http://developer.apple.com/techpubs/macosx/Essentials/ +// SystemOverview/Frameworks/Dynamic_Shared_Libraries.html void wxWindowsDylibInit() { @@ -338,6 +413,8 @@ void wxWindowsDylibInit() // library initialization routine to cause the static C++ objects in // the library to be initialized (reference number 2441683). + // This only seems to be necessary if the library initialization routine + // needs to use the static C++ objects __initialize_Cplusplus(); }