From 9fcec66115e7dba03e03881439cccabe934d512d Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 17 Jan 2024 10:36:45 +0000 Subject: [PATCH] giarginfo: Return indexes as uints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As with previous commits, don’t use up half the return value space to indicate an invalid index. Signed-off-by: Philip Withnall Helps: #3155 --- girepository/giarginfo.c | 39 ++++++++++++++++++++++++++------------- girepository/giarginfo.h | 6 ++++-- girepository/girwriter.c | 11 +++++------ 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/girepository/giarginfo.c b/girepository/giarginfo.c index a0ec63301..17cdb47f0 100644 --- a/girepository/giarginfo.c +++ b/girepository/giarginfo.c @@ -262,50 +262,63 @@ gi_arg_info_get_scope (GIArgInfo *info) /** * gi_arg_info_get_closure_index: * @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 * 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 */ -gssize -gi_arg_info_get_closure_index (GIArgInfo *info) +gboolean +gi_arg_info_get_closure_index (GIArgInfo *info, + unsigned int *out_closure_index) { GIRealInfo *rinfo = (GIRealInfo *)info; ArgBlob *blob; + gboolean has_closure_index; - g_return_val_if_fail (info != NULL, -1); - g_return_val_if_fail (GI_IS_ARG_INFO (info), -1); + g_return_val_if_fail (info != NULL, FALSE); + g_return_val_if_fail (GI_IS_ARG_INFO (info), FALSE); 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: * @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 * valid for arguments which are callbacks. * - * Returns: Index of the [type@GLib.DestroyNotify] argument or `-1` if there is - * none + * Returns: `TRUE` if the argument has a [type@GLib.DestroyNotify] argument * Since: 2.80 */ -gssize -gi_arg_info_get_destroy_index (GIArgInfo *info) +gboolean +gi_arg_info_get_destroy_index (GIArgInfo *info, + unsigned int *out_destroy_index) { GIRealInfo *rinfo = (GIRealInfo *)info; ArgBlob *blob; + gboolean has_destroy_index; - g_return_val_if_fail (info != NULL, -1); - g_return_val_if_fail (GI_IS_ARG_INFO (info), -1); + g_return_val_if_fail (info != NULL, FALSE); + g_return_val_if_fail (GI_IS_ARG_INFO (info), FALSE); 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; } /** diff --git a/girepository/giarginfo.h b/girepository/giarginfo.h index 42592ea67..2fec04216 100644 --- a/girepository/giarginfo.h +++ b/girepository/giarginfo.h @@ -69,10 +69,12 @@ GI_AVAILABLE_IN_ALL GIScopeType gi_arg_info_get_scope (GIArgInfo *info); 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 -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 GITypeInfo * gi_arg_info_get_type_info (GIArgInfo *info); diff --git a/girepository/girwriter.c b/girepository/girwriter.c index 4d8081ce9..0116795e4 100644 --- a/girepository/girwriter.c +++ b/girepository/girwriter.c @@ -490,6 +490,7 @@ write_callable_info (const char *ns, for (unsigned int i = 0; i < gi_callable_info_get_n_args (info); i++) { GIArgInfo *arg = gi_callable_info_get_arg (info, i); + unsigned int closure_index, destroy_index; xml_start_element (file, "parameter"); xml_printf (file, " name=\"%s\"", @@ -541,13 +542,11 @@ write_callable_info (const char *ns, g_assert_not_reached (); } - if (gi_arg_info_get_closure_index (arg) >= 0) - xml_printf (file, " closure=\"%" G_GSSIZE_FORMAT "\"", - gi_arg_info_get_closure_index (arg)); + if (gi_arg_info_get_closure_index (arg, &closure_index)) + xml_printf (file, " closure=\"%u\"", closure_index); - if (gi_arg_info_get_destroy_index (arg) >= 0) - xml_printf (file, " destroy=\"%" G_GSSIZE_FORMAT "\"", - gi_arg_info_get_destroy_index (arg)); + if (gi_arg_info_get_destroy_index (arg, &destroy_index)) + xml_printf (file, " destroy=\"%u\"", destroy_index); if (gi_arg_info_is_skip (arg)) xml_printf (file, " skip=\"1\"");