Correctly restore the originally used C locale in wxLocale dtor.

Save the original locale used before we changed it instead of "restoring" the
same locate that this wxLocale object was using.

Add a unit test to verify that this does work as expected.

Closes #14873.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74426 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2013-07-06 22:48:20 +00:00
parent c80ae45452
commit 700256bbdb
2 changed files with 32 additions and 8 deletions

View File

@@ -206,7 +206,11 @@ wxLanguageInfoArray *wxLocale::ms_languagesDB = NULL;
void wxLocale::DoCommonInit()
{
m_pszOldLocale = NULL;
// Store the current locale in order to be able to restore it in the dtor.
m_pszOldLocale = wxSetlocale(LC_ALL, NULL);
if ( m_pszOldLocale )
m_pszOldLocale = wxStrdup(m_pszOldLocale);
m_pOldLocale = wxSetLocale(this);
@@ -285,13 +289,7 @@ bool wxLocale::DoInit(const wxString& name,
wxS("no locale to set in wxLocale::Init()") );
}
const char *oldLocale = wxSetlocale(LC_ALL, szLocale);
if ( oldLocale )
m_pszOldLocale = wxStrdup(oldLocale);
else
m_pszOldLocale = NULL;
if ( m_pszOldLocale == NULL )
if ( !wxSetlocale(LC_ALL, szLocale) )
{
wxLogError(_("locale '%s' cannot be set."), szLocale);
}