[pygobject] Fix leaks with GValues holding boxed and object types
- From: Simon Feltman <sfeltman src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Fix leaks with GValues holding boxed and object types
- Date: Mon, 12 Nov 2012 07:18:48 +0000 (UTC)
commit df589458358d7e7bf178dff4e6ad937a70f806e3
Author: Simon Feltman <sfeltman src gnome org>
Date: Sun Nov 11 22:26:19 2012 -0800
Fix leaks with GValues holding boxed and object types
Expose read access to PyGIBoxed.free_on_dealloc.
Add GObject.Value.__del__ override and call unset() to
correctly free reference counts.
https://bugzilla.gnome.org/show_bug.cgi?id=688137
gi/overrides/GObject.py | 9 +++++++++
gi/pygi-boxed.c | 12 ++++++++++++
tests/test_gi.py | 2 --
3 files changed, 21 insertions(+), 2 deletions(-)
---
diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py
index 2ed7166..c0198b3 100644
--- a/gi/overrides/GObject.py
+++ b/gi/overrides/GObject.py
@@ -204,6 +204,15 @@ __all__ += ['add_emission_hook', 'features', 'list_properties',
'signal_new', 'threads_init', 'type_register']
+class Value(GObjectModule.Value):
+ def __del__(self):
+ if self._free_on_dealloc:
+ self.unset()
+
+Value = override(Value)
+__all__.append('Value')
+
+
def type_from_name(name):
type_ = GObjectModule.type_from_name(name)
if type_ == TYPE_INVALID:
diff --git a/gi/pygi-boxed.c b/gi/pygi-boxed.c
index 2fd446c..ff3db9b 100644
--- a/gi/pygi-boxed.c
+++ b/gi/pygi-boxed.c
@@ -165,6 +165,17 @@ _pygi_boxed_new (PyTypeObject *type,
return (PyObject *) self;
}
+static PyObject *
+_pygi_boxed_get_free_on_dealloc(PyGIBoxed *self, void *closure)
+{
+ return PyBool_FromLong( ((PyGBoxed *)self)->free_on_dealloc );
+}
+
+static PyGetSetDef pygi_boxed_getsets[] = {
+ { "_free_on_dealloc", (getter)_pygi_boxed_get_free_on_dealloc, (setter)0 },
+ { NULL, 0, 0 }
+};
+
void
_pygi_boxed_register_types (PyObject *m)
{
@@ -174,6 +185,7 @@ _pygi_boxed_register_types (PyObject *m)
PyGIBoxed_Type.tp_init = (initproc) _boxed_init;
PyGIBoxed_Type.tp_dealloc = (destructor) _boxed_dealloc;
PyGIBoxed_Type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
+ PyGIBoxed_Type.tp_getset = pygi_boxed_getsets;
if (PyType_Ready (&PyGIBoxed_Type))
return;
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 8681738..275baab 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -1231,7 +1231,6 @@ class TestGValue(unittest.TestCase):
values = GIMarshallingTests.return_gvalue_flat_array()
self.assertEqual(values, [42, '42', True])
- @unittest.expectedFailure # https://bugzilla.gnome.org/show_bug.cgi?id=688137
def test_gvalue_gobject_ref_counts(self):
# Tests a GObject held by a GValue
obj = GObject.Object()
@@ -1269,7 +1268,6 @@ class TestGValue(unittest.TestCase):
gc.collect()
self.assertEqual(ref(), None)
- @unittest.expectedFailure # https://bugzilla.gnome.org/show_bug.cgi?id=688137
def test_gvalue_boxed_ref_counts(self):
# Tests a boxed type wrapping a python object pointer (TYPE_PYOBJECT)
# held by a GValue
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]