Commit 4c51a541 authored by Jasper St. Pierre's avatar Jasper St. Pierre Committed by Martin Pitt
Browse files

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: default avatarMartin Pitt <martinpitt@gnome.org>
parent dc8eef26
......@@ -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);
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment