From 2d47c55e85c74333663a70e76752865f513a1731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Bonithon?= <gael@xfce.org> Date: Sat, 28 Dec 2024 16:20:08 +0100 Subject: [PATCH 1/3] channel: Fix get_arrayv() return value When the array is empty, it should be returned as is, instead of NULL: this is not a case of failure. So, in particular, when get_string_list() is called, an empty string array (NULL-terminated) is returned, and not NULL, as advertised in its documentation: get_string_list() should only return NULL if the property doesn't exist (or in case of failure more generally). --- xfconf/xfconf-channel.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/xfconf/xfconf-channel.c b/xfconf/xfconf-channel.c index f84628e..dc540ff 100644 --- a/xfconf/xfconf-channel.c +++ b/xfconf/xfconf-channel.c @@ -1534,7 +1534,6 @@ xfconf_channel_get_arrayv(XfconfChannel *channel, const gchar *property) { GValue val = G_VALUE_INIT; - GPtrArray *arr = NULL; gboolean ret; g_return_val_if_fail(XFCONF_IS_CHANNEL(channel) && property, NULL); @@ -1551,13 +1550,7 @@ xfconf_channel_get_arrayv(XfconfChannel *channel, return NULL; } - /* Do not free it, it is owned by the GValue in cache */ - arr = g_value_get_boxed(&val); - if (!arr->len) { - g_ptr_array_free(arr, TRUE); - return NULL; - } - return arr; + return g_value_get_boxed(&val); } /** -- GitLab From ad9eaf50943e40c4f822e6b54545fec41bb2b787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Bonithon?= <gael@xfce.org> Date: Sat, 28 Dec 2024 16:25:52 +0100 Subject: [PATCH 2/3] channel: Warn in case of failure in get_string_list() --- xfconf/xfconf-channel.c | 1 + 1 file changed, 1 insertion(+) diff --git a/xfconf/xfconf-channel.c b/xfconf/xfconf-channel.c index dc540ff..9ccb7e7 100644 --- a/xfconf/xfconf-channel.c +++ b/xfconf/xfconf-channel.c @@ -838,6 +838,7 @@ xfconf_channel_get_string_list(XfconfChannel *channel, GValue *val = g_ptr_array_index(arr, i); if (G_VALUE_TYPE(val) != G_TYPE_STRING) { + g_warning("Unexpected value type %s", G_VALUE_TYPE_NAME(val)); xfconf_array_free(arr); g_strfreev(values); return NULL; -- GitLab From 147771a24596df01c9d8dca40151eb7643af3b28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Bonithon?= <gael@xfce.org> Date: Sun, 29 Dec 2024 06:59:38 +0100 Subject: [PATCH 3/3] channel: Complete and harmonize docs of get_string_list()/get_arrayv() --- xfconf/xfconf-channel.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/xfconf/xfconf-channel.c b/xfconf/xfconf-channel.c index 9ccb7e7..c9716f3 100644 --- a/xfconf/xfconf-channel.c +++ b/xfconf/xfconf-channel.c @@ -814,9 +814,10 @@ xfconf_channel_get_string(XfconfChannel *channel, * * Retrieves the string list value associated with @property on @channel. * - * Returns: (transfer full) (element-type utf8) (array zero-terminated=1): A newly-allocated string list which should be freed with + * Returns: (transfer full) (element-type utf8) (array zero-terminated=1) (nullable): + * A newly-allocated string list which should be freed with * g_strfreev() when no longer needed. If @property is not in - * @channel, %NULL is returned. + * @channel, or in case of failure, %NULL is returned. */ gchar ** xfconf_channel_get_string_list(XfconfChannel *channel, @@ -1527,8 +1528,8 @@ out: * a #GPtrArray, which can be freed with xfconf_array_free() * when no longer needed. * - * Returns: (transfer full) (element-type GValue) (nullable): A newly-allocated #GPtrArray on success, - * or %NULL on failure. + * Returns: (transfer full) (element-type GValue) (nullable): A newly-allocated #GPtrArray. + * If @property is not in @channel, or in case of failure, %NULL is returned. **/ GPtrArray * xfconf_channel_get_arrayv(XfconfChannel *channel, -- GitLab