summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--gobject/pygtype.c2
-rw-r--r--tests/test_gtype.py10
-rw-r--r--tests/testhelpermodule.c19
4 files changed, 39 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index e7020f1..4117bb2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2007-04-29 Johan Dahlin <johan@gnome.org>
+
+ * gobject/pygtype.c: (pyg_value_array_from_pyobject):
+ * tests/test_gtype.py:
+ * tests/testhelpermodule.c: (_wrap_test_value_array):
+
+ Treat None in a GValueArray as pointer/NULL, patch by
+ Ed Catmur, fixes #352209.
+
2007-04-29 Loïc Minier <lool+gnome@via.ecp.fr>
reviewed by: Johan Dahlin <johan@gnome.org>
diff --git a/gobject/pygtype.c b/gobject/pygtype.c
index 0015b42..5606e2a 100644
--- a/gobject/pygtype.c
+++ b/gobject/pygtype.c
@@ -628,6 +628,8 @@ pyg_value_array_from_pyobject(GValue *value,
if (pspec && pspec->element_spec)
type = G_PARAM_SPEC_VALUE_TYPE(pspec->element_spec);
+ else if (item == Py_None)
+ type = G_TYPE_POINTER; /* store None as NULL */
else {
type = pyg_type_from_object((PyObject *) item->ob_type);
if (! type) {
diff --git a/tests/test_gtype.py b/tests/test_gtype.py
index 52efda4..cbf3e1c 100644
--- a/tests/test_gtype.py
+++ b/tests/test_gtype.py
@@ -1,7 +1,7 @@
import unittest
from gobject import GType
-from common import gobject
+from common import gobject, testhelper
class GTypeTest(unittest.TestCase):
def checkType(self, expected, *objects):
@@ -54,6 +54,14 @@ class GTypeTest(unittest.TestCase):
def testObject(self):
self.checkType(gobject.TYPE_OBJECT, 'PyObject')
+ def testValueArray(self):
+ array = [1, 2, 3, "foo", True]
+ self.assertEqual(array, testhelper.test_value_array(array))
+
+ def testValueArrayNone(self):
+ array = [1, 2, 3, "foo", True, None]
+ self.assertEqual(array, testhelper.test_value_array(array))
+
# XXX: Flags, Enums
class MyObject(gobject.GObject):
diff --git a/tests/testhelpermodule.c b/tests/testhelpermodule.c
index c811876..95542a3 100644
--- a/tests/testhelpermodule.c
+++ b/tests/testhelpermodule.c
@@ -450,12 +450,31 @@ _wrap_connectcallbacks(PyObject * self, PyObject *args)
return Py_None;
}
+static PyObject *
+_wrap_test_value_array(PyObject *self, PyObject *args)
+{
+ GValue tvalue = {0,}, *value = &tvalue;
+ PyObject *obj;
+
+ if (!PyArg_ParseTuple(args, "O", &obj))
+ return NULL;
+
+ g_value_init(value, G_TYPE_VALUE_ARRAY);
+ if (pyg_value_from_pyobject(value, obj)) {
+ PyErr_SetString(PyExc_TypeError, "Could not convert to GValueArray");
+ return NULL;
+ }
+
+ return pyg_value_as_pyobject(value, FALSE);
+}
+
static PyMethodDef testhelper_functions[] = {
{ "get_test_thread", (PyCFunction)_wrap_get_test_thread, METH_NOARGS },
{ "get_unknown", (PyCFunction)_wrap_get_unknown, METH_NOARGS },
{ "create_test_type", (PyCFunction)_wrap_create_test_type, METH_NOARGS },
{ "test_g_object_new", (PyCFunction)_wrap_test_g_object_new, METH_NOARGS },
{ "connectcallbacks", (PyCFunction)_wrap_connectcallbacks, METH_VARARGS },
+ { "test_value_array", (PyCFunction)_wrap_test_value_array, METH_VARARGS },
{ NULL, NULL }
};