From 5aa42683eebeee6ab8dfdb612d1b39df4176225d Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 13 Feb 2025 18:56:04 +0000 Subject: [PATCH 1/4] gfilemonitor: Use an enum for properties to allow -Wswitch-enum MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This lets the compiler tell us if we’ve accidentally missed a property implementation from `get_property()` or `set_property()`. Signed-off-by: Philip Withnall --- gio/gfilemonitor.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gio/gfilemonitor.c b/gio/gfilemonitor.c index f78fad2e9..ebb9e6fdb 100644 --- a/gio/gfilemonitor.c +++ b/gio/gfilemonitor.c @@ -64,12 +64,11 @@ struct _GFileMonitorPrivate G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GFileMonitor, g_file_monitor, G_TYPE_OBJECT) -enum +typedef enum { - PROP_0, - PROP_RATE_LIMIT, + PROP_RATE_LIMIT = 1, PROP_CANCELLED -}; +} GFileMonitorProperty; static guint g_file_monitor_changed_signal; @@ -79,16 +78,17 @@ g_file_monitor_set_property (GObject *object, const GValue *value, GParamSpec *pspec) { - //GFileMonitor *monitor; - - //monitor = G_FILE_MONITOR (object); - - switch (prop_id) + switch ((GFileMonitorProperty) prop_id) { case PROP_RATE_LIMIT: /* not supported by default */ break; + case PROP_CANCELLED: + /* Read only */ + g_assert_not_reached (); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -101,7 +101,7 @@ g_file_monitor_get_property (GObject *object, GValue *value, GParamSpec *pspec) { - switch (prop_id) + switch ((GFileMonitorProperty) prop_id) { case PROP_RATE_LIMIT: /* we expect this to be overridden... */ From 8ffdbb55d99ffe0f05dcfd27fe6163f894cd8266 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 13 Feb 2025 18:57:04 +0000 Subject: [PATCH 2/4] gfilemonitor: Install properties all at once This is a minor performance improvement, since the pspec list for the class now only has to be modified once, rather than twice. It also means we now have the `GParamSpec` pointers to hand in a `props` array, which will be used in the upcoming commits. Signed-off-by: Philip Withnall --- gio/gfilemonitor.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/gio/gfilemonitor.c b/gio/gfilemonitor.c index ebb9e6fdb..e3028935b 100644 --- a/gio/gfilemonitor.c +++ b/gio/gfilemonitor.c @@ -70,6 +70,7 @@ typedef enum PROP_CANCELLED } GFileMonitorProperty; +static GParamSpec *props[PROP_CANCELLED + 1]; static guint g_file_monitor_changed_signal; static void @@ -200,19 +201,21 @@ g_file_monitor_class_init (GFileMonitorClass *klass) * * The limit of the monitor to watch for changes, in milliseconds. */ - g_object_class_install_property (object_class, PROP_RATE_LIMIT, - g_param_spec_int ("rate-limit", NULL, NULL, - 0, G_MAXINT, DEFAULT_RATE_LIMIT_MSECS, G_PARAM_READWRITE | - G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); + props[PROP_RATE_LIMIT] = + g_param_spec_int ("rate-limit", NULL, NULL, + 0, G_MAXINT, DEFAULT_RATE_LIMIT_MSECS, G_PARAM_READWRITE | + G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); /** * GFileMonitor:cancelled: * * Whether the monitor has been cancelled. */ - g_object_class_install_property (object_class, PROP_CANCELLED, - g_param_spec_boolean ("cancelled", NULL, NULL, - FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + props[PROP_CANCELLED] = + g_param_spec_boolean ("cancelled", NULL, NULL, + FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, G_N_ELEMENTS (props), props); } /** From 06077435c98ecffc8a10a5b770f4e63a0c58c8b8 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 13 Feb 2025 18:57:58 +0000 Subject: [PATCH 3/4] gfilemonitor: Emit GObject::notify by pspec rather than property name This is equivalent, but slightly faster, as it avoids a pspec lookup. Signed-off-by: Philip Withnall --- gio/gfilemonitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gio/gfilemonitor.c b/gio/gfilemonitor.c index e3028935b..5ba244e89 100644 --- a/gio/gfilemonitor.c +++ b/gio/gfilemonitor.c @@ -254,7 +254,7 @@ g_file_monitor_cancel (GFileMonitor *monitor) G_FILE_MONITOR_GET_CLASS (monitor)->cancel (monitor); g_atomic_int_set (&monitor->priv->cancelled, CANCEL_STATE_CANCELLED); - g_object_notify (G_OBJECT (monitor), "cancelled"); + g_object_notify_by_pspec (G_OBJECT (monitor), props[PROP_CANCELLED]); } return TRUE; From f2878327f40fff3721ab41a3244efab3905c129d Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 13 Feb 2025 18:58:30 +0000 Subject: [PATCH 4/4] gfilemonitor: Fix value of `GFileMonitor:cancelled` via `g_object_get_property()` It was hard-coded to return `FALSE` for some reason. Fix that. Signed-off-by: Philip Withnall --- gio/gfilemonitor.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gio/gfilemonitor.c b/gio/gfilemonitor.c index 5ba244e89..50d159bf6 100644 --- a/gio/gfilemonitor.c +++ b/gio/gfilemonitor.c @@ -102,6 +102,8 @@ g_file_monitor_get_property (GObject *object, GValue *value, GParamSpec *pspec) { + GFileMonitor *self = G_FILE_MONITOR (object); + switch ((GFileMonitorProperty) prop_id) { case PROP_RATE_LIMIT: @@ -110,9 +112,7 @@ g_file_monitor_get_property (GObject *object, break; case PROP_CANCELLED: - //g_mutex_lock (&fms->lock); - g_value_set_boolean (value, FALSE);//fms->cancelled); - //g_mutex_unlock (&fms->lock); + g_value_set_boolean (value, g_file_monitor_is_cancelled (self)); break; default: