cleanup: Use g_clear_signal_handler() where possible

This is inspired by 98892391d7 where the usage of
`g_signal_handler_disconnect()` without resetting the corresponding
handler id later resulted in a bug. Using `g_clear_signal_handler()`
makes sure we avoid similar bugs and is almost always the better
alternative. We use it for new code, let's clean up the old code to
also use it.

A further benefit is that it can get called even if the passed id is
0, allowing us to remove a lot of now unnessecary checks, and the fact
that `g_clear_signal_handler()` checks for the right type size, forcing us
to clean up all places where we used `guint` instead of `gulong`.

No functional changes intended here and all changes should be trivial,
thus bundled in one big commit.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/940
This commit is contained in:
Robert Mader
2019-11-16 01:25:52 +01:00
committed by Florian Müllner
parent 22d1febf3c
commit 92375c75f8
45 changed files with 168 additions and 303 deletions

View File

@ -54,9 +54,9 @@ struct _GestureActionData
{
ClutterGestureAction *gesture;
MetaSequenceState state;
guint gesture_begin_id;
guint gesture_end_id;
guint gesture_cancel_id;
gulong gesture_begin_id;
gulong gesture_end_id;
gulong gesture_cancel_id;
};
struct _MetaGestureTrackerPrivate
@ -334,9 +334,9 @@ cancel_and_unref_gesture_cb (ClutterGestureAction *action)
static void
clear_gesture_data (GestureActionData *data)
{
g_signal_handler_disconnect (data->gesture, data->gesture_begin_id);
g_signal_handler_disconnect (data->gesture, data->gesture_end_id);
g_signal_handler_disconnect (data->gesture, data->gesture_cancel_id);
g_clear_signal_handler (&data->gesture_begin_id, data->gesture);
g_clear_signal_handler (&data->gesture_end_id, data->gesture);
g_clear_signal_handler (&data->gesture_cancel_id, data->gesture);
/* Defer cancellation to an idle, as it may happen within event handling */
g_idle_add ((GSourceFunc) cancel_and_unref_gesture_cb, data->gesture);

View File

@ -43,7 +43,7 @@ struct _MetaPlayRequest
{
ca_proplist *props;
uint32_t id;
guint cancel_id;
gulong cancel_id;
GCancellable *cancellable;
MetaSoundPlayer *player;
};
@ -119,8 +119,8 @@ finish_cb (ca_context *context,
if (error_code != CA_ERROR_CANCELED)
g_cancellable_disconnect (req->cancellable, req->cancel_id);
else if (req->cancellable != NULL && req->cancel_id != 0)
g_signal_handler_disconnect (req->cancellable, req->cancel_id);
else if (req->cancellable != NULL)
g_clear_signal_handler (&req->cancel_id, req->cancellable);
meta_play_request_free (req);
}

View File

@ -1992,7 +1992,7 @@ gboolean
meta_prefs_remove_keybinding (const char *name)
{
MetaKeyPref *pref;
guint id;
gulong id;
pref = g_hash_table_lookup (key_bindings, name);
if (!pref)
@ -2008,7 +2008,7 @@ meta_prefs_remove_keybinding (const char *name)
}
id = GPOINTER_TO_UINT (g_object_steal_data (G_OBJECT (pref->settings), name));
g_signal_handler_disconnect (pref->settings, id);
g_clear_signal_handler (&id, pref->settings);
g_hash_table_remove (key_bindings, name);