[glib/th/gsignal-cleanup: 3/3] gsignal: use g_clear_signal_handler() macro to implement g_clear_signal_handler() function




commit f07070fb9a8c211839674bfc71ef349bd6fa4bc7
Author: Thomas Haller <thaller redhat com>
Date:   Tue Jan 26 14:16:26 2021 +0100

    gsignal: use g_clear_signal_handler() macro to implement g_clear_signal_handler() function
    
    We have a "good" implementation of g_clear_signal_handler() in
    form of a macro. Use it, and don't duplicate the code.
    
    Also add a comment to the documentation that "instance" in fact must
    not point to a valid GObject instance -- if the handler ID is unset.
    
    Also reword the documentation about the reasoning for why a macro
    version exists. The reason is not to use the function "without
    pointer cast". At least I am not clear which part would require
    a pointer cast, surely not the "instance" which is of type gpointer
    already.

 gobject/gsignal.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
---
diff --git a/gobject/gsignal.c b/gobject/gsignal.c
index eb69edf61..df40ab47a 100644
--- a/gobject/gsignal.c
+++ b/gobject/gsignal.c
@@ -4009,6 +4009,7 @@ g_signal_accumulator_first_wins (GSignalInvocationHint *ihint,
  * g_clear_signal_handler:
  * @handler_id_ptr: A pointer to a handler ID (of type #gulong) of the handler to be disconnected.
  * @instance: (type GObject.Object): The instance to remove the signal handler from.
+ *   This pointer may be %NULL or invalid, if the handler ID is zero.
  *
  * Disconnects a handler from @instance so it will not be called during
  * any future or currently ongoing emissions of the signal it has been
@@ -4016,21 +4017,20 @@ g_signal_accumulator_first_wins (GSignalInvocationHint *ihint,
  *
  * If the handler ID is 0 then this function does nothing.
  *
- * A macro is also included that allows this function to be used without
- * pointer casts.
+ * There is also a macro version of this function so that the code
+ * will be inlined.
  *
  * Since: 2.62
  */
-#undef g_clear_signal_handler
 void
-g_clear_signal_handler (gulong   *handler_id_ptr,
-                        gpointer  instance)
+(g_clear_signal_handler) (gulong   *handler_id_ptr,
+                          gpointer  instance)
 {
   g_return_if_fail (handler_id_ptr != NULL);
 
-  if (*handler_id_ptr != 0)
-    {
-      g_signal_handler_disconnect (instance, *handler_id_ptr);
-      *handler_id_ptr = 0;
-    }
+#ifndef g_clear_signal_handler
+#error g_clear_signal_handler() macro is not defined
+#endif
+
+  g_clear_signal_handler (handler_id_ptr, instance);
 }


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