diff options
author | Thomas Haller <thaller@redhat.com> | 2021-01-26 14:09:02 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-01-27 09:26:35 +0100 |
commit | 3ba97a69d7eb5adf82a2dc5a38a655bd07a58efa (patch) | |
tree | aaf91f109b30dd51945c2e5aa79ea8ce78b11f0f | |
parent | e0f2cf536b0dfdba6936d87114d0a3bce42bfe86 (diff) | |
download | glib-3ba97a69d7eb5adf82a2dc5a38a655bd07a58efa.tar.gz |
gsignal: let g_clear_signal_handler() evaluate argument only once
Preferably macros behave function-like to minimize surprises. That
means for example that they evaluate all arguments exactly once.
Rework g_clear_signal_handler() to assign the macro parameters
to auto variables so they are accessed exactly once.
Also, drop the static assert for the size of (*handler_id_ptr).
As we now assign to a "gulong *" pointer, the compiler already
checks. In fact, the check is now stricter than before, previously
it would have allowed a pointer to a "signed long".
This is a change in behavior of the macro and the stricter compile
check could cause a build failure with broken code.
Also, clear the handler id first, before calling
g_signal_handler_disconnect(). Disconnecting a signal invokes the
destroy notify, which can have side effects. It just feels cleaner
to first reset the *_handler_id_ptr, before those side effects
can happen. Of course, in practice it makes little difference.
-rw-r--r-- | gobject/gsignal.h | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/gobject/gsignal.h b/gobject/gsignal.h index 536102dad..64aa9d6a8 100644 --- a/gobject/gsignal.h +++ b/gobject/gsignal.h @@ -451,13 +451,14 @@ void g_clear_signal_handler (gulong *handler_id_ptr, #define g_clear_signal_handler(handler_id_ptr, instance) \ G_STMT_START { \ - G_STATIC_ASSERT (sizeof *(handler_id_ptr) == sizeof (gulong)); \ - gulong _handler_id = *(handler_id_ptr); \ + gpointer const _instance = (instance); \ + gulong *const _handler_id_ptr = (handler_id_ptr); \ + const gulong _handler_id = *_handler_id_ptr; \ \ if (_handler_id > 0) \ { \ - g_signal_handler_disconnect ((instance), _handler_id); \ - *(handler_id_ptr) = 0; \ + *_handler_id_ptr = 0; \ + g_signal_handler_disconnect (_instance, _handler_id); \ } \ } G_STMT_END \ GLIB_AVAILABLE_MACRO_IN_2_62 |