aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Smith <nathanjsmith@gmail.com>2012-07-03 17:55:04 -0500
committerMarcelo Lira <marcelo.lira@openbossa.org>2012-07-04 20:25:37 +0200
commita3cecbab9735d40f97c0a031dd17ac594cf39e82 (patch)
tree5bec47690f2d692dc0f48670169be0c46b36602d
parente1a91dd721c17727bea41b591336d1cacca6dea4 (diff)
PYSIDE-83 Fix segfault calling shiboken.dump1.1.2
shiboken.dump would segfault when called on an object whose C++ object had been deleted or whose parent C++ object had been deleted. This now checks to see if the data pointers beneath the PyObject are NULL before printing data. Change-Id: I89763a3ca3a5d25fad4142ff924692cd232c9c40 Reviewed-by: Marcelo Lira <marcelo.lira@openbossa.org>
-rw-r--r--libshiboken/basewrapper.cpp23
-rw-r--r--tests/shibokenmodule/module_test.py6
2 files changed, 20 insertions, 9 deletions
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp
index 096f2c5..91c353e 100644
--- a/libshiboken/basewrapper.cpp
+++ b/libshiboken/basewrapper.cpp
@@ -1321,16 +1321,21 @@ std::string info(SbkObject* self)
std::ostringstream s;
std::list<SbkObjectType*> bases;
- if (ObjectType::isUserType(Py_TYPE(self)))
- bases = getCppBaseClasses(Py_TYPE(self));
- else
- bases.push_back(reinterpret_cast<SbkObjectType*>(Py_TYPE(self)));
+ if (self->d && self->d->cptr) {
+ if (ObjectType::isUserType(Py_TYPE(self)))
+ bases = getCppBaseClasses(Py_TYPE(self));
+ else
+ bases.push_back(reinterpret_cast<SbkObjectType*>(Py_TYPE(self)));
- s << "C++ address....... ";
- std::list<SbkObjectType*>::const_iterator it = bases.begin();
- for (int i = 0; it != bases.end(); ++it, ++i)
- s << ((PyTypeObject*)*it)->tp_name << "/" << self->d->cptr[i] << ' ';
- s << "\n";
+ s << "C++ address....... ";
+ std::list<SbkObjectType*>::const_iterator it = bases.begin();
+ for (int i = 0; it != bases.end(); ++it, ++i)
+ s << ((PyTypeObject*)*it)->tp_name << "/" << self->d->cptr[i] << ' ';
+ s << "\n";
+ }
+ else {
+ s << "C++ address....... <<Deleted>>\n";
+ }
s << "hasOwnership...... " << bool(self->d->hasOwnership) << "\n"
"containsCppWrapper " << self->d->containsCppWrapper << "\n"
diff --git a/tests/shibokenmodule/module_test.py b/tests/shibokenmodule/module_test.py
index 61a5f56..54c47de 100644
--- a/tests/shibokenmodule/module_test.py
+++ b/tests/shibokenmodule/module_test.py
@@ -56,6 +56,12 @@ class TestShiboken(unittest.TestCase):
shiboken.dump(m)
self.assertEqual(len(shiboken.getCppPointer(m)), 2)
+ # Don't crash even after deleting an object
+ shiboken.invalidate(obj)
+ shiboken.dump(obj) # deleted
+ shiboken.dump(p) # child deleted
+ shiboken.dump(obj2) # parent deleted
+
def testDelete(self):
obj = ObjectType()
child = ObjectType(obj)