GNOME Bugzilla – Bug 352209
Cannot convert sequence with None items into GValueArray
Last modified: 2007-04-30 02:42:32 UTC
pyg_value_array_from_pyobject() has: for (i = 0; i < len; ++i) { PyObject *item = PySequence_GetItem(obj, i); GType type; GValue item_value = { 0, }; int status; if (! item) { PyErr_Clear(); g_value_array_free(value_array); return -1; } if (pspec && pspec->element_spec) type = G_PARAM_SPEC_VALUE_TYPE(pspec->element_spec); else { type = pyg_type_from_object((PyObject *) item->ob_type); if (! type) { PyErr_Clear(); g_value_array_free(value_array); Py_DECREF(item); return -1; } } g_value_init(&item_value, type); If pspec is NULL, when a sequence item is Py_None pyg_type_from_object will return G_TYPE_NONE, which cannot be stored in GValue. Fix: if (type == G_TYPE_NONE) type = G_TYPE_POINTER;
Ed: Can you create a patch with a testcase?
Created attachment 76866 [details] gvamodule.c Hrk. Well, I can't find any pygobject-derived modules that actually use GValueArray (which is I guess why I noted this as a minor bug), so here's a hand-rolled one.
Created attachment 76867 [details] setup.py distutils setup.py ($ python setup.py build)
Testing: $ PYTHONPATH=build/lib.linux-i686-2.4/ python -c 'import gva; print gva.round_trip_gva([1,2,3,"foo",True])' [1, 2, 3, 'foo', True] $ PYTHONPATH=build/lib.linux-i686-2.4/ python -c 'import gva; print gva.round_trip_gva([1,2,3,"foo",True,None])' Traceback (most recent call last):
+ Trace 87806
Created attachment 76870 [details] [review] gvaluearray-store-none-as-null.patch And patch. Not quite what I said above; seems pyg_type_from_object can't handle PyNone_Type. Doesn't matter really.
$ PYTHONPATH=build/lib.linux-i686-2.4/ python -c 'import gva; print gva.round_trip_gva([1,2,3,"foo",True,None])' [1, 2, 3, 'foo', True, None]
Thanks for the patch and the test. I integrated it into our testsuite. It got committed to svn trunk as revision 656.