gsignal: Add G_CONNECT_DEFAULT

This makes calls to g_signal_connect_data() and g_signal_connect_object()
with default flags more self-documenting.

Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
Simon McVittie 2022-06-23 09:41:21 +01:00
parent 5e164c6615
commit 7045260c22
9 changed files with 28 additions and 17 deletions

View File

@ -589,7 +589,7 @@ g_cancellable_connect (GCancellable *cancellable,
id = g_signal_connect_data (cancellable, "cancelled",
callback, data,
(GClosureNotify) data_destroy_func,
0);
G_CONNECT_DEFAULT);
g_mutex_unlock (&cancellable_mutex);
}

View File

@ -1456,7 +1456,7 @@ initable_init (GInitable *initable,
G_CALLBACK (on_notify_g_name_owner),
weak_ref_new (G_OBJECT (manager)),
(GClosureNotify) weak_ref_free,
0 /* flags */);
G_CONNECT_DEFAULT);
manager->priv->signal_signal_id =
g_signal_connect_data (manager->priv->control_proxy,
@ -1464,7 +1464,7 @@ initable_init (GInitable *initable,
G_CALLBACK (on_control_proxy_g_signal),
weak_ref_new (G_OBJECT (manager)),
(GClosureNotify) weak_ref_free,
0 /* flags */);
G_CONNECT_DEFAULT);
manager->priv->name_owner = g_dbus_proxy_get_name_owner (manager->priv->control_proxy);
if (manager->priv->name_owner == NULL && manager->priv->name != NULL)

View File

@ -630,7 +630,7 @@ g_dbus_server_start (GDBusServer *server)
G_CALLBACK (on_run),
g_object_ref (server),
(GClosureNotify) g_object_unref,
0 /* flags */);
G_CONNECT_DEFAULT);
g_socket_service_start (G_SOCKET_SERVICE (server->listener));
server->active = TRUE;
g_object_notify (G_OBJECT (server), "active");

View File

@ -809,7 +809,8 @@ g_local_file_monitor_start (GLocalFileMonitor *local_monitor,
local_monitor->mount_monitor = g_unix_mount_monitor_get ();
g_signal_connect_object (local_monitor->mount_monitor, "mounts-changed",
G_CALLBACK (g_local_file_monitor_mounts_changed), local_monitor, 0);
G_CALLBACK (g_local_file_monitor_mounts_changed), local_monitor,
G_CONNECT_DEFAULT);
#endif
}
@ -924,7 +925,7 @@ g_local_file_monitor_new_in_worker (const gchar *pathname,
{
if (callback)
g_signal_connect_data (monitor, "changed", G_CALLBACK (callback),
user_data, destroy_user_data, 0 /* flags */);
user_data, destroy_user_data, G_CONNECT_DEFAULT);
g_local_file_monitor_start (monitor, pathname, is_directory, flags, GLIB_PRIVATE_CALL(g_get_worker_context) ());
}

View File

@ -756,7 +756,9 @@ g_subprocess_wait_async (GSubprocess *subprocess,
* see the cancellation in the _finish().
*/
if (cancellable)
g_signal_connect_object (cancellable, "cancelled", G_CALLBACK (g_subprocess_wait_cancelled), task, 0);
g_signal_connect_object (cancellable, "cancelled",
G_CALLBACK (g_subprocess_wait_cancelled),
task, G_CONNECT_DEFAULT);
subprocess->pending_waits = g_slist_prepend (subprocess->pending_waits, task);
task = NULL;

View File

@ -1530,7 +1530,8 @@ g_task_start_task_thread (GTask *task,
g_signal_connect_data (task->cancellable, "cancelled",
G_CALLBACK (task_thread_cancelled),
g_object_ref (task),
task_thread_cancelled_disconnect_notify, 0);
task_thread_cancelled_disconnect_notify,
G_CONNECT_DEFAULT);
}
if (g_private_get (&task_private))

View File

