[pygi] correctly handle floating objects in gtk



commit 60fdf4b8f738dd0f5c190bc18ddf010032d3c5ca
Author: John (J5) Palmieri <johnp redhat com>
Date:   Sat May 22 14:06:37 2010 +0200

    correctly handle floating objects in gtk
    
    * this is a stopgap so we work with older pygobject libraries
    * there is a patch at https://bugzilla.gnome.org/show_bug.cgi?id=583909
      which adds the correct fix to pygobject
    * once pygobject accepts the above patch this patch does not need to
      be reverted because pygobject_register_sinkfunc becomes a noop
    * add tests (Tomeu)
    
    https://bugzilla.gnome.org/show_bug.cgi?id=619007

 gi/gimodule.c            |   12 ++++++++++++
 tests/test_everything.py |    3 +++
 2 files changed, 15 insertions(+), 0 deletions(-)
---
diff --git a/gi/gimodule.c b/gi/gimodule.c
index 665c796..7453139 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -222,6 +222,13 @@ _wrap_pyg_hook_up_vfunc_implementation (PyObject *self, PyObject *args)
     Py_RETURN_NONE;
 }
 
+static void
+_sink_gobject(GObject *obj)
+{
+    if (G_IS_INITIALLY_UNOWNED(obj) || g_object_is_floating(obj)) {
+            g_object_ref_sink(obj);
+    }
+}
 
 static PyMethodDef _pygi_functions[] = {
     { "enum_add", (PyCFunction)_wrap_pyg_enum_add, METH_VARARGS | METH_KEYWORDS },
@@ -261,6 +268,11 @@ init_gi(void)
     if (Pycairo_CAPI == NULL)
         return;
 
+    // register our floating object sink while we wait for the pygobject
+    // patch to be approved.  Once the patch is in this becomes a noop
+    // For more details - https://bugzilla.gnome.org/show_bug.cgi?id=583909
+    pygobject_register_sinkfunc(G_TYPE_OBJECT, _sink_gobject);
+
     _pygi_repository_register_types(m);
     _pygi_info_register_types(m);
     _pygi_struct_register_types(m);
diff --git a/tests/test_everything.py b/tests/test_everything.py
index 5953dd1..7ef7b8a 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -46,6 +46,9 @@ class TestEverything(unittest.TestCase):
         self.assertEquals(surface.get_width(), 10)
         self.assertEquals(surface.get_height(), 10)
 
+    def test_floating(self):
+        Everything.TestFloating()
+
 
 class TestNullableArgs(unittest.TestCase):
     def test_in_nullable_hash(self):



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