[pygobject] pygi-value: special case for NULL GValueArray
- From: Simon Feltman <sfeltman src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] pygi-value: special case for NULL GValueArray
- Date: Sun, 21 Feb 2016 05:16:54 +0000 (UTC)
commit f27b1976ea325fcd55359888401dd08ac8fb074a
Author: Mikhail Fludkov <misha pexip com>
Date: Tue Sep 1 17:54:17 2015 +0200
pygi-value: special case for NULL GValueArray
Don't segfault when dealing with GValue of GValueArray type containing
NULL. Return empty list in this case.
https://bugzilla.gnome.org/show_bug.cgi?id=754359
gi/pygi-value.c | 5 +++--
tests/test_gobject.py | 6 ++++++
2 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/gi/pygi-value.c b/gi/pygi-value.c
index 2cf567d..3bdd854 100644
--- a/gi/pygi-value.c
+++ b/gi/pygi-value.c
@@ -775,9 +775,10 @@ pygi_value_to_py_structured_type (const GValue *value, GType fundamental, gboole
return pyg_value_as_pyobject(n_value, copy_boxed);
} else if (holds_value_array) {
GValueArray *array = (GValueArray *) g_value_get_boxed(value);
- PyObject *ret = PyList_New(array->n_values);
+ Py_ssize_t n_values = array ? array->n_values : 0;
+ PyObject *ret = PyList_New(n_values);
int i;
- for (i = 0; i < array->n_values; ++i)
+ for (i = 0; i < n_values; ++i)
PyList_SET_ITEM(ret, i, pyg_value_as_pyobject
(array->values + i, copy_boxed));
return ret;
diff --git a/tests/test_gobject.py b/tests/test_gobject.py
index 6c15e20..87b0e4c 100644
--- a/tests/test_gobject.py
+++ b/tests/test_gobject.py
@@ -669,5 +669,11 @@ class TestGValue(unittest.TestCase):
value = GObject.Value(GObject.TYPE_OBJECT, obj)
self.assertEqual(value.get_value(), obj)
+ def test_value_array(self):
+ value = GObject.Value(GObject.ValueArray)
+ self.assertEqual(value.g_type, GObject.type_from_name('GValueArray'))
+ value.set_value([32, 'foo_bar', 0.3])
+ self.assertEqual(value.get_value(), [32, 'foo_bar', 0.3])
+
if __name__ == '__main__':
unittest.main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]