diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | gobject/pygtype.c | 5 | ||||
-rw-r--r-- | tests/test_signal.py | 27 |
3 files changed, 27 insertions, 12 deletions
@@ -1,3 +1,10 @@ +2006-11-18 Johan Dahlin <jdahlin@async.com.br> + + * gobject/pygtype.c (gclosure_from_pyfunc): Use PyObject_Cmp instead + of comparing function closure addresses, which makes it possible + to use any callable and not just functions. + Fixes #375589 (Dima) + 2006-10-13 John Finlay <finlay@moeraki.com> * docs/Makefile.am (HTML_FILES): Remove diff --git a/gobject/pygtype.c b/gobject/pygtype.c index 2146978..5bc29b5 100644 --- a/gobject/pygtype.c +++ b/gobject/pygtype.c @@ -1331,8 +1331,9 @@ gclosure_from_pyfunc(PyGObject *object, PyObject *func) for (l = object->closures; l; l = l->next) { PyGClosure *pyclosure = l->data; - if (PyFunction_GetClosure(pyclosure->callback) == - PyFunction_GetClosure(func)) { + int res; + PyObject_Cmp(pyclosure->callback, func, &res); + if (!res) { return (GClosure*)pyclosure; } } diff --git a/tests/test_signal.py b/tests/test_signal.py index 6312711..d22281e 100644 --- a/tests/test_signal.py +++ b/tests/test_signal.py @@ -242,6 +242,23 @@ class TestClosures(unittest.TestCase): e.emit('signal') self.assertEqual(self.count, 1) + def testHandlerBlockMethod(self): + # Filed as #375589 + class A: + def __init__(self): + self.a = 0 + + def callback(self, o): + self.a = 1 + o.handler_block_by_func(self.callback) + + inst = A() + e = E() + e.connect("signal", inst.callback) + e.emit('signal') + self.assertEqual(inst.a, 1) + gc.collect() + def testGString(self): class C(gobject.GObject): __gsignals__ = { 'my_signal': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_GSTRING, @@ -257,16 +274,6 @@ class TestClosures(unittest.TestCase): data = c.emit("my_signal", "\01\00\02") self.assertEqual(data, "\02\00\01") - def _test_bug375589(self): - class A: - def callback(self, o): - o.handler_block_by_func(self.callback) - - e = E() - e.connect("signal", A().callback) - e.emit('signal') - gc.collect() - class SigPropClass(gobject.GObject): __gsignals__ = { 'my_signal': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_INT,)) } |