mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-24 13:06:14 +01:00
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:
parent
1b32e72073
commit
6a7806da4d
@ -245,7 +245,7 @@ write_type_info (const char *ns,
|
|||||||
else if (tag == GI_TYPE_TAG_ARRAY)
|
else if (tag == GI_TYPE_TAG_ARRAY)
|
||||||
{
|
{
|
||||||
gssize length;
|
gssize length;
|
||||||
gssize size;
|
size_t size;
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
|
|
||||||
xml_start_element (file, "array");
|
xml_start_element (file, "array");
|
||||||
@ -275,9 +275,8 @@ write_type_info (const char *ns,
|
|||||||
if (length >= 0)
|
if (length >= 0)
|
||||||
xml_printf (file, " length=\"%" G_GSSIZE_FORMAT "\"", length);
|
xml_printf (file, " length=\"%" G_GSSIZE_FORMAT "\"", length);
|
||||||
|
|
||||||
size = gi_type_info_get_array_fixed_size (info);
|
if (gi_type_info_get_array_fixed_size (info, &size))
|
||||||
if (size >= 0)
|
xml_printf (file, " fixed-size=\"%zu\"", size);
|
||||||
xml_printf (file, " fixed-size=\"%" G_GSSIZE_FORMAT "\"", size);
|
|
||||||
|
|
||||||
if (gi_type_info_is_zero_terminated (info))
|
if (gi_type_info_is_zero_terminated (info))
|
||||||
xml_printf (file, " zero-terminated=\"1\"");
|
xml_printf (file, " zero-terminated=\"1\"");
|
||||||
|
@ -269,22 +269,25 @@ gi_type_info_get_array_length_index (GITypeInfo *info)
|
|||||||
/**
|
/**
|
||||||
* gi_type_info_get_array_fixed_size:
|
* gi_type_info_get_array_fixed_size:
|
||||||
* @info: a #GITypeInfo
|
* @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).
|
* 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
|
* Since: 2.80
|
||||||
*/
|
*/
|
||||||
gssize
|
gboolean
|
||||||
gi_type_info_get_array_fixed_size (GITypeInfo *info)
|
gi_type_info_get_array_fixed_size (GITypeInfo *info,
|
||||||
|
size_t *out_size)
|
||||||
{
|
{
|
||||||
GIRealInfo *rinfo = (GIRealInfo *)info;
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
||||||
SimpleTypeBlob *type;
|
SimpleTypeBlob *type;
|
||||||
|
|
||||||
g_return_val_if_fail (info != NULL, -1);
|
g_return_val_if_fail (info != NULL, FALSE);
|
||||||
g_return_val_if_fail (GI_IS_TYPE_INFO (info), -1);
|
g_return_val_if_fail (GI_IS_TYPE_INFO (info), FALSE);
|
||||||
|
|
||||||
type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
|
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->tag == GI_TYPE_TAG_ARRAY)
|
||||||
{
|
{
|
||||||
if (blob->has_size)
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,7 +99,8 @@ GI_AVAILABLE_IN_ALL
|
|||||||
gssize gi_type_info_get_array_length_index (GITypeInfo *info);
|
gssize gi_type_info_get_array_length_index (GITypeInfo *info);
|
||||||
|
|
||||||
GI_AVAILABLE_IN_ALL
|
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
|
GI_AVAILABLE_IN_ALL
|
||||||
gboolean gi_type_info_is_zero_terminated (GITypeInfo *info);
|
gboolean gi_type_info_is_zero_terminated (GITypeInfo *info);
|
||||||
|
Loading…
Reference in New Issue
Block a user