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:
parent
61e6a2ab5e
commit
5bbca8b037
@ -116,9 +116,6 @@ public:
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#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)
|
||||
void SetConfigPath(const wxString& prefix);
|
||||
|
||||
@ -129,8 +126,8 @@ public:
|
||||
|
||||
protected:
|
||||
#if wxUSE_CONFIG && wxUSE_FILECONFIG
|
||||
// get the config object we're using -- if it wasn't set explicitly, this
|
||||
// function will use wxConfig::Get() to get the global one
|
||||
// get the config object we're using -- either the global config object
|
||||
// or a wxMemoryConfig object created by this class otherwise
|
||||
wxConfigBase *GetConfig();
|
||||
|
||||
// gets the root path for our settings -- if it wasn't set explicitly, use
|
||||
@ -149,8 +146,7 @@ protected:
|
||||
void RestorePath(const wxString& pathOld);
|
||||
|
||||
// config object and path (in it) to use
|
||||
wxConfigBase *m_config;
|
||||
bool m_configIsDummy;
|
||||
wxConfigBase *m_configDummy;
|
||||
|
||||
wxString m_configRootPath;
|
||||
#endif // wxUSE_CONFIG
|
||||
|
@ -247,16 +247,15 @@ wxFontMapper *wxFontMapperBase::sm_instance = NULL;
|
||||
wxFontMapperBase::wxFontMapperBase()
|
||||
{
|
||||
#if wxUSE_CONFIG && wxUSE_FILECONFIG
|
||||
m_config = NULL;
|
||||
m_configIsDummy = false;
|
||||
m_configDummy = NULL;
|
||||
#endif // wxUSE_CONFIG
|
||||
}
|
||||
|
||||
wxFontMapperBase::~wxFontMapperBase()
|
||||
{
|
||||
#if wxUSE_CONFIG && wxUSE_FILECONFIG
|
||||
if ( m_configIsDummy )
|
||||
delete m_config;
|
||||
if ( m_configDummy )
|
||||
delete m_configDummy;
|
||||
#endif // wxUSE_CONFIG
|
||||
}
|
||||
|
||||
@ -322,42 +321,23 @@ void wxFontMapperBase::SetConfigPath(const wxString& prefix)
|
||||
|
||||
wxConfigBase *wxFontMapperBase::GetConfig()
|
||||
{
|
||||
if ( !m_config )
|
||||
{
|
||||
// try the default
|
||||
m_config = wxConfig::Get(false /*don't create on demand*/ );
|
||||
wxConfigBase *config = wxConfig::Get(false);
|
||||
|
||||
if ( !m_config )
|
||||
{
|
||||
// we still want to have a config object because otherwise we would
|
||||
// keep asking the user the same questions in the interactive mode,
|
||||
// so create a dummy config which won't write to any files/registry
|
||||
// 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 )
|
||||
// If there is no global configuration, use an internal memory configuration
|
||||
if ( !config )
|
||||
{
|
||||
// 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,
|
||||
if ( !m_configDummy )
|
||||
m_configDummy = new wxMemoryConfig;
|
||||
config = m_configDummy;
|
||||
|
||||
// FIXME: ideally, we should add keys from dummy config to a real one later,
|
||||
// but it is a low-priority task because typical wxWin application
|
||||
// either doesn't use wxConfig at all or creates wxConfig object in
|
||||
// wxApp::OnInit(), before any real interaction with the user takes
|
||||
// place...
|
||||
}
|
||||
|
||||
return m_config;
|
||||
return config;
|
||||
}
|
||||
|
||||
const wxString& wxFontMapperBase::GetConfigPath()
|
||||
|
Loading…
Reference in New Issue
Block a user