]> git.saurik.com Git - wxWidgets.git/commitdiff
Remove wxConfig object caching (m_config), which solves dangling pointer problem...
authorKevin Hock <hockkn@yahoo.com>
Thu, 29 Dec 2005 01:49:55 +0000 (01:49 +0000)
committerKevin Hock <hockkn@yahoo.com>
Thu, 29 Dec 2005 01:49:55 +0000 (01:49 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36586 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/fontmap.h
src/common/fmapbase.cpp

index d3b0461e72ebb88c2533b39cb0fc0050a779f22f..881adb6ee550133996ddd51a2b1a69366935c7e7 100644 (file)
@@ -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
index 4a8a019edd7e2d151d8f93ed1e774d665a9570ca..707a0a8114e1ffe12aa42ff7de6c78345fd7a171 100644 (file)
@@ -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()