From 96daf7b8aec18dcf2cc232265ffeacc4e426e864 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 26 Jan 2021 14:16:26 +0100 Subject: 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". I don't think the non-macro version requires any pointer cast, since "instance" is a void pointer. Was this referring to the handler_id_ptr? That doesn't seem right either, because the caller should always provide a "gulong *" pointer and nothing else. --- gobject/gsignal.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gobject/gsignal.c b/gobject/gsignal.c index 78f878a0b..e41c60203 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); } -- cgit v1.2.1