Merge branch '3155-girepository-more-api-cleanups' into 'main'

girepository: Change various alignments to use size_t

See merge request GNOME/glib!3833
This commit is contained in:
Philip Withnall 2024-01-18 14:50:42 +00:00
commit b13d8883b8
7 changed files with 162 additions and 102 deletions

View File

@ -262,50 +262,63 @@ gi_arg_info_get_scope (GIArgInfo *info)
/** /**
* gi_arg_info_get_closure_index: * gi_arg_info_get_closure_index:
* @info: a #GIArgInfo * @info: a #GIArgInfo
* @out_closure_index: (out) (optional): return location for the closure index
* *
* Obtain the index of the user data argument. This is only valid * Obtain the index of the user data argument. This is only valid
* for arguments which are callbacks. * for arguments which are callbacks.
* *
* Returns: Index of the user data argument or `-1` if there is none * Returns: `TRUE` if the argument has a user data argument
* Since: 2.80 * Since: 2.80
*/ */
gssize gboolean
gi_arg_info_get_closure_index (GIArgInfo *info) gi_arg_info_get_closure_index (GIArgInfo *info,
unsigned int *out_closure_index)
{ {
GIRealInfo *rinfo = (GIRealInfo *)info; GIRealInfo *rinfo = (GIRealInfo *)info;
ArgBlob *blob; ArgBlob *blob;
gboolean has_closure_index;
g_return_val_if_fail (info != NULL, -1); g_return_val_if_fail (info != NULL, FALSE);
g_return_val_if_fail (GI_IS_ARG_INFO (info), -1); g_return_val_if_fail (GI_IS_ARG_INFO (info), FALSE);
blob = (ArgBlob *)&rinfo->typelib->data[rinfo->offset]; blob = (ArgBlob *)&rinfo->typelib->data[rinfo->offset];
return blob->closure; has_closure_index = (blob->closure >= 0);
if (out_closure_index != NULL)
*out_closure_index = has_closure_index ? blob->closure : 0;
return has_closure_index;
} }
/** /**
* gi_arg_info_get_destroy_index: * gi_arg_info_get_destroy_index:
* @info: a #GIArgInfo * @info: a #GIArgInfo
* @out_destroy_index: (out) (optional): return location for the destroy index
* *
* Obtains the index of the [type@GLib.DestroyNotify] argument. This is only * Obtains the index of the [type@GLib.DestroyNotify] argument. This is only
* valid for arguments which are callbacks. * valid for arguments which are callbacks.
* *
* Returns: Index of the [type@GLib.DestroyNotify] argument or `-1` if there is * Returns: `TRUE` if the argument has a [type@GLib.DestroyNotify] argument
* none
* Since: 2.80 * Since: 2.80
*/ */
gssize gboolean
gi_arg_info_get_destroy_index (GIArgInfo *info) gi_arg_info_get_destroy_index (GIArgInfo *info,
unsigned int *out_destroy_index)
{ {
GIRealInfo *rinfo = (GIRealInfo *)info; GIRealInfo *rinfo = (GIRealInfo *)info;
ArgBlob *blob; ArgBlob *blob;
gboolean has_destroy_index;
g_return_val_if_fail (info != NULL, -1); g_return_val_if_fail (info != NULL, FALSE);
g_return_val_if_fail (GI_IS_ARG_INFO (info), -1); g_return_val_if_fail (GI_IS_ARG_INFO (info), FALSE);
blob = (ArgBlob *)&rinfo->typelib->data[rinfo->offset]; blob = (ArgBlob *)&rinfo->typelib->data[rinfo->offset];
return blob->destroy; has_destroy_index = (blob->destroy >= 0);
if (out_destroy_index != NULL)
*out_destroy_index = has_destroy_index ? blob->destroy : 0;
return has_destroy_index;
} }
/** /**

View File

@ -69,10 +69,12 @@ GI_AVAILABLE_IN_ALL
GIScopeType gi_arg_info_get_scope (GIArgInfo *info); GIScopeType gi_arg_info_get_scope (GIArgInfo *info);
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL
gssize gi_arg_info_get_closure_index (GIArgInfo *info); gboolean gi_arg_info_get_closure_index (GIArgInfo *info,
unsigned int *out_closure_index);
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL
gssize gi_arg_info_get_destroy_index (GIArgInfo *info); gboolean gi_arg_info_get_destroy_index (GIArgInfo *info,
unsigned int *out_destroy_index);
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL
GITypeInfo * gi_arg_info_get_type_info (GIArgInfo *info); GITypeInfo * gi_arg_info_get_type_info (GIArgInfo *info);

View File

@ -70,6 +70,27 @@ typedef enum
GI_IR_NODE_XREF = 19 GI_IR_NODE_XREF = 19
} GIIrNodeTypeId; } GIIrNodeTypeId;
/**
* GIIrOffsetsState:
* @GI_IR_OFFSETS_UNKNOWN: offsets have not been calculated yet
* @GI_IR_OFFSETS_COMPUTED: offsets have been successfully calculated
* @GI_IR_OFFSETS_FAILED: calculating the offsets failed
* @GI_IR_OFFSETS_IN_PROGRESS: offsets are currently being calculated (used to
* detect type recursion)
*
* State tracking for calculating size and alignment of
* [type@GIRepository.IrNode]s.
*
* Since: 2.80
*/
typedef enum
{
GI_IR_OFFSETS_UNKNOWN,
GI_IR_OFFSETS_COMPUTED,
GI_IR_OFFSETS_FAILED,
GI_IR_OFFSETS_IN_PROGRESS,
} GIIrOffsetsState;
struct _GIIrNode struct _GIIrNode
{ {
GIIrNodeTypeId type; GIIrNodeTypeId type;
@ -261,8 +282,9 @@ struct _GIIrNodeInterface
GList *interfaces; GList *interfaces;
GList *prerequisites; GList *prerequisites;
gssize alignment; size_t alignment;
size_t size; size_t size;
GIIrOffsetsState offsets_state;
GList *members; GList *members;
}; };
@ -311,8 +333,9 @@ struct _GIIrNodeBoxed
char *gtype_name; char *gtype_name;
char *gtype_init; char *gtype_init;
gssize alignment; size_t alignment;
size_t size; size_t size;
GIIrOffsetsState offsets_state;
GList *members; GList *members;
}; };
@ -334,8 +357,9 @@ struct _GIIrNodeStruct
char *copy_func; char *copy_func;
char *free_func; char *free_func;
gssize alignment; size_t alignment;
size_t size; size_t size;
GIIrOffsetsState offsets_state;
GList *members; GList *members;
}; };
@ -355,8 +379,9 @@ struct _GIIrNodeUnion
char *copy_func; char *copy_func;
char *free_func; char *free_func;
gssize alignment; size_t alignment;
size_t size; size_t size;
GIIrOffsetsState offsets_state;
int discriminator_offset; int discriminator_offset;
GIIrNodeType *discriminator_type; GIIrNodeType *discriminator_type;

