[pygobject] Fix boxed type equality



commit 4c51a5411092f8ab6f8f6e9692a9b49692f621a7
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Fri Jun 1 02:53:13 2012 -0400

    Fix boxed type equality
    
    Each boxed type has its own Python type, not PyGBoxed_Type. Use
    PyObject_IsInstance instead of comparing against PyGBoxed_Type directly.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=677249
    
    Signed-off-by: Martin Pitt <martinpitt gnome org>

 gi/_gobject/pygboxed.c   |    3 ++-
 tests/test_everything.py |    8 ++++++++
 2 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/gi/_gobject/pygboxed.c b/gi/_gobject/pygboxed.c
index a00386b..541e77b 100644
--- a/gi/_gobject/pygboxed.c
+++ b/gi/_gobject/pygboxed.c
@@ -50,7 +50,8 @@ pyg_boxed_dealloc(PyGBoxed *self)
 static PyObject*
 pyg_boxed_richcompare(PyObject *self, PyObject *other, int op)
 {
-    if (Py_TYPE(self) == Py_TYPE(other) && Py_TYPE(self) == &PyGBoxed_Type)
+    if (Py_TYPE(self) == Py_TYPE(other) &&
+        PyObject_IsInstance(self, (PyObject*)&PyGBoxed_Type))
         return _pyglib_generic_ptr_richcompare(((PyGBoxed*)self)->boxed,
                                                ((PyGBoxed*)other)->boxed,
                                                op);
diff --git a/tests/test_everything.py b/tests/test_everything.py
index aa27059..f6c13a8 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -556,6 +556,14 @@ class TestProperties(unittest.TestCase):
         self.assertTrue(isinstance(object_.props.boxed, Everything.TestBoxed))
         self.assertEqual(object_.props.boxed.some_int8, 42)
 
+    def test_boxed_equality(self):
+        boxed = Everything.TestBoxedC()
+        # TestBoxedC uses refcounting, so we know that
+        # the pointer is the same when copied
+        copy = boxed.copy()
+        self.assertEqual(boxed, copy)
+        self.assertNotEqual(id(boxed), id(copy))
+
     def test_gtype(self):
         object_ = Everything.TestObj()
         self.assertEqual(object_.props.gtype, GObject.TYPE_INVALID)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]