Remove wxConfig object caching (m_config), which solves dangling pointer problem if the global config object changes (and just makes things simpler)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36586 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -116,9 +116,6 @@ public:
|
|||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
#if wxUSE_CONFIG && wxUSE_FILECONFIG
|
#if wxUSE_CONFIG && wxUSE_FILECONFIG
|
||||||
// set the config object to use (may be NULL to use default)
|
|
||||||
void SetConfig(wxConfigBase *config) { m_config = config; }
|
|
||||||
|
|
||||||
// set the root config path to use (should be an absolute path)
|
// set the root config path to use (should be an absolute path)
|
||||||
void SetConfigPath(const wxString& prefix);
|
void SetConfigPath(const wxString& prefix);
|
||||||
|
|
||||||
@@ -129,8 +126,8 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
#if wxUSE_CONFIG && wxUSE_FILECONFIG
|
#if wxUSE_CONFIG && wxUSE_FILECONFIG
|
||||||
// get the config object we're using -- if it wasn't set explicitly, this
|
// get the config object we're using -- either the global config object
|
||||||
// function will use wxConfig::Get() to get the global one
|
// or a wxMemoryConfig object created by this class otherwise
|
||||||
wxConfigBase *GetConfig();
|
wxConfigBase *GetConfig();
|
||||||
|
|
||||||
// gets the root path for our settings -- if it wasn't set explicitly, use
|
// gets the root path for our settings -- if it wasn't set explicitly, use
|
||||||
@@ -149,8 +146,7 @@ protected:
|
|||||||
void RestorePath(const wxString& pathOld);
|
void RestorePath(const wxString& pathOld);
|
||||||
|
|
||||||
// config object and path (in it) to use
|
// config object and path (in it) to use
|
||||||
wxConfigBase *m_config;
|
wxConfigBase *m_configDummy;
|
||||||
bool m_configIsDummy;
|
|
||||||
|
|
||||||
wxString m_configRootPath;
|
wxString m_configRootPath;
|
||||||
#endif // wxUSE_CONFIG
|
#endif // wxUSE_CONFIG
|
||||||
|
@@ -247,16 +247,15 @@ wxFontMapper *wxFontMapperBase::sm_instance = NULL;
|
|||||||
wxFontMapperBase::wxFontMapperBase()
|
wxFontMapperBase::wxFontMapperBase()
|
||||||
{
|
{
|
||||||
#if wxUSE_CONFIG && wxUSE_FILECONFIG
|
#if wxUSE_CONFIG && wxUSE_FILECONFIG
|
||||||
m_config = NULL;
|
m_configDummy = NULL;
|
||||||
m_configIsDummy = false;
|
|
||||||
#endif // wxUSE_CONFIG
|
#endif // wxUSE_CONFIG
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontMapperBase::~wxFontMapperBase()
|
wxFontMapperBase::~wxFontMapperBase()
|
||||||
{
|
{
|
||||||
#if wxUSE_CONFIG && wxUSE_FILECONFIG
|
#if wxUSE_CONFIG && wxUSE_FILECONFIG
|
||||||
if ( m_configIsDummy )
|
if ( m_configDummy )
|
||||||
delete m_config;
|
delete m_configDummy;
|
||||||
#endif // wxUSE_CONFIG
|
#endif // wxUSE_CONFIG
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,42 +321,23 @@ void wxFontMapperBase::SetConfigPath(const wxString& prefix)
|
|||||||
|
|
||||||
wxConfigBase *wxFontMapperBase::GetConfig()
|
wxConfigBase *wxFontMapperBase::GetConfig()
|
||||||
{
|
{
|
||||||
if ( !m_config )
|
wxConfigBase *config = wxConfig::Get(false);
|
||||||
{
|
|
||||||
// try the default
|
|
||||||
m_config = wxConfig::Get(false /*don't create on demand*/ );
|
|
||||||
|
|
||||||
if ( !m_config )
|
// If there is no global configuration, use an internal memory configuration
|
||||||
|
if ( !config )
|
||||||
{
|
{
|
||||||
// we still want to have a config object because otherwise we would
|
if ( !m_configDummy )
|
||||||
// keep asking the user the same questions in the interactive mode,
|
m_configDummy = new wxMemoryConfig;
|
||||||
// so create a dummy config which won't write to any files/registry
|
config = m_configDummy;
|
||||||
// but will allow us to remember the results of the questions at
|
|
||||||
// least during this run
|
|
||||||
m_config = new wxMemoryConfig;
|
|
||||||
m_configIsDummy = true;
|
|
||||||
// VS: we can't call wxConfig::Set(m_config) here because that would
|
|
||||||
// disable automatic wxConfig instance creation if this code was
|
|
||||||
// called before wxApp::OnInit (this happens in wxGTK -- it sets
|
|
||||||
// default wxFont encoding in wxApp::Initialize())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( m_configIsDummy && wxConfig::Get(false) != NULL )
|
// FIXME: ideally, we should add keys from dummy config to a real one later,
|
||||||
{
|
|
||||||
// VS: in case we created dummy m_config (see above), we want to switch back
|
|
||||||
// to the real one as soon as one becomes available.
|
|
||||||
delete m_config;
|
|
||||||
m_config = wxConfig::Get(false);
|
|
||||||
m_configIsDummy = false;
|
|
||||||
// FIXME: ideally, we should add keys from dummy config to the real one now,
|
|
||||||
// but it is a low-priority task because typical wxWin application
|
// but it is a low-priority task because typical wxWin application
|
||||||
// either doesn't use wxConfig at all or creates wxConfig object in
|
// either doesn't use wxConfig at all or creates wxConfig object in
|
||||||
// wxApp::OnInit(), before any real interaction with the user takes
|
// wxApp::OnInit(), before any real interaction with the user takes
|
||||||
// place...
|
// place...
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
const wxString& wxFontMapperBase::GetConfigPath()
|
const wxString& wxFontMapperBase::GetConfigPath()
|
||||||
|
Reference in New Issue
Block a user