View File

@ -150,7 +150,7 @@ compute_enum_storage_type (GIIrNodeEnum *enum_node)
static gboolean static gboolean
get_enum_size_alignment (GIIrNodeEnum *enum_node, get_enum_size_alignment (GIIrNodeEnum *enum_node,
size_t *size, size_t *size,
gssize *alignment) size_t *alignment)
{ {
ffi_type *type_ffi; ffi_type *type_ffi;
@ -189,7 +189,7 @@ static gboolean
get_interface_size_alignment (GIIrTypelibBuild *build, get_interface_size_alignment (GIIrTypelibBuild *build,
GIIrNodeType *type, GIIrNodeType *type,
size_t *size, size_t *size,
gssize *alignment, size_t *alignment,
const char *who) const char *who)
{ {
GIIrNode *iface; GIIrNode *iface;
@ -198,8 +198,8 @@ get_interface_size_alignment (GIIrTypelibBuild *build,
if (!iface) if (!iface)
{ {
gi_ir_module_fatal (build, 0, "Can't resolve type '%s' for %s", type->giinterface, who); gi_ir_module_fatal (build, 0, "Can't resolve type '%s' for %s", type->giinterface, who);
*size = -1; *size = 0;
*alignment = -1; *alignment = 0;
return FALSE; return FALSE;
} }
@ -253,9 +253,9 @@ get_interface_size_alignment (GIIrTypelibBuild *build,
g_warning ("%s has is not a pointer and is of type %s", g_warning ("%s has is not a pointer and is of type %s",
who, who,
gi_ir_node_type_to_string (iface->type)); gi_ir_node_type_to_string (iface->type));
*size = -1; *size = 0;
*alignment = -1; *alignment = 0;
break; return FALSE;
} }
} }
@ -266,7 +266,7 @@ static gboolean
get_type_size_alignment (GIIrTypelibBuild *build, get_type_size_alignment (GIIrTypelibBuild *build,
GIIrNodeType *type, GIIrNodeType *type,
size_t *size, size_t *size,
gssize *alignment, size_t *alignment,
const char *who) const char *who)
{ {
ffi_type *type_ffi; ffi_type *type_ffi;
@ -278,14 +278,14 @@ get_type_size_alignment (GIIrTypelibBuild *build,
else if (type->tag == GI_TYPE_TAG_ARRAY) else if (type->tag == GI_TYPE_TAG_ARRAY)
{ {
size_t elt_size; size_t elt_size;
gssize elt_alignment; size_t elt_alignment;
if (!type->has_size if (!type->has_size
|| !get_type_size_alignment(build, type->parameter_type1, || !get_type_size_alignment(build, type->parameter_type1,
&elt_size, &elt_alignment, who)) &elt_size, &elt_alignment, who))
{ {
*size = -1; *size = 0;
*alignment = -1; *alignment = 0;
return FALSE; return FALSE;
} }
@ -307,8 +307,8 @@ get_type_size_alignment (GIIrTypelibBuild *build,
if (type_ffi == &ffi_type_void) if (type_ffi == &ffi_type_void)
{ {
g_warning ("%s has void type", who); g_warning ("%s has void type", who);
*size = -1; *size = 0;
*alignment = -1; *alignment = 0;
return FALSE; return FALSE;
} }
else if (type_ffi == &ffi_type_pointer) else if (type_ffi == &ffi_type_pointer)
@ -316,8 +316,8 @@ get_type_size_alignment (GIIrTypelibBuild *build,
g_warning ("%s has is not a pointer and is of type %s", g_warning ("%s has is not a pointer and is of type %s",
who, who,
gi_type_tag_to_string (type->tag)); gi_type_tag_to_string (type->tag));
*size = -1; *size = 0;
*alignment = -1; *alignment = 0;
return FALSE; return FALSE;
} }
} }
@ -335,7 +335,7 @@ get_field_size_alignment (GIIrTypelibBuild *build,
GIIrNodeField *field, GIIrNodeField *field,
GIIrNode *parent_node, GIIrNode *parent_node,
size_t *size, size_t *size,
gssize *alignment) size_t *alignment)
{ {
GIIrModule *module = build->module; GIIrModule *module = build->module;
char *who; char *who;
@ -363,14 +363,15 @@ compute_struct_field_offsets (GIIrTypelibBuild *build,
GIIrNode *node, GIIrNode *node,
GList *members, GList *members,
size_t *size_out, size_t *size_out,
gssize *alignment_out) size_t *alignment_out,
GIIrOffsetsState *offsets_state_out)
{ {
int size = 0; size_t size = 0;
int alignment = 1; size_t alignment = 1;
GList *l; GList *l;
gboolean have_error = FALSE; gboolean have_error = FALSE;
*alignment_out = -2; /* mark to detect recursion */ *offsets_state_out = GI_IR_OFFSETS_IN_PROGRESS; /* mark to detect recursion */
for (l = members; l; l = l->next) for (l = members; l; l = l->next)
{ {
@ -383,7 +384,7 @@ compute_struct_field_offsets (GIIrTypelibBuild *build,
if (!have_error) if (!have_error)
{ {
size_t member_size; size_t member_size;
gssize member_alignment; size_t member_alignment;
if (get_field_size_alignment (build, field, node, if (get_field_size_alignment (build, field, node,
&member_size, &member_alignment)) &member_size, &member_alignment))
@ -415,11 +416,13 @@ compute_struct_field_offsets (GIIrTypelibBuild *build,
{ {
*size_out = size; *size_out = size;
*alignment_out = alignment; *alignment_out = alignment;
*offsets_state_out = GI_IR_OFFSETS_COMPUTED;
} }
else else
{ {
*size_out = -1; *size_out = 0;
*alignment_out = -1; *alignment_out = 0;
*offsets_state_out = GI_IR_OFFSETS_FAILED;
} }
return !have_error; return !have_error;
@ -430,14 +433,15 @@ compute_union_field_offsets (GIIrTypelibBuild *build,
GIIrNode *node, GIIrNode *node,
GList *members, GList *members,
size_t *size_out, size_t *size_out,
gssize *alignment_out) size_t *alignment_out,
GIIrOffsetsState *offsets_state_out)
{ {
size_t size = 0; size_t size = 0;
int alignment = 1; size_t alignment = 1;
GList *l; GList *l;
gboolean have_error = FALSE; gboolean have_error = FALSE;
*alignment_out = -2; /* mark to detect recursion */ *offsets_state_out = GI_IR_OFFSETS_IN_PROGRESS; /* mark to detect recursion */
for (l = members; l; l = l->next) for (l = members; l; l = l->next)
{ {
@ -450,7 +454,7 @@ compute_union_field_offsets (GIIrTypelibBuild *build,
if (!have_error) if (!have_error)
{ {
size_t member_size; size_t member_size;
gssize member_alignment; size_t member_alignment;
if (get_field_size_alignment (build,field, node, if (get_field_size_alignment (build,field, node,
&member_size, &member_alignment)) &member_size, &member_alignment))
@ -471,11 +475,13 @@ compute_union_field_offsets (GIIrTypelibBuild *build,
{ {
*size_out = size; *size_out = size;
*alignment_out = alignment; *alignment_out = alignment;
*offsets_state_out = GI_IR_OFFSETS_COMPUTED;
} }
else else
{ {
*size_out = -1; *size_out = 0;
*alignment_out = -1; *alignment_out = 0;
*offsets_state_out = GI_IR_OFFSETS_FAILED;
} }
return !have_error; return !have_error;
@ -484,22 +490,17 @@ compute_union_field_offsets (GIIrTypelibBuild *build,
static gboolean static gboolean
check_needs_computation (GIIrTypelibBuild *build, check_needs_computation (GIIrTypelibBuild *build,
GIIrNode *node, GIIrNode *node,
int alignment) GIIrOffsetsState offsets_state)
{ {
GIIrModule *module = build->module; GIIrModule *module = build->module;
/*
* 0: Not yet computed if (offsets_state == GI_IR_OFFSETS_IN_PROGRESS)
* >0: Previously succeeded
* -1: Previously failed
* -2: In progress
*/
if (alignment == -2)
{ {
g_warning ("Recursion encountered when computing the size of %s.%s", g_warning ("Recursion encountered when computing the size of %s.%s",
module->name, node->name); module->name, node->name);
} }
return alignment == 0; return offsets_state == GI_IR_OFFSETS_UNKNOWN;
} }
/* /*
@ -532,22 +533,22 @@ gi_ir_node_compute_offsets (GIIrTypelibBuild *build,
{ {
GIIrNodeBoxed *boxed = (GIIrNodeBoxed *)node; GIIrNodeBoxed *boxed = (GIIrNodeBoxed *)node;
if (!check_needs_computation (build, node, boxed->alignment)) if (!check_needs_computation (build, node, boxed->offsets_state))
return; return;
compute_struct_field_offsets (build, node, boxed->members, compute_struct_field_offsets (build, node, boxed->members,
&boxed->size, &boxed->alignment); &boxed->size, &boxed->alignment, &boxed->offsets_state);
break; break;
} }
case GI_IR_NODE_STRUCT: case GI_IR_NODE_STRUCT:
{ {
GIIrNodeStruct *struct_ = (GIIrNodeStruct *)node; GIIrNodeStruct *struct_ = (GIIrNodeStruct *)node;
if (!check_needs_computation (build, node, struct_->alignment)) if (!check_needs_computation (build, node, struct_->offsets_state))
return; return;
compute_struct_field_offsets (build, node, struct_->members, compute_struct_field_offsets (build, node, struct_->members,
&struct_->size, &struct_->alignment); &struct_->size, &struct_->alignment, &struct_->offsets_state);
break; break;
} }
case GI_IR_NODE_OBJECT: case GI_IR_NODE_OBJECT:
@ -555,22 +556,22 @@ gi_ir_node_compute_offsets (GIIrTypelibBuild *build,
{ {
GIIrNodeInterface *iface = (GIIrNodeInterface *)node; GIIrNodeInterface *iface = (GIIrNodeInterface *)node;
if (!check_needs_computation (build, node, iface->alignment)) if (!check_needs_computation (build, node, iface->offsets_state))
return; return;
compute_struct_field_offsets (build, node, iface->members, compute_struct_field_offsets (build, node, iface->members,
&iface->size, &iface->alignment); &iface->size, &iface->alignment, &iface->offsets_state);
break; break;
} }
case GI_IR_NODE_UNION: case GI_IR_NODE_UNION:
{ {
GIIrNodeUnion *union_ = (GIIrNodeUnion *)node; GIIrNodeUnion *union_ = (GIIrNodeUnion *)node;
if (!check_needs_computation (build, node, union_->alignment)) if (!check_needs_computation (build, node, union_->offsets_state))
return; return;
compute_union_field_offsets (build, (GIIrNode*)union_, union_->members, compute_union_field_offsets (build, (GIIrNode*)union_, union_->members,
&union_->size, &union_->alignment); &union_->size, &union_->alignment, &union_->offsets_state);
break; break;
} }
case GI_IR_NODE_ENUM: case GI_IR_NODE_ENUM:

View File

@ -244,8 +244,8 @@ write_type_info (const char *ns,
} }
else if (tag == GI_TYPE_TAG_ARRAY) else if (tag == GI_TYPE_TAG_ARRAY)
{ {
gssize length; unsigned int length_index;
gssize size; size_t size;
const char *name = NULL; const char *name = NULL;
xml_start_element (file, "array"); xml_start_element (file, "array");
@ -271,13 +271,11 @@ write_type_info (const char *ns,
type = gi_type_info_get_param_type (info, 0); type = gi_type_info_get_param_type (info, 0);
length = gi_type_info_get_array_length_index (info); if (gi_type_info_get_array_length_index (info, &length_index))
if (length >= 0) xml_printf (file, " length=\"%u\"", length_index);
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\"");
@ -492,6 +490,7 @@ write_callable_info (const char *ns,
for (unsigned int i = 0; i < gi_callable_info_get_n_args (info); i++) for (unsigned int i = 0; i < gi_callable_info_get_n_args (info); i++)
{ {
GIArgInfo *arg = gi_callable_info_get_arg (info, i); GIArgInfo *arg = gi_callable_info_get_arg (info, i);
unsigned int closure_index, destroy_index;
xml_start_element (file, "parameter"); xml_start_element (file, "parameter");
xml_printf (file, " name=\"%s\"", xml_printf (file, " name=\"%s\"",
@ -543,13 +542,11 @@ write_callable_info (const char *ns,
g_assert_not_reached (); g_assert_not_reached ();
} }
if (gi_arg_info_get_closure_index (arg) >= 0) if (gi_arg_info_get_closure_index (arg, &closure_index))
xml_printf (file, " closure=\"%" G_GSSIZE_FORMAT "\"", xml_printf (file, " closure=\"%u\"", closure_index);
gi_arg_info_get_closure_index (arg));
if (gi_arg_info_get_destroy_index (arg) >= 0) if (gi_arg_info_get_destroy_index (arg, &destroy_index))
xml_printf (file, " destroy=\"%" G_GSSIZE_FORMAT "\"", xml_printf (file, " destroy=\"%u\"", destroy_index);
gi_arg_info_get_destroy_index (arg));
if (gi_arg_info_is_skip (arg)) if (gi_arg_info_is_skip (arg))
xml_printf (file, " skip=\"1\""); xml_printf (file, " skip=\"1\"");

View File

@ -232,23 +232,25 @@ gi_type_info_get_interface (GITypeInfo *info)
/** /**
* gi_type_info_get_array_length_index: * gi_type_info_get_array_length_index:
* @info: a #GITypeInfo * @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. * 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 * Returns: `TRUE` if the type is an array and has a length argument
* or it has no length argument
* Since: 2.80 * Since: 2.80
*/ */
gssize gboolean
gi_type_info_get_array_length_index (GITypeInfo *info) gi_type_info_get_array_length_index (GITypeInfo *info,
unsigned int *out_length_index)
{ {
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];
@ -259,32 +261,41 @@ gi_type_info_get_array_length_index (GITypeInfo *info)
if (blob->tag == GI_TYPE_TAG_ARRAY) if (blob->tag == GI_TYPE_TAG_ARRAY)
{ {
if (blob->has_length) 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;
} }
/** /**
* 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 +306,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;
} }
/** /**
@ -341,10 +358,12 @@ gi_type_info_is_zero_terminated (GITypeInfo *info)
* *
* Obtain the array type for this type. * Obtain the array type for this type.
* *
* See [enum@GIRepository.ArrayType] for a list of possible values. If the type * See [enum@GIRepository.ArrayType] for a list of possible values.
* tag of this type is not array, `-1` will be returned.
* *
* Returns: the array type or `-1` * It is an error to call this on an @info which is not an array type. Use
* [method@GIRepository.TypeInfo.get_tag] to check.
*
* Returns: the array type
* Since: 2.80 * Since: 2.80
*/ */
GIArrayType GIArrayType
@ -366,7 +385,8 @@ gi_type_info_get_array_type (GITypeInfo *info)
return blob->array_type; return blob->array_type;
} }
return -1; /* Not an array type */
g_assert_not_reached ();
} }
/** /**

View File

@ -96,10 +96,12 @@ GI_AVAILABLE_IN_ALL
GIBaseInfo * gi_type_info_get_interface (GITypeInfo *info); GIBaseInfo * gi_type_info_get_interface (GITypeInfo *info);
GI_AVAILABLE_IN_ALL 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 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);