gitypeinfo: Change gi_type_info_get_array_fixed_size() to return size_t

Return information about whether the type is a fixed-size array
separately from the array size, which allows us to use the full `size_t`
for the array size.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3155
This commit is contained in:
Philip Withnall 2024-01-16 23:11:16 +00:00
parent 1b32e72073
commit 6a7806da4d
3 changed files with 22 additions and 13 deletions

View File

@ -245,7 +245,7 @@ write_type_info (const char *ns,
else if (tag == GI_TYPE_TAG_ARRAY)
{
gssize length;
gssize size;
size_t size;
const char *name = NULL;
xml_start_element (file, "array");
@ -275,9 +275,8 @@ write_type_info (const char *ns,
if (length >= 0)
xml_printf (file, " length=\"%" G_GSSIZE_FORMAT "\"", length);
size = gi_type_info_get_array_fixed_size (info);
if (size >= 0)
xml_printf (file, " fixed-size=\"%" G_GSSIZE_FORMAT "\"", size);
if (gi_type_info_get_array_fixed_size (info, &size))
xml_printf (file, " fixed-size=\"%zu\"", size);
if (gi_type_info_is_zero_terminated (info))
xml_printf (file, " zero-terminated=\"1\"");

View File

@ -269,22 +269,25 @@ gi_type_info_get_array_length_index (GITypeInfo *info)
/**
* gi_type_info_get_array_fixed_size:
* @info: a #GITypeInfo
* @out_size: (out) (optional): return location for the array size
*
* Obtain the fixed array size of the type, in number of elements (not bytes).
*
* 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 fixed size, or `FALSE` will
* be returned.
*
* Returns: the size or `-1` if the type is not an array or it has no fixed size
* Returns: `TRUE` if the type is an array and has a fixed size
* Since: 2.80
*/
gssize
gi_type_info_get_array_fixed_size (GITypeInfo *info)
gboolean
gi_type_info_get_array_fixed_size (GITypeInfo *info,
size_t *out_size)
{
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];
@ -295,11 +298,17 @@ gi_type_info_get_array_fixed_size (GITypeInfo *info)
if (blob->tag == GI_TYPE_TAG_ARRAY)
{
if (blob->has_size)
return blob->dimensions.size;
{
if (out_size != NULL)
*out_size = blob->dimensions.size;
return TRUE;
}
}
}
return -1;
if (out_size != NULL)
*out_size = 0;
return FALSE;
}
/**

View File

@ -99,7 +99,8 @@ GI_AVAILABLE_IN_ALL
gssize gi_type_info_get_array_length_index (GITypeInfo *info);
GI_AVAILABLE_IN_ALL
gssize gi_type_info_get_array_fixed_size (GITypeInfo *info);
gboolean gi_type_info_get_array_fixed_size (GITypeInfo *info,
size_t *out_size);
GI_AVAILABLE_IN_ALL
gboolean gi_type_info_is_zero_terminated (GITypeInfo *info);