Commit 7bc41228 authored by Steve Frécinaux's avatar Steve Frécinaux
Browse files

Fix wrong refcount when calling introspected widget constructors

Introspected widget constructors, like, can return
objects with a floating reference, which was then reffed by pygobject,
resulting in two references, despite the object is not owned by anyone.

This patch uses ref_sink() when pygobject takes its own reference, to
avoid adding that extra reference. Hence we now claim ownership on
objects returned by constructors with transfer=none (which is the case
for nearly all the widget constructors, despite the floating ref).
parent afeaaa12
......@@ -967,7 +967,9 @@ pygobject_new_full(GObject *obj, gboolean sink, gpointer g_class)
self->weakreflist = NULL;
self->private_flags.flags = 0;
self->obj = obj;
/* if we are creating a wrapper around a newly created object, it can have
a floating ref (e.g. for methods like Bug 640868 */
pygobject_register_wrapper((PyObject *)self);
PyObject_GC_Track((PyObject *)self);
......@@ -67,7 +67,14 @@ class TestEverything(unittest.TestCase):
def test_floating(self):
e = Everything.TestFloating()
self.assertEquals(e.__grefcount__, 1)
e =
self.assertEquals(e.__grefcount__, 1)
e =
self.assertEquals(e.__grefcount__, 1)
def test_caller_allocates(self):
struct_a = Everything.TestStructA()
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