@ -3093,8 +3093,8 @@ g_object_get_property (GObject *object,
*
* The signal specs expected by this function have the form
* "modifier::signal_name", where modifier can be one of the following:
* - signal: equivalent to g_signal_connect_data (..., NULL, 0)
* - object-signal, object_signal: equivalent to g_signal_connect_object (..., 0)
* - signal: equivalent to g_signal_connect_data (..., NULL, G_CONNECT_DEFAULT)
* - object-signal, object_signal: equivalent to g_signal_connect_object (..., G_CONNECT_DEFAULT)
* - swapped-signal, swapped_signal: equivalent to g_signal_connect_data (..., NULL, G_CONNECT_SWAPPED)
* - swapped_object_signal, swapped-object-signal: equivalent to g_signal_connect_object (..., G_CONNECT_SWAPPED)
* - signal_after, signal-after: equivalent to g_signal_connect_data (..., NULL, G_CONNECT_AFTER)
@ -3135,12 +3135,12 @@ g_object_connect (gpointer _object,
if (strncmp (signal_spec, "signal::", 8) == 0)
g_signal_connect_data (object, signal_spec + 8,
callback, data, NULL,
0);
G_CONNECT_DEFAULT);
else if (strncmp (signal_spec, "object_signal::", 15) == 0 ||
strncmp (signal_spec, "object-signal::", 15) == 0)
g_signal_connect_object (object, signal_spec + 15,
callback, data,
0);
G_CONNECT_DEFAULT);
else if (strncmp (signal_spec, "swapped_signal::", 16) == 0 ||
strncmp (signal_spec, "swapped-signal::", 16) == 0)
g_signal_connect_data (object, signal_spec + 16,

View File

@ -155,9 +155,11 @@ typedef enum
#define G_SIGNAL_FLAGS_MASK 0x1ff
/**
* GConnectFlags:
* @G_CONNECT_AFTER: whether the handler should be called before or after the
* default handler of the signal.
* @G_CONNECT_SWAPPED: whether the instance and data should be swapped when
* @G_CONNECT_DEFAULT: Default behaviour (no special flags). Since: 2.74
* @G_CONNECT_AFTER: If set, the handler should be called after the
* default handler of the signal. Normally, the handler is called before
* the default handler.
* @G_CONNECT_SWAPPED: If set, the instance and data should be swapped when
* calling the handler; see g_signal_connect_swapped() for an example.
*
* The connection flags are used to specify the behaviour of a signal's
@ -165,6 +167,7 @@ typedef enum
*/
typedef enum
{
G_CONNECT_DEFAULT GLIB_AVAILABLE_ENUMERATOR_IN_2_74 = 0,
G_CONNECT_AFTER = 1 << 0,
G_CONNECT_SWAPPED = 1 << 1
} GConnectFlags;
@ -504,6 +507,8 @@ void g_signal_chain_from_overridden_handler (gpointer instance,
*
* Returns: the handler ID, of type #gulong (always greater than 0 for successful connections)
*/
/* Intentionally not using G_CONNECT_DEFAULT here to avoid deprecation
* warnings with older GLIB_VERSION_MAX_ALLOWED */
#define g_signal_connect(instance, detailed_signal, c_handler, data) \
g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, (GConnectFlags) 0)
/**

View File

@ -1109,8 +1109,10 @@ test_destroy_target_object (void)
sender = g_object_new (test_get_type (), NULL);
target1 = g_object_new (test_get_type (), NULL);
target2 = g_object_new (test_get_type (), NULL);
g_signal_connect_object (sender, "simple", G_CALLBACK (simple_handler1), target1, 0);
g_signal_connect_object (sender, "simple", G_CALLBACK (simple_handler2), target2, 0);
g_signal_connect_object (sender, "simple", G_CALLBACK (simple_handler1),
target1, G_CONNECT_DEFAULT);
g_signal_connect_object (sender, "simple", G_CALLBACK (simple_handler2),
target2, G_CONNECT_DEFAULT);
g_signal_emit_by_name (sender, "simple");
g_object_unref (sender);
}