X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/42841dfcaddc6045ffc618acbb620b1fde1bc618..d0430ee2bab2a2c12485f64f003b2d4573a946e8:/src/common/config.cpp diff --git a/src/common/config.cpp b/src/common/config.cpp index 00f2daa6b7..3248e1e59a 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -39,9 +39,9 @@ #include "wx/textfile.h" #include "wx/utils.h" #include "wx/utils.h" +#include "wx/math.h" #include -#include #include #include // for INT_MAX @@ -73,6 +73,11 @@ wxConfigBase::wxConfigBase(const wxString& appName, m_bRecordDefaults = false; } +wxConfigBase::~wxConfigBase() +{ + // required here for Darwin +} + wxConfigBase *wxConfigBase::Set(wxConfigBase *pConfig) { wxConfigBase *pOld = ms_pConfig; @@ -229,21 +234,38 @@ wxConfigPathChanger::wxConfigPathChanger(const wxConfigBase *pContainer, wxString strPath = strEntry.BeforeLast(wxCONFIG_PATH_SEPARATOR); // except in the special case of "/keyname" when there is nothing before "/" - if ( strPath.IsEmpty() && - ((!strEntry.IsEmpty()) && strEntry[0] == wxCONFIG_PATH_SEPARATOR) ) + if ( strPath.empty() && + ((!strEntry.empty()) && strEntry[0] == wxCONFIG_PATH_SEPARATOR) ) { strPath = wxCONFIG_PATH_SEPARATOR; } - if ( !strPath.IsEmpty() && m_pContainer->GetPath() != strPath ) { - // do change the path - m_bChanged = true; + if ( !strPath.empty() ) + { + if ( m_pContainer->GetPath() != strPath ) + { + // do change the path + m_bChanged = true; + + /* JACS: work around a memory bug that causes an assert + when using wxRegConfig, related to reference-counting. + Can be reproduced by removing (const wxChar*) below and + adding the following code to the config sample OnInit under + Windows: + + pConfig->SetPath(wxT("MySettings")); + pConfig->SetPath(wxT("..")); + int value; + pConfig->Read(_T("MainWindowX"), & value); + */ + m_strOldPath = (const wxChar*) m_pContainer->GetPath(); + if ( *m_strOldPath.c_str() != wxCONFIG_PATH_SEPARATOR ) + m_strOldPath += wxCONFIG_PATH_SEPARATOR; + m_pContainer->SetPath(strPath); + } + + // in any case, use the just the name, not full path m_strName = strEntry.AfterLast(wxCONFIG_PATH_SEPARATOR); - m_strOldPath = m_pContainer->GetPath(); - if ( m_strOldPath.Len() == 0 || - m_strOldPath.Last() != wxCONFIG_PATH_SEPARATOR ) - m_strOldPath += wxCONFIG_PATH_SEPARATOR; - m_pContainer->SetPath(strPath); } else { // it's a name only, without path - nothing to do @@ -374,7 +396,8 @@ wxString wxExpandEnvVars(const wxString& str) case '\\': // backslash can be used to suppress special meaning of % and $ - if ( n != str.Len() && (str[n + 1] == wxT('%') || str[n + 1] == wxT('$')) ) { + if ( n != str.Len() - 1 && + (str[n + 1] == wxT('%') || str[n + 1] == wxT('$')) ) { strResult += str[++n]; break; @@ -410,7 +433,7 @@ void wxSplitPath(wxArrayString& aParts, const wxChar *sz) strCurrent.Empty(); } - else if ( !strCurrent.IsEmpty() ) { + else if ( !strCurrent.empty() ) { aParts.push_back(strCurrent); strCurrent.Empty(); }