fix crash in ~wxString with global wxString objects: temporarily move conversion buffers from a hash to wxString

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45335 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2007-04-08 17:52:00 +00:00
parent 7708a26720
commit 132276cf0d
2 changed files with 63 additions and 10 deletions

View File

@@ -571,8 +571,6 @@ public:
wxString(const wxString& str, size_t nLength)
: m_impl(str.Mid(0, nLength).m_impl) {}
~wxString();
public:
// standard types
typedef wxUniChar value_type;
@@ -2001,6 +1999,35 @@ private:
private:
wxStringImpl m_impl;
// buffers for compatibility conversion from (char*)c_str() and
// (wchar_t*)c_str():
// FIXME-UTF8: bechmark various approaches to keeping compatibility buffers
template<typename T>
struct ConvertedBuffer
{
ConvertedBuffer() : m_buf(NULL) {}
~ConvertedBuffer()
{ free(m_buf); }
operator const T*() const { return m_buf; }
ConvertedBuffer& operator=(T *str)
{
free(m_buf);
m_buf = str;
return *this;
}
T *m_buf;
};
#if wxUSE_UNICODE
ConvertedBuffer<char> m_convertedToChar;
#endif
#if !wxUSE_UNICODE_WCHAR
ConvertedBuffer<wchar_t> m_convertedToWChar;
#endif
friend class WXDLLIMPEXP_BASE wxCStrData;
};
#ifdef wxNEEDS_WXSTRING_PRINTF_MIXIN