aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2010-09-24 15:47:41 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2010-09-24 16:03:58 -0300
commitdedc78b3fef25e04cf436ca462714ad8dc0329cd (patch)
treef679cfcc9ef848330c79410e7fda5493d24bc679
parent16579322f177c1fde0336c2b255a4a696ed73e5d (diff)
Fixed segmentation fault libpyside's signalUpdateSource function.
This function is called when an object is instantiated, and it will go through the class attributes looking for signals and what else is relevant. If the user has set a new attribute in the constructor before the call to its parent QObject-like __init__ method, a segmentation fault would ensue. This commit fixes this condition and also adds an unit test. Reviewed by Hugo Parente <hugo.lima@openbossa.org> Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
-rw-r--r--libpyside/qsignal.cpp2
-rw-r--r--tests/QtCore/CMakeLists.txt1
-rw-r--r--tests/QtCore/qobject_objectproperty_test.py29
3 files changed, 31 insertions, 1 deletions
diff --git a/libpyside/qsignal.cpp b/libpyside/qsignal.cpp
index aa218eccd..95fc25198 100644
--- a/libpyside/qsignal.cpp
+++ b/libpyside/qsignal.cpp
@@ -225,7 +225,7 @@ void signalUpdateSource(PyObject* source)
for(int i = 0, iMax = PyList_GET_SIZE(attrs.object()); i < iMax; ++i) {
PyObject *attrName = PyList_GET_ITEM(attrs.object(), i);
Shiboken::AutoDecRef attr(PyObject_GetAttr(reinterpret_cast<PyObject*>(source->ob_type), attrName));
- if (attr->ob_type == &Signal_Type) {
+ if (!attr.isNull() && attr->ob_type == &Signal_Type) {
Shiboken::AutoDecRef signalInstance((PyObject*)PyObject_New(SignalInstanceData, &SignalInstance_Type));
signal_instance_initialize(signalInstance, attrName, reinterpret_cast<SignalData*>(attr.object()), source, 0);
PyObject_SetAttr(source, attrName, signalInstance);
diff --git a/tests/QtCore/CMakeLists.txt b/tests/QtCore/CMakeLists.txt
index 76db54f25..210aa01de 100644
--- a/tests/QtCore/CMakeLists.txt
+++ b/tests/QtCore/CMakeLists.txt
@@ -34,6 +34,7 @@ PYSIDE_TEST(qobject_connect_notify_test.py)
PYSIDE_TEST(qobject_destructor.py)
PYSIDE_TEST(qobject_event_filter_test.py)
PYSIDE_TEST(qobject_inherits_test.py)
+PYSIDE_TEST(qobject_objectproperty_test.py)
PYSIDE_TEST(qobject_parent_test.py)
PYSIDE_TEST(qobject_property_test.py)
PYSIDE_TEST(qobject_protected_methods_test.py)
diff --git a/tests/QtCore/qobject_objectproperty_test.py b/tests/QtCore/qobject_objectproperty_test.py
new file mode 100644
index 000000000..2456b82cf
--- /dev/null
+++ b/tests/QtCore/qobject_objectproperty_test.py
@@ -0,0 +1,29 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+'''Test case for the bug #378
+http://bugs.openbossa.org/show_bug.cgi?id=378
+'''
+
+import unittest
+from PySide.QtCore import QObject
+
+class ExtQObject(QObject):
+ def __init__(self):
+ # "foobar" will become a object attribute that will not be
+ # listed on the among the type attributes. Thus for bug
+ # condition be correctly triggered the "foobar" attribute
+ # must not previously exist in the parent class.
+ self.foobar = None
+ # The parent __init__ method must be called after the
+ # definition of "self.foobar".
+ QObject.__init__(self)
+
+class TestBug378(unittest.TestCase):
+ '''Test case for the bug #378'''
+
+ def testBug378(self):
+ obj = ExtQObject()
+
+if __name__ == '__main__':
+ unittest.main()
+