[glib: 1/2] gobject: Allow passing %NULL for @data in g_object_remove_toggle_ref




commit edb40c7171a863d67d15d2d26c32df2c17b5b9e8
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu May 27 21:09:45 2021 +0530

    gobject: Allow passing %NULL for @data in g_object_remove_toggle_ref
    
    gjs has some situations where it's not always aware of the @data that
    was passed into g_object_add_toggle_ref, so allow passing %NULL to
    just match on @notify.
    
    Rebased and updated by Nitin Wartkar
    
    Closes #817

 gobject/gobject.c          | 5 +++--
 tests/gobject/references.c | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/gobject/gobject.c b/gobject/gobject.c
index 750a7d120..2346cb3ef 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -3319,7 +3319,8 @@ g_object_add_toggle_ref (GObject       *object,
  * @notify: a function to call when this reference is the
  *  last reference to the object, or is no longer
  *  the last reference.
- * @data: data to pass to @notify
+ * @data: (nullable): data to pass to @notify, or %NULL to
+ *  match any toggle refs with the @notify argument.
  *
  * Removes a reference added with g_object_add_toggle_ref(). The
  * reference count of the object is decreased by one.
@@ -3345,7 +3346,7 @@ g_object_remove_toggle_ref (GObject       *object,
 
       for (i = 0; i < tstack->n_toggle_refs; i++)
        if (tstack->toggle_refs[i].notify == notify &&
-           tstack->toggle_refs[i].data == data)
+           (tstack->toggle_refs[i].data == data || data == NULL))
          {
            found_one = TRUE;
            tstack->n_toggle_refs -= 1;
diff --git a/tests/gobject/references.c b/tests/gobject/references.c
index 8c1266042..36ff35c63 100644
--- a/tests/gobject/references.c
+++ b/tests/gobject/references.c
@@ -256,7 +256,8 @@ main (int   argc,
   g_assert (object_destroyed == FALSE);
 
   clear_flags ();
-  g_object_remove_toggle_ref (object, toggle_ref2, GUINT_TO_POINTER (24));
+  /* Check that removing a toggle ref with %NULL data works fine. */
+  g_object_remove_toggle_ref (object, toggle_ref2, NULL);
   g_assert (toggle_ref1_weakened == FALSE);
   g_assert (toggle_ref1_strengthened == FALSE);
   g_assert (toggle_ref2_weakened == FALSE);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]