don't use invalid/uninitialized iterator in wxList::compatibility_iterator in wxUSE_STL==1 case, this doesn't work with the debug version of glibc STL

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38893 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-04-24 17:59:10 +00:00
parent bc5a523959
commit 7d13fbc6dc
2 changed files with 21 additions and 10 deletions

View File

@@ -136,7 +136,7 @@ private:
#endif // defined( __VISUALC__ ) #endif // defined( __VISUALC__ )
/* /*
Note: the outer helper class _WX_LIST_HELPER_##liT below is a workaround Note 1: the outer helper class _WX_LIST_HELPER_##liT below is a workaround
for mingw 3.2.3 compiler bug that prevents a static function of liT class for mingw 3.2.3 compiler bug that prevents a static function of liT class
from being exported into dll. A minimal code snippet reproducing the bug: from being exported into dll. A minimal code snippet reproducing the bug:
@@ -155,6 +155,13 @@ private:
The program does not link under mingw_gcc 3.2.3 producing undefined The program does not link under mingw_gcc 3.2.3 producing undefined
reference to Foo::Bar() function reference to Foo::Bar() function
Note 2: the EmptyList is needed to allow having a NULL pointer-like
invalid iterator. We used to use just an uninitialized iterator object
instead but this fails with some debug/checked versions of STL, notably the
glibc version activated with _GLIBCXX_DEBUG, so we need to have a separate
invalid iterator.
*/ */
// the real wxList-class declaration // the real wxList-class declaration
@@ -170,6 +177,9 @@ private:
decl liT : public std::list<elT> \ decl liT : public std::list<elT> \
{ \ { \
private: \ private: \
typedef std::list<elT> BaseListType; \
static BaseListType EmptyList; \
\
bool m_destroy; \ bool m_destroy; \
public: \ public: \
decl compatibility_iterator \ decl compatibility_iterator \
@@ -183,7 +193,7 @@ private:
liT * m_list; \ liT * m_list; \
public: \ public: \
compatibility_iterator() \ compatibility_iterator() \
: m_iter(), m_list( NULL ) {} \ : m_iter(EmptyList.end()), m_list( NULL ) {} \
compatibility_iterator( liT* li, iterator i ) \ compatibility_iterator( liT* li, iterator i ) \
: m_iter( i ), m_list( li ) {} \ : m_iter( i ), m_list( li ) {} \
compatibility_iterator( const liT* li, iterator i ) \ compatibility_iterator( const liT* li, iterator i ) \

View File

@@ -16,9 +16,10 @@
void _WX_LIST_HELPER_##name::DeleteFunction( _WX_LIST_ITEM_TYPE_##name X )\ void _WX_LIST_HELPER_##name::DeleteFunction( _WX_LIST_ITEM_TYPE_##name X )\
{ \ { \
delete X; \ delete X; \
} } \
name::BaseListType name::EmptyList;
#else // if !wxUSE_STL #else // !wxUSE_STL
#define _DEFINE_LIST(T, name) \ #define _DEFINE_LIST(T, name) \
void wx##name##Node::DeleteData() \ void wx##name##Node::DeleteData() \
@@ -34,5 +35,5 @@
// don't pollute preprocessor's name space // don't pollute preprocessor's name space
//#undef _DEFINE_LIST //#undef _DEFINE_LIST
#endif #endif // wxUSE_STL/!wxUSE_STL