GNOME Bugzilla – Bug 645139
Cannot call a C function returning a zero-terminated GStrv
Last modified: 2011-05-26 18:46:56 UTC
A C function returns "const GStrv" with the following annotation: * Returns: (transfer none) (array zero-terminated=1) (element-type char*): */ const GStrv sw_item_get_value_all (SwItem *item, const gchar *key) The generated .gir file contains: <return-value transfer-ownership="none"> <array c:type="GStrv"> <type name="utf8"/> </array> </return-value> The generated .vapi file contains: public unowned string[] get_value_all (string key); When I call the C function from vala code, the generated C code does not compile: _tmp12_ = sw_item_get_value_all (item, "url", &_tmp11_); swf-persona.c:446: error: too many arguments to function ‘sw_item_get_value_all’ The additional argument "_tmp11_" is used as the size of the returned array. Expected outcome: - GStrv should be automatically detected as a zero-terminated array, even without annotation. - If not automatically detected, the annotation zero-terminated=1 should be added in the vapi/gir file. - The generated C code should not have extra arguments. - The generated C code should compile.
Thanks for your report. I found these types of gstrv in a single gir: <type name="utf8" c:type="gchar**"/> <type name="GObject.Strv"/> <array c:type="GStrv"><type name="utf8"/></array> <array><type name="utf8"/></array> I'm tempted to reassign this to gobject introspection, just to understand which annotation is the correct one.
We special case GStrv in the scanner to be <array c:type="GStrv"><type name="utf8"/></array>. Can you try dropping the (array) and (element-type) annotations?
(In reply to comment #2) > We special case GStrv in the scanner to be <array c:type="GStrv"><type > name="utf8"/></array>. Can you try dropping the (array) and (element-type) > annotations? When I drop the (array) and (element-type) annotations, it is still generate the same XML <array c:type="GStrv"><type name="utf8"/></array>. But valac still generate C code which does not compile.
commit d99a06073f028e98401323ac0ac57003a82159dc Author: Luca Bruno <lucabru@src.gnome.org> Date: Thu May 26 20:41:28 2011 +0200 girparser: Special case array of ctype GStrv as a null terminated array Fixes bug 645139. This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.