summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-07-19 15:58:20 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2011-07-20 17:54:11 -0300
commit2e98f87d20b5b310d40995acefb93b1a105025de (patch)
tree44fb08b3be49cfa07bf2020526b92dc9016fe5a5
parent33bf95628f11abfed959b6dc01d048d2f075087a (diff)
downloadpyside-2e98f87d20b5b310d40995acefb93b1a105025de.tar.gz
pyside-2e98f87d20b5b310d40995acefb93b1a105025de.tar.xz
pyside-2e98f87d20b5b310d40995acefb93b1a105025de.zip
Fixes bug #910 - installEventFilter() increments reference count on target object.
http://bugs.pyside.org/show_bug.cgi?id=910 Also added/fixed unit tests. Reviewed by Hugo Parente <hugo.lima@openbossa.org> Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
-rw-r--r--PySide/QtCore/typesystem_core.xml10
-rw-r--r--tests/QtCore/qobject_event_filter_test.py36
-rw-r--r--tests/QtGui/event_filter_test.py6
3 files changed, 39 insertions, 13 deletions
diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml
index 3737fbb..8421e9a 100644
--- a/PySide/QtCore/typesystem_core.xml
+++ b/PySide/QtCore/typesystem_core.xml
@@ -1284,16 +1284,6 @@
<define-ownership owner="c++"/>
</modify-argument>
</modify-function>
- <modify-function signature="installEventFilter(QObject*)">
- <inject-code>
- Shiboken::Object::keepReference((SbkObject*)%PYARG_1, "eventFilter", %PYSELF, true);
- </inject-code>
- </modify-function>
- <modify-function signature="removeEventFilter(QObject*)">
- <inject-code>
- Shiboken::Object::removeReference((SbkObject*)%PYARG_1, "eventFilter", %PYSELF);
- </inject-code>
- </modify-function>
<!-- Invalidate-after-use stuff -->
<modify-function signature="childEvent(QChildEvent*)">
<modify-argument index="1" invalidate-after-use="yes"/>
diff --git a/tests/QtCore/qobject_event_filter_test.py b/tests/QtCore/qobject_event_filter_test.py
index 8018fcd..8fded79 100644
--- a/tests/QtCore/qobject_event_filter_test.py
+++ b/tests/QtCore/qobject_event_filter_test.py
@@ -2,6 +2,8 @@
'''Test cases for QObject.eventFilter'''
import unittest
+import weakref
+import sys
from PySide.QtCore import QObject, QTimerEvent
@@ -76,5 +78,39 @@ class TestQObjectEventFilterPython(UsesQCoreApplication):
self.assertEqual(filtered.times_called, 5)
self.assertEqual(self.obj_filter.events_handled, 5)
+ def testInstallEventFilterRefCountAfterDelete(self):
+ '''Bug 910 - installEventFilter() increments reference count on target object
+ http://bugs.pyside.org/show_bug.cgi?id=910'''
+ obj = QObject()
+ filt = QObject()
+
+ self.assertEqual(sys.getrefcount(obj), 2)
+ self.assertEqual(sys.getrefcount(filt), 2)
+ obj.installEventFilter(filt)
+ self.assertEqual(sys.getrefcount(obj), 2)
+ self.assertEqual(sys.getrefcount(filt), 2)
+
+ wref = weakref.ref(obj)
+ del obj
+ self.assertEqual(wref(), None)
+
+ def testInstallEventFilterRefCountAfterRemove(self):
+ # Bug 910
+ obj = QObject()
+ filt = QObject()
+
+ self.assertEqual(sys.getrefcount(obj), 2)
+ self.assertEqual(sys.getrefcount(filt), 2)
+ obj.installEventFilter(filt)
+ self.assertEqual(sys.getrefcount(obj), 2)
+ self.assertEqual(sys.getrefcount(filt), 2)
+ obj.removeEventFilter(filt)
+ self.assertEqual(sys.getrefcount(obj), 2)
+ self.assertEqual(sys.getrefcount(filt), 2)
+
+ wref = weakref.ref(obj)
+ del obj
+ self.assertEqual(wref(), None)
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/QtGui/event_filter_test.py b/tests/QtGui/event_filter_test.py
index 88dbd96..ec82515 100644
--- a/tests/QtGui/event_filter_test.py
+++ b/tests/QtGui/event_filter_test.py
@@ -2,7 +2,7 @@ import unittest
import sys
from helper import UsesQApplication
-from PySide.QtCore import QObject, QEvent, QTimer
+from PySide.QtCore import QObject, QEvent
from PySide.QtGui import QWidget
class MyFilter(QObject):
@@ -17,10 +17,10 @@ class EventFilter(UsesQApplication):
o = QObject()
filt = MyFilter()
o.installEventFilter(filt)
- self.assertEqual(sys.getrefcount(o), 3)
+ self.assertEqual(sys.getrefcount(o), 2)
o.installEventFilter(filt)
- self.assertEqual(sys.getrefcount(o), 3)
+ self.assertEqual(sys.getrefcount(o), 2)
o.removeEventFilter(filt)
self.assertEqual(sys.getrefcount(o), 2)