mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-13 15:56:23 +01:00
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.
This commit is contained in:
parent
7777f3bdbe
commit
8416211231
@ -4012,6 +4012,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
|
||||
@ -4019,21 +4020,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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user