From 6c3ad2363412897ef13882797ace7cb401b94531 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 13 Mar 2024 14:48:07 +0000 Subject: [PATCH 1/2] gstrfuncs: Add missing (transfer none) annotations for several funcs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These unfortunately have `gchar*` return types rather than `const gchar*`. This is a historical artifact which we can’t change: while adding `const` would only be an API break and not an ABI break, it would cause all sorts of C++ code which uses GLib to emit new cast warnings (similarly, C code with const correctness compiler warnings enabled would do the same). The incorrect return type causes the GIR scanner to (reasonably) assume the return value is allocated, which is wrong. Fix that by explicitly adding `(transfer none)`. Also add an explicit `(nullable)` because all three functions are. Signed-off-by: Philip Withnall Fixes: #3286 --- glib/gstrfuncs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c index c6faa0367..e1afddf47 100644 --- a/glib/gstrfuncs.c +++ b/glib/gstrfuncs.c @@ -2732,7 +2732,8 @@ g_strjoin (const gchar *separator, * A length of `-1` can be used to mean “search the entire string”, like * `strstr()`. * - * Returns: a pointer to the found occurrence, or `NULL` if not found + * Returns: (transfer none) (nullable): a pointer to the found occurrence, or + * `NULL` if not found */ gchar * g_strstr_len (const gchar *haystack, @@ -2784,7 +2785,8 @@ g_strstr_len (const gchar *haystack, * Searches the string @haystack for the last occurrence * of the string @needle. * - * Returns: a pointer to the found occurrence, or `NULL` if not found + * Returns: (transfer none) (nullable): a pointer to the found occurrence, or + * `NULL` if not found */ gchar * g_strrstr (const gchar *haystack, @@ -2835,7 +2837,8 @@ g_strrstr (const gchar *haystack, * of the string @needle, limiting the length of the search * to @haystack_len. * - * Returns: a pointer to the found occurrence, or `NULL` if not found + * Returns: (transfer none) (nullable): a pointer to the found occurrence, or + * `NULL` if not found */ gchar * g_strrstr_len (const gchar *haystack, From e0c18a2f048a8d5d0fe4d13fbc55abd40d13debf Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 13 Mar 2024 15:06:34 +0000 Subject: [PATCH 2/2] gstrfuncs: Mention slightly odd return types in docs See the previous commit for details. Signed-off-by: Philip Withnall Helps: #3286 --- glib/gstrfuncs.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c index e1afddf47..9af21a953 100644 --- a/glib/gstrfuncs.c +++ b/glib/gstrfuncs.c @@ -2732,6 +2732,9 @@ g_strjoin (const gchar *separator, * A length of `-1` can be used to mean “search the entire string”, like * `strstr()`. * + * The fact that this function returns `gchar *` rather than `const gchar *` is + * a historical artifact. + * * Returns: (transfer none) (nullable): a pointer to the found occurrence, or * `NULL` if not found */ @@ -2785,6 +2788,9 @@ g_strstr_len (const gchar *haystack, * Searches the string @haystack for the last occurrence * of the string @needle. * + * The fact that this function returns `gchar *` rather than `const gchar *` is + * a historical artifact. + * * Returns: (transfer none) (nullable): a pointer to the found occurrence, or * `NULL` if not found */ @@ -2837,6 +2843,9 @@ g_strrstr (const gchar *haystack, * of the string @needle, limiting the length of the search * to @haystack_len. * + * The fact that this function returns `gchar *` rather than `const gchar *` is + * a historical artifact. + * * Returns: (transfer none) (nullable): a pointer to the found occurrence, or * `NULL` if not found */