[pygobject] Fix reference counting problems with GLib.Variant.new_tuple()



commit c1d387540a0b2db66e860c574b070051a5431914
Author: Simon Feltman <sfeltman src gnome org>
Date:   Thu Aug 21 14:37:14 2014 -0700

    Fix reference counting problems with GLib.Variant.new_tuple()
    
    Always sink the results of g_variant_new_tuple() in the statically
    bound wrapper. This matches the generic GI marshalling behavior
    of passing GVariants to Python with transfer-none.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=735166

 gi/gimodule.c                |    1 +
 tests/test_overrides_glib.py |    7 +++++++
 2 files changed, 8 insertions(+), 0 deletions(-)
---
diff --git a/gi/gimodule.c b/gi/gimodule.c
index 00c9422..a18c477 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -500,6 +500,7 @@ _wrap_pyg_variant_new_tuple (PyObject *self, PyObject *args)
     }
 
     variant = g_variant_new_tuple (values, PyTuple_Size (py_values));
+    g_variant_ref_sink (variant);
 
     py_variant = _pygi_struct_new ( (PyTypeObject *) py_type, variant, FALSE);
 
diff --git a/tests/test_overrides_glib.py b/tests/test_overrides_glib.py
index 4d7e63a..af68895 100644
--- a/tests/test_overrides_glib.py
+++ b/tests/test_overrides_glib.py
@@ -1,6 +1,7 @@
 # -*- Mode: Python; py-indent-offset: 4 -*-
 # vim: tabstop=4 shiftwidth=4 expandtab
 
+import gc
 import unittest
 
 import gi
@@ -61,6 +62,12 @@ class TestGVariant(unittest.TestCase):
         self.assertEqual(variant.get_type_string(), '((si)(ub))')
         self.assertEqual(variant.unpack(), (('hello', -1), (_long(42), True)))
 
+    def test_new_tuple_sink(self):
+        # https://bugzilla.gnome.org/show_bug.cgi?id=735166
+        variant = GLib.Variant.new_tuple(GLib.Variant.new_tuple())
+        del variant
+        gc.collect()
+
     def test_create_dictionary(self):
         variant = GLib.Variant('a{si}', {})
         self.assertTrue(isinstance(variant, GLib.Variant))


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