summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2010-11-24 14:24:09 -0200
committerHugo Parente Lima <hugo.pl@gmail.com>2010-11-24 14:35:33 -0200
commit47aa7189789b43be6c7fee10affc83966fbbab07 (patch)
tree4434668ff4ef32f9542666665b2b64619246be9c
parentf31d9107555376e60757b9c8054030e2cf7bddad (diff)
downloadpyside-47aa7189789b43be6c7fee10affc83966fbbab07.tar.gz
pyside-47aa7189789b43be6c7fee10affc83966fbbab07.tar.xz
pyside-47aa7189789b43be6c7fee10affc83966fbbab07.zip
Fix crash at exit when there's a chain of referenced objects.
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Marcelo Lira <marcelo.lira@openbossa.org>
-rw-r--r--libpyside/pyside.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/libpyside/pyside.cpp b/libpyside/pyside.cpp
index bbec1fa..81e5d65 100644
--- a/libpyside/pyside.cpp
+++ b/libpyside/pyside.cpp
@@ -32,6 +32,7 @@
#include <basewrapper.h>
#include <conversions.h>
#include <typeresolver.h>
+#include <bindingmanager.h>
#include <algorithm>
#include <cctype>
#include <QStack>
@@ -102,6 +103,18 @@ void runCleanupFunctions()
}
}
+static void destructionVisitor(SbkObject* pyObj, void* data)
+{
+ void** realData = reinterpret_cast<void**>(data);
+ SbkObject* pyQApp = reinterpret_cast<SbkObject*>(realData[0]);
+ PyTypeObject* pyQObjectType = reinterpret_cast<PyTypeObject*>(realData[1]);
+
+ if (pyObj != pyQApp && PyObject_TypeCheck(pyObj, pyQObjectType)) {
+ if (Shiboken::Object::hasOwnership(pyObj))
+ Shiboken::callCppDestructor<QObject>(Shiboken::Object::cppPointer(pyObj, Shiboken::SbkType<QObject*>()));
+ }
+};
+
void destroyQCoreApplication()
{
SignalManager::instance().clear();
@@ -114,19 +127,8 @@ void destroyQCoreApplication()
PyTypeObject* pyQObjectType = Shiboken::TypeResolver::get("QObject*")->pythonType();
assert(pyQObjectType);
- QList<SbkObject*> objects;
-
- //filter only QObjects which we have ownership, this will avoid list changes during the destruction of some parent object
- foreach (SbkObject* pyObj, bm.getAllPyObjects()) {
- if (pyObj != pyQApp && PyObject_TypeCheck(pyObj, pyQObjectType)) {
- if (Shiboken::Object::hasOwnership(pyObj))
- objects << pyObj;
- }
- }
-
- //Now we can destroy all object in the list
- foreach (SbkObject* pyObj, objects)
- Shiboken::callCppDestructor<QObject>(Shiboken::Object::cppPointer(pyObj, Shiboken::SbkType<QObject*>()));
+ void* data[2] = {pyQApp, pyQObjectType};
+ bm.visitAllPyObjects(&destructionVisitor, &data);
// in the end destroy app
delete app;