gstrfuncs: Add missing (transfer none) annotations for several funcs

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 <pwithnall@gnome.org>
Fixes: #3286
This commit is contained in:
Philip Withnall 2024-03-13 14:48:07 +00:00
parent 92eb8d2ddc
commit 6c3ad23634

View File

@ -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,