giarginfo: Return indexes as uints

As with previous commits, don’t use up half the return value space to
indicate an invalid index.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3155
This commit is contained in:
Philip Withnall 2024-01-17 10:36:45 +00:00
parent fe6f9a661b
commit 9fcec66115
3 changed files with 35 additions and 21 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

@ -490,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\"",
@ -541,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\"");