From 7c5e930170931a58aaaad361022551a6f9e67df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 20 Feb 2023 10:16:11 +0200 Subject: [PATCH] Allow passing a `NULL` item to `g_list_store_find_with_equal_func()` The `equal_func` closure can already have all required information available without the item, and passing the item via the closure instead of an explicit parameter is more natural for languages that have a concept of closures that can capture variables. --- gio/gliststore.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/gio/gliststore.c b/gio/gliststore.c index e7dbbd38f..f405abd79 100644 --- a/gio/gliststore.c +++ b/gio/gliststore.c @@ -530,7 +530,7 @@ simple_equal (gconstpointer a, /** * g_list_store_find_with_equal_func: * @store: a #GListStore - * @item: (type GObject): an item + * @item: (type GObject) (nullable): an item * @equal_func: (scope call): A custom equality check function * @position: (out) (optional): the first position of @item, if it was found. * @@ -539,6 +539,10 @@ simple_equal (gconstpointer a, * matches. If @item was not found, then @position will not be set, and this * method will return %FALSE. * + * @item is always passed as second parameter to @equal_func. + * + * Since GLib 2.76 it is possible to pass `NULL` for @item. + * * Returns: Whether @store contains @item. If it was found, @position will be * set to the position where @item occurred for the first time. * @@ -559,7 +563,7 @@ g_list_store_find_with_equal_func (GListStore *store, /** * g_list_store_find_with_equal_func_full: * @store: a #GListStore - * @item: (type GObject): an item + * @item: (type GObject) (nullable): an item * @equal_func: (scope call): A custom equality check function * @user_data: (closure): user data for @equal_func * @position: (out) (optional): the first position of @item, if it was found. @@ -567,6 +571,10 @@ g_list_store_find_with_equal_func (GListStore *store, * Like g_list_store_find_with_equal_func() but with an additional @user_data * that is passed to @equal_func. * + * @item is always passed as second parameter to @equal_func. + * + * Since GLib 2.76 it is possible to pass `NULL` for @item. + * * Returns: Whether @store contains @item. If it was found, @position will be * set to the position where @item occurred for the first time. * @@ -582,7 +590,7 @@ g_list_store_find_with_equal_func_full (GListStore *store, GSequenceIter *iter, *begin, *end; g_return_val_if_fail (G_IS_LIST_STORE (store), FALSE); - g_return_val_if_fail (g_type_is_a (G_OBJECT_TYPE (item), store->item_type), + g_return_val_if_fail (item == NULL || g_type_is_a (G_OBJECT_TYPE (item), store->item_type), FALSE); g_return_val_if_fail (equal_func != NULL, FALSE);