gitypeinfo: Change gi_type_info_get_array_length_index() to return uint

Rather than mixing `-1` and valid indexes, split out the indication of
whether the type is an array with a length argument from the actual
index of the length argument.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3155
This commit is contained in:
Philip Withnall 2024-01-16 23:26:02 +00:00
parent 33f157bd6b
commit fe6f9a661b
3 changed files with 22 additions and 14 deletions

View File

@ -244,7 +244,7 @@ write_type_info (const char *ns,
}
else if (tag == GI_TYPE_TAG_ARRAY)
{
gssize length;
unsigned int length_index;
size_t size;
const char *name = NULL;
@ -271,9 +271,8 @@ write_type_info (const char *ns,
type = gi_type_info_get_param_type (info, 0);
length = gi_type_info_get_array_length_index (info);
if (length >= 0)
xml_printf (file, " length=\"%" G_GSSIZE_FORMAT "\"", length);
if (gi_type_info_get_array_length_index (info, &length_index))
xml_printf (file, " length=\"%u\"", length_index);
if (gi_type_info_get_array_fixed_size (info, &size))
xml_printf (file, " fixed-size=\"%zu\"", size);

View File

@ -232,23 +232,25 @@ gi_type_info_get_interface (GITypeInfo *info)
/**
* gi_type_info_get_array_length_index:
* @info: a #GITypeInfo
* @out_length_index: (out) (optional): return location for the length argument
*
* Obtain the position of the argument which gives the array length of the type.
*
* The type tag must be a `GI_TYPE_TAG_ARRAY` or `-1` will be returned.
* The type tag must be a `GI_TYPE_TAG_ARRAY` with a length argument, or `FALSE`
* will be returned.
*
* Returns: the array length argument index, or `-1` if the type is not an array
* or it has no length argument
* Returns: `TRUE` if the type is an array and has a length argument
* Since: 2.80
*/
gssize
gi_type_info_get_array_length_index (GITypeInfo *info)
gboolean
gi_type_info_get_array_length_index (GITypeInfo *info,
unsigned int *out_length_index)
{
GIRealInfo *rinfo = (GIRealInfo *)info;
SimpleTypeBlob *type;
g_return_val_if_fail (info != NULL, -1);
g_return_val_if_fail (GI_IS_TYPE_INFO (info), -1);
g_return_val_if_fail (info != NULL, FALSE);
g_return_val_if_fail (GI_IS_TYPE_INFO (info), FALSE);
type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
@ -259,11 +261,17 @@ gi_type_info_get_array_length_index (GITypeInfo *info)
if (blob->tag == GI_TYPE_TAG_ARRAY)
{
if (blob->has_length)
return blob->dimensions.length;
{
if (out_length_index != NULL)
*out_length_index = blob->dimensions.length;
return TRUE;
}
}
}
return -1;
if (out_length_index != NULL)
*out_length_index = 0;
return FALSE;
}
/**

View File

@ -96,7 +96,8 @@ GI_AVAILABLE_IN_ALL
GIBaseInfo * gi_type_info_get_interface (GITypeInfo *info);
GI_AVAILABLE_IN_ALL
gssize gi_type_info_get_array_length_index (GITypeInfo *info);
gboolean gi_type_info_get_array_length_index (GITypeInfo *info,
unsigned int *out_length_index);
GI_AVAILABLE_IN_ALL
gboolean gi_type_info_get_array_fixed_size (GITypeInfo *info,