Some days ago I noticed that a few of the gobject-introspection generated functions for the Nim bindings are wrong.
Concerned are only a few functions with parameters of type NULL-terminated array of string.
Well of course I thought that I may do something wrong in the gintro package, so I spent whole evening yesterday and a few hours today on this issue. But now I get the impression that the GIR files just contain insufficient entries like
<function name="strv_length" c:identifier="g_strv_length" version="2.6">
<doc xml:space="preserve">Returns the length of the given %NULL-terminated
string array @str_array. @str_array must not be %NULL.</doc>
<return-value transfer-ownership="none">
<doc xml:space="preserve">length of @str_array.</doc>
<type name="guint" c:type="guint"/>
</return-value>
<parameters>
<parameter name="str_array" transfer-ownership="none">
<doc xml:space="preserve">a %NULL-terminated array of strings</doc>
<type name="utf8" c:type="gchar**"/>
</parameter>
</parameters>
</function>
From the doc comment we learn that parameter str_array is an NULL-terminated array of strings, which matches the c:type=“gchar**”. But type name=“utf8” is the only info available for introspection, so for the bindings I have that type is utf8, and that it is a pointer. But Of course that is not correct, as we know that is a NULL-terminated array of strings. I think there is really no way to get the correct information from gobject-introspection – maybe there are no correct annotations in source code?
Luckily these issues are rare, less than 100 I think. Most functions are correctly annotated as array type when a parameter is an NULL-terminated array of strings.
Maybe looking at the C source codes support my assumption:
/**
* g_strv_length:
* @str_array: a %NULL-terminated array of strings
*
* Returns the length of the given %NULL-terminated
* string array @str_array. @str_array must not be %NULL.
*
* Returns: length of @str_array.
*
* Since: 2.6
*/
guint
g_strv_length (gchar **str_array)
{
guint i = 0;
g_return_val_if_fail (str_array != NULL, 0);
while (str_array[i])
++i;
return i;
}
–
/**
* gtk_selection_data_set_uris:
* @selection_data: a #GtkSelectionData
* @uris: (array zero-terminated=1): a %NULL-terminated array of
* strings holding URIs
*
* Sets the contents of the selection from a list of URIs.
* The string is converted to the form determined by
* @selection_data->target.
*
* Returns: %TRUE if the selection was successfully set,
* otherwise %FALSE.
**/
gboolean
gtk_selection_data_set_uris (GtkSelectionData *selection_data,
gchar **uris)
{
For gtk_selection_data_set_uris(), which is an example for the majority of functions which gives me fully correct bindings, there is @uris: (array zero-terminated=1): which is missing for g_strv_length()