1From 7045260c226e409530e4f961f613f8c7d6f6725a Mon Sep 17 00:00:00 2001 2From: Simon McVittie <smcv@collabora.com> 3Date: Thu, 23 Jun 2022 09:41:21 +0100 4Subject: [PATCH] gsignal: Add G_CONNECT_DEFAULT 5 6This makes calls to g_signal_connect_data() and g_signal_connect_object() 7with default flags more self-documenting. 8 9Signed-off-by: Simon McVittie <smcv@collabora.com> 10 11Conflict:NA 12Reference:https://gitlab.gnome.org/GNOME/glib/-/commit/7045260c226e409530e4f961f613f8c7d6f6725a 13 14--- 15 gio/gcancellable.c | 2 +- 16 gio/gdbusobjectmanagerclient.c | 4 ++-- 17 gio/gdbusserver.c | 2 +- 18 gio/glocalfilemonitor.c | 5 +++-- 19 gio/gsubprocess.c | 4 +++- 20 gio/gtask.c | 3 ++- 21 gobject/gobject.c | 8 ++++---- 22 gobject/gsignal.h | 11 ++++++++--- 23 gobject/tests/signals.c | 6 ++++-- 24 9 files changed, 28 insertions(+), 17 deletions(-) 25 26diff --git a/gio/gcancellable.c b/gio/gcancellable.c 27index 64755206be..fe3cbeb7f7 100644 28--- a/gio/gcancellable.c 29+++ b/gio/gcancellable.c 30@@ -589,7 +589,7 @@ g_cancellable_connect (GCancellable *cancellable, 31 id = g_signal_connect_data (cancellable, "cancelled", 32 callback, data, 33 (GClosureNotify) data_destroy_func, 34- 0); 35+ G_CONNECT_DEFAULT); 36 37 g_mutex_unlock (&cancellable_mutex); 38 } 39diff --git a/gio/gdbusobjectmanagerclient.c b/gio/gdbusobjectmanagerclient.c 40index bfb73b5308..fa5e73041e 100644 41--- a/gio/gdbusobjectmanagerclient.c 42+++ b/gio/gdbusobjectmanagerclient.c 43@@ -1456,7 +1456,7 @@ initable_init (GInitable *initable, 44 G_CALLBACK (on_notify_g_name_owner), 45 weak_ref_new (G_OBJECT (manager)), 46 (GClosureNotify) weak_ref_free, 47- 0 /* flags */); 48+ G_CONNECT_DEFAULT); 49 50 manager->priv->signal_signal_id = 51 g_signal_connect_data (manager->priv->control_proxy, 52@@ -1464,7 +1464,7 @@ initable_init (GInitable *initable, 53 G_CALLBACK (on_control_proxy_g_signal), 54 weak_ref_new (G_OBJECT (manager)), 55 (GClosureNotify) weak_ref_free, 56- 0 /* flags */); 57+ G_CONNECT_DEFAULT); 58 59 manager->priv->name_owner = g_dbus_proxy_get_name_owner (manager->priv->control_proxy); 60 if (manager->priv->name_owner == NULL && manager->priv->name != NULL) 61diff --git a/gio/gdbusserver.c b/gio/gdbusserver.c 62index fe5b23ed4d..f144d129ae 100644 63--- a/gio/gdbusserver.c 64+++ b/gio/gdbusserver.c 65@@ -630,7 +630,7 @@ g_dbus_server_start (GDBusServer *server) 66 G_CALLBACK (on_run), 67 g_object_ref (server), 68 (GClosureNotify) g_object_unref, 69- 0 /* flags */); 70+ G_CONNECT_DEFAULT); 71 g_socket_service_start (G_SOCKET_SERVICE (server->listener)); 72 server->active = TRUE; 73 g_object_notify (G_OBJECT (server), "active"); 74diff --git a/gio/glocalfilemonitor.c b/gio/glocalfilemonitor.c 75index fde52193a9..8de4079394 100644 76--- a/gio/glocalfilemonitor.c 77+++ b/gio/glocalfilemonitor.c 78@@ -809,7 +809,8 @@ g_local_file_monitor_start (GLocalFileMonitor *local_monitor, 79 80 local_monitor->mount_monitor = g_unix_mount_monitor_get (); 81 g_signal_connect_object (local_monitor->mount_monitor, "mounts-changed", 82- G_CALLBACK (g_local_file_monitor_mounts_changed), local_monitor, 0); 83+ G_CALLBACK (g_local_file_monitor_mounts_changed), local_monitor, 84+ G_CONNECT_DEFAULT); 85 #endif 86 } 87 88@@ -924,7 +925,7 @@ g_local_file_monitor_new_in_worker (const gchar *pathname, 89 { 90 if (callback) 91 g_signal_connect_data (monitor, "changed", G_CALLBACK (callback), 92- user_data, destroy_user_data, 0 /* flags */); 93+ user_data, destroy_user_data, G_CONNECT_DEFAULT); 94 95 g_local_file_monitor_start (monitor, pathname, is_directory, flags, GLIB_PRIVATE_CALL(g_get_worker_context) ()); 96 } 97diff --git a/gio/gsubprocess.c b/gio/gsubprocess.c 98index bb157197fc..c4747a1481 100644 99--- a/gio/gsubprocess.c 100+++ b/gio/gsubprocess.c 101@@ -756,7 +756,9 @@ g_subprocess_wait_async (GSubprocess *subprocess, 102 * see the cancellation in the _finish(). 103 */ 104 if (cancellable) 105- g_signal_connect_object (cancellable, "cancelled", G_CALLBACK (g_subprocess_wait_cancelled), task, 0); 106+ g_signal_connect_object (cancellable, "cancelled", 107+ G_CALLBACK (g_subprocess_wait_cancelled), 108+ task, G_CONNECT_DEFAULT); 109 110 subprocess->pending_waits = g_slist_prepend (subprocess->pending_waits, task); 111 task = NULL; 112diff --git a/gio/gtask.c b/gio/gtask.c 113index d0f8b4e33a..774cba793a 100644 114--- a/gio/gtask.c 115+++ b/gio/gtask.c 116@@ -1530,7 +1530,8 @@ g_task_start_task_thread (GTask *task, 117 g_signal_connect_data (task->cancellable, "cancelled", 118 G_CALLBACK (task_thread_cancelled), 119 g_object_ref (task), 120- task_thread_cancelled_disconnect_notify, 0); 121+ task_thread_cancelled_disconnect_notify, 122+ G_CONNECT_DEFAULT); 123 } 124 125 if (g_private_get (&task_private)) 126diff --git a/gobject/gobject.c b/gobject/gobject.c 127index df908984b7..5ba8fd017b 100644 128--- a/gobject/gobject.c 129+++ b/gobject/gobject.c 130@@ -3093,8 +3093,8 @@ g_object_get_property (GObject *object, 131 * 132 * The signal specs expected by this function have the form 133 * "modifier::signal_name", where modifier can be one of the following: 134- * - signal: equivalent to g_signal_connect_data (..., NULL, 0) 135- * - object-signal, object_signal: equivalent to g_signal_connect_object (..., 0) 136+ * - signal: equivalent to g_signal_connect_data (..., NULL, G_CONNECT_DEFAULT) 137+ * - object-signal, object_signal: equivalent to g_signal_connect_object (..., G_CONNECT_DEFAULT) 138 * - swapped-signal, swapped_signal: equivalent to g_signal_connect_data (..., NULL, G_CONNECT_SWAPPED) 139 * - swapped_object_signal, swapped-object-signal: equivalent to g_signal_connect_object (..., G_CONNECT_SWAPPED) 140 * - signal_after, signal-after: equivalent to g_signal_connect_data (..., NULL, G_CONNECT_AFTER) 141@@ -3135,12 +3135,12 @@ g_object_connect (gpointer _object, 142 if (strncmp (signal_spec, "signal::", 8) == 0) 143 g_signal_connect_data (object, signal_spec + 8, 144 callback, data, NULL, 145- 0); 146+ G_CONNECT_DEFAULT); 147 else if (strncmp (signal_spec, "object_signal::", 15) == 0 || 148 strncmp (signal_spec, "object-signal::", 15) == 0) 149 g_signal_connect_object (object, signal_spec + 15, 150 callback, data, 151- 0); 152+ G_CONNECT_DEFAULT); 153 else if (strncmp (signal_spec, "swapped_signal::", 16) == 0 || 154 strncmp (signal_spec, "swapped-signal::", 16) == 0) 155 g_signal_connect_data (object, signal_spec + 16, 156diff --git a/gobject/gsignal.h b/gobject/gsignal.h 157index 7b3974a8c4..53da2a6eab 100644 158--- a/gobject/gsignal.h 159+++ b/gobject/gsignal.h 160@@ -155,9 +155,11 @@ typedef enum 161 #define G_SIGNAL_FLAGS_MASK 0x1ff 162 /** 163 * GConnectFlags: 164- * @G_CONNECT_AFTER: whether the handler should be called before or after the 165- * default handler of the signal. 166- * @G_CONNECT_SWAPPED: whether the instance and data should be swapped when 167+ * @G_CONNECT_DEFAULT: Default behaviour (no special flags). Since: 2.74 168+ * @G_CONNECT_AFTER: If set, the handler should be called after the 169+ * default handler of the signal. Normally, the handler is called before 170+ * the default handler. 171+ * @G_CONNECT_SWAPPED: If set, the instance and data should be swapped when 172 * calling the handler; see g_signal_connect_swapped() for an example. 173 * 174 * The connection flags are used to specify the behaviour of a signal's 175@@ -165,6 +167,7 @@ typedef enum 176 */ 177 typedef enum 178 { 179+ G_CONNECT_DEFAULT GLIB_AVAILABLE_ENUMERATOR_IN_2_74 = 0, 180 G_CONNECT_AFTER = 1 << 0, 181 G_CONNECT_SWAPPED = 1 << 1 182 } GConnectFlags; 183@@ -504,6 +507,8 @@ void g_signal_chain_from_overridden_handler (gpointer instance, 184 * 185 * Returns: the handler ID, of type #gulong (always greater than 0 for successful connections) 186 */ 187+/* Intentionally not using G_CONNECT_DEFAULT here to avoid deprecation 188+ * warnings with older GLIB_VERSION_MAX_ALLOWED */ 189 #define g_signal_connect(instance, detailed_signal, c_handler, data) \ 190 g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, (GConnectFlags) 0) 191 /** 192diff --git a/gobject/tests/signals.c b/gobject/tests/signals.c 193index ea9a778bf8..e4be41575f 100644 194--- a/gobject/tests/signals.c 195+++ b/gobject/tests/signals.c 196@@ -1109,8 +1109,10 @@ test_destroy_target_object (void) 197 sender = g_object_new (test_get_type (), NULL); 198 target1 = g_object_new (test_get_type (), NULL); 199 target2 = g_object_new (test_get_type (), NULL); 200- g_signal_connect_object (sender, "simple", G_CALLBACK (simple_handler1), target1, 0); 201- g_signal_connect_object (sender, "simple", G_CALLBACK (simple_handler2), target2, 0); 202+ g_signal_connect_object (sender, "simple", G_CALLBACK (simple_handler1), 203+ target1, G_CONNECT_DEFAULT); 204+ g_signal_connect_object (sender, "simple", G_CALLBACK (simple_handler2), 205+ target2, G_CONNECT_DEFAULT); 206 g_signal_emit_by_name (sender, "simple"); 207 g_object_unref (sender); 208 } 209-- 210GitLab 211 212