mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-09 19:06:15 +01:00
gisgnal: Add g_clear_signal_handler
It allows to disconnect a signal handler from GObject instance and at the same time to nullify the signal handler. Provided also a macro for handler type conversion.
This commit is contained in:
parent
32ea5b7e1f
commit
409c1522bc
@ -861,6 +861,7 @@ g_signal_get_invocation_hint
|
||||
g_signal_type_cclosure_new
|
||||
g_signal_accumulator_first_wins
|
||||
g_signal_accumulator_true_handled
|
||||
g_clear_signal_handler
|
||||
<SUBSECTION Private>
|
||||
g_signal_handlers_destroy
|
||||
</SECTION>
|
||||
|
@ -3893,3 +3893,33 @@ g_signal_accumulator_first_wins (GSignalInvocationHint *ihint,
|
||||
g_value_copy (handler_return, return_accu);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* Disconnects a handler from @instance so it will not be called during
|
||||
* any future or currently ongoing emissions of the signal it has been
|
||||
* connected to. The @handler_id_ptr is then set to zero, which is never a valid handler ID value (see g_signal_connect()).
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Since: 2.62
|
||||
*/
|
||||
#undef g_clear_signal_handler
|
||||
void
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -436,6 +436,21 @@ guint g_signal_handlers_disconnect_matched (gpointer instance,
|
||||
gpointer func,
|
||||
gpointer data);
|
||||
|
||||
GLIB_AVAILABLE_IN_2_62
|
||||
void g_clear_signal_handler (gulong *handler_id_ptr,
|
||||
gpointer instance);
|
||||
|
||||
#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); \
|
||||
\
|
||||
if (_handler_id > 0) \
|
||||
{ \
|
||||
g_signal_handler_disconnect ((instance), _handler_id); \
|
||||
*(handler_id_ptr) = 0; \
|
||||
} \
|
||||
} G_STMT_END
|
||||
|
||||
/* --- overriding and chaining --- */
|
||||
GLIB_AVAILABLE_IN_ALL
|
||||
|
Loading…
Reference in New Issue
Block a user