After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 352209 - Cannot convert sequence with None items into GValueArray
Cannot convert sequence with None items into GValueArray
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: gobject
2.11.x
Other Linux
: Normal minor
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2006-08-20 22:39 UTC by Ed Catmur
Modified: 2007-04-30 02:42 UTC
See Also:
GNOME target: ---
GNOME version: 2.15/2.16


Attachments
gvamodule.c (717 bytes, text/x-csrc)
2006-11-19 21:27 UTC, Ed Catmur
  Details
setup.py (436 bytes, text/x-python)
2006-11-19 21:28 UTC, Ed Catmur
  Details
gvaluearray-store-none-as-null.patch (454 bytes, patch)
2006-11-19 22:05 UTC, Ed Catmur
none Details | Review

Description Ed Catmur 2006-08-20 22:39:14 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;
Comment 1 Johan (not receiving bugmail) Dahlin 2006-11-18 15:28:55 UTC
Ed: Can you create a patch with a testcase?
Comment 2 Ed Catmur 2006-11-19 21:27:13 UTC
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.
Comment 3 Ed Catmur 2006-11-19 21:28:37 UTC
Created attachment 76867 [details]
setup.py

distutils setup.py ($ python setup.py build)
Comment 4 Ed Catmur 2006-11-19 21:29:46 UTC
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):
  • File "<string>", line 1 in ?
TypeError: Could not convert to GValueArray

Comment 5 Ed Catmur 2006-11-19 22:05:11 UTC
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.
Comment 6 Ed Catmur 2006-11-19 22:05:58 UTC
$ 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]
Comment 7 Johan (not receiving bugmail) Dahlin 2007-04-30 02:42:32 UTC
Thanks for the patch and the test. I integrated it into our testsuite.

It got committed to svn trunk as revision 656.