From 69ac96fd0d0e7b9d0fb1b349fe043502380ca929 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 11 Apr 2005 19:14:34 +0000 Subject: [PATCH] Better handling of the refcount of the wx.App object, so it now destroyed when expected and also resets the current instance pointer returned by wx.GetApp(). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33515 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/src/_app.i | 6 +++--- wxPython/src/_app_ex.py | 7 +++++-- wxPython/src/helpers.cpp | 8 +++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/wxPython/src/_app.i b/wxPython/src/_app.i index 5628f0242b..5aa20a5d55 100644 --- a/wxPython/src/_app.i +++ b/wxPython/src/_app.i @@ -48,8 +48,8 @@ class wxPyApp : public wxEvtHandler { public: %pythonAppend wxPyApp - "self._setCallbackInfo(self, PyApp) - self._setOORInfo(self)"; + "self._setCallbackInfo(self, PyApp, False) + self._setOORInfo(self, False)"; %typemap(out) wxPyApp*; // turn off this typemap DocStr(wxPyApp, @@ -67,7 +67,7 @@ public: %typemap(out) wxPyApp* { $result = wxPyMake_wxObject($1, $owner); } - void _setCallbackInfo(PyObject* self, PyObject* _class); + void _setCallbackInfo(PyObject* self, PyObject* _class, bool incref); DocDeclStr( diff --git a/wxPython/src/_app_ex.py b/wxPython/src/_app_ex.py index bae7df624e..98b35efc21 100644 --- a/wxPython/src/_app_ex.py +++ b/wxPython/src/_app_ex.py @@ -176,9 +176,12 @@ your Mac.""" def __del__(self): try: self.RestoreStdio() # Just in case the MainLoop was overridden - except: - pass + finally: + wx.PyApp.__del__(self) + def Destroy(self): + wx.PyApp.Destroy(self) + self.thisown = 0 def SetTopWindow(self, frame): """Set the \"main\" top level window""" diff --git a/wxPython/src/helpers.cpp b/wxPython/src/helpers.cpp index 1a23c8f8d6..f37f539eca 100644 --- a/wxPython/src/helpers.cpp +++ b/wxPython/src/helpers.cpp @@ -126,6 +126,8 @@ wxPyApp::wxPyApp() { wxPyApp::~wxPyApp() { + wxPythonApp = NULL; + wxApp::SetInstance(NULL); } @@ -408,11 +410,11 @@ void wxPyApp::_BootstrapApp() if (sysargv != NULL && executable != NULL) { argc = PyList_Size(sysargv) + 1; argv = new char*[argc+1]; - argv[0] = PyString_AsString(executable); + argv[0] = strdup(PyString_AsString(executable)); int x; for(x=1; x