X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5276b0a53cef4815230e39b54d2ecda14f72cbd1..cc4d5638c66a409e421420ed7110917755a66788:/src/common/dynload.cpp?ds=sidebyside diff --git a/src/common/dynload.cpp b/src/common/dynload.cpp index a76a190733..0b184d0e5b 100644 --- a/src/common/dynload.cpp +++ b/src/common/dynload.cpp @@ -5,7 +5,6 @@ // (derived in part from dynlib.cpp (c) 1998 Guilhem Lavaux) // Modified by: // Created: 03/12/01 -// RCS-ID: $Id$ // Copyright: (c) 2001 Ron Lee // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -76,9 +75,33 @@ wxPluginLibrary::wxPluginLibrary(const wxString &libname, int flags) : m_linkcount(1) , m_objcount(0) { - m_before = wxClassInfo::GetFirst(); + const wxClassInfo* const oldFirst = wxClassInfo::GetFirst(); Load( libname, flags ); - m_after = wxClassInfo::GetFirst(); + + // It is simple to know what is the first object in the linked list of + // wxClassInfo that we registered (it's also the last one chronologically), + // it's just the new head of the wxClassInfo list: + m_ourFirst = wxClassInfo::GetFirst(); + + // But to find the first wxClassInfo created by this library we need to + // iterate until we get to the previous head as we don't have the links in + // the backwards direction: + if ( m_ourFirst != oldFirst ) + { + for ( const wxClassInfo* info = m_ourFirst; ; info = info->GetNext() ) + { + if ( info->GetNext() == oldFirst ) + { + m_ourLast = info; + break; + } + } + } + else // We didn't register any classes at all. + { + m_ourFirst = + m_ourLast = NULL; + } if( m_handle != 0 ) { @@ -130,7 +153,10 @@ bool wxPluginLibrary::UnrefLib() void wxPluginLibrary::UpdateClasses() { - for (const wxClassInfo *info = m_after; info != m_before; info = info->GetNext()) + if ( !m_ourFirst ) + return; + + for ( const wxClassInfo *info = m_ourFirst; ; info = info->GetNext() ) { if( info->GetClassName() ) { @@ -138,6 +164,9 @@ void wxPluginLibrary::UpdateClasses() // we can quickly find the entry they correspond to. (*ms_classes)[info->GetClassName()] = this; } + + if ( info == m_ourLast ) + break; } } @@ -147,9 +176,15 @@ void wxPluginLibrary::RestoreClasses() if (!ms_classes) return; - for(const wxClassInfo *info = m_after; info != m_before; info = info->GetNext()) + if ( !m_ourFirst ) + return; + + for ( const wxClassInfo *info = m_ourFirst; ; info = info->GetNext() ) { ms_classes->erase(ms_classes->find(info->GetClassName())); + + if ( info == m_ourLast ) + break; } } @@ -166,16 +201,22 @@ void wxPluginLibrary::RegisterModules() wxASSERT_MSG( m_linkcount == 1, wxT("RegisterModules should only be called for the first load") ); - for ( const wxClassInfo *info = m_after; info != m_before; info = info->GetNext()) + if ( m_ourFirst ) { - if( info->IsKindOf(CLASSINFO(wxModule)) ) + for ( const wxClassInfo *info = m_ourFirst; ; info = info->GetNext() ) { - wxModule *m = wxDynamicCast(info->CreateObject(), wxModule); + if( info->IsKindOf(wxCLASSINFO(wxModule)) ) + { + wxModule *m = wxDynamicCast(info->CreateObject(), wxModule); - wxASSERT_MSG( m, wxT("wxDynamicCast of wxModule failed") ); + wxASSERT_MSG( m, wxT("wxDynamicCast of wxModule failed") ); + + m_wxmodules.push_back(m); + wxModule::RegisterModule(m); + } - m_wxmodules.push_back(m); - wxModule::RegisterModule(m); + if ( info == m_ourLast ) + break; } } @@ -242,7 +283,7 @@ wxPluginManager::LoadLibrary(const wxString &libname, int flags) wxString realname(libname); if( !(flags & wxDL_VERBATIM) ) - realname += wxDynamicLibrary::GetDllExt(); + realname += wxDynamicLibrary::GetDllExt(wxDL_MODULE); wxPluginLibrary *entry; @@ -301,7 +342,7 @@ bool wxPluginManager::UnloadLibrary(const wxString& libname) if ( !entry ) { - realname += wxDynamicLibrary::GetDllExt(); + realname += wxDynamicLibrary::GetDllExt(wxDL_MODULE); entry = FindByName(realname); }