[glib: 4/6] gsettings: Clarify that g_settings_get_child() inherits delay-apply
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 4/6] gsettings: Clarify that g_settings_get_child() inherits delay-apply
- Date: Wed, 3 Nov 2021 18:03:22 +0000 (UTC)
commit 0101ccba16419ab20ebfc2cbd5aa91924494f890
Author: Philip Withnall <pwithnall endlessos org>
Date: Tue Oct 26 14:10:19 2021 +0100
gsettings: Clarify that g_settings_get_child() inherits delay-apply
Previously, the delay-apply status of the parent `GSettings` object
would be partially inherited: `settings->priv->backend` in the child
`GSettings` object would point to a `GDelayedSettingsBackend`, but
`settings->priv->delayed` would be `NULL`.
The expectation from https://bugzilla.gnome.org/show_bug.cgi?id=720891
was that `get_child()` would fully inherit delay-apply status.
So, ensure that `settings->priv->delayed` is correctly set to point to
the delayed backend when constructing any `GSettings`. Update the tests
to work again (presumably the inverted test was an oversight in the
original changes).
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Fixes: #2426
gio/gsettings.c | 16 +++++++++++++++-
gio/tests/gsettings.c | 7 ++++++-
2 files changed, 21 insertions(+), 2 deletions(-)
---
diff --git a/gio/gsettings.c b/gio/gsettings.c
index 5ebac1170..711929cff 100644
--- a/gio/gsettings.c
+++ b/gio/gsettings.c
@@ -604,6 +604,11 @@ g_settings_set_property (GObject *object,
case PROP_BACKEND:
settings->priv->backend = g_value_dup_object (value);
+ if (G_IS_DELAYED_SETTINGS_BACKEND (settings->priv->backend))
+ {
+ g_assert (settings->priv->delayed == NULL);
+ settings->priv->delayed = G_DELAYED_SETTINGS_BACKEND (settings->priv->backend);
+ }
break;
default:
@@ -680,7 +685,13 @@ g_settings_constructed (GObject *object)
}
if (settings->priv->backend == NULL)
- settings->priv->backend = g_settings_backend_get_default ();
+ {
+ settings->priv->backend = g_settings_backend_get_default ();
+
+ /* The default had better not be delayed, otherwise we also need to set
+ * settings->priv->delayed. */
+ g_assert (!G_IS_DELAYED_SETTINGS_BACKEND (settings->priv->backend));
+ }
g_settings_backend_watch (settings->priv->backend,
&listener_vtable, G_OBJECT (settings),
@@ -2426,6 +2437,9 @@ g_settings_is_writable (GSettings *settings,
* The schema for the child settings object must have been declared
* in the schema of @settings using a `<child>` element.
*
+ * The created child settings object will inherit the #GSettings:delay-apply
+ * mode from @settings.
+ *
* Returns: (not nullable) (transfer full): a 'child' settings object
*
* Since: 2.26
diff --git a/gio/tests/gsettings.c b/gio/tests/gsettings.c
index 0b19f2a67..dad1623b7 100644
--- a/gio/tests/gsettings.c
+++ b/gio/tests/gsettings.c
@@ -619,7 +619,7 @@ test_delay_child (void)
g_assert_nonnull (child);
g_object_get (child, "delay-apply", &delay, NULL);
- g_assert_false (delay);
+ g_assert_true (delay);
g_settings_get (child, "test-byte", "y", &byte);
g_assert_cmpuint (byte, ==, 36);
@@ -630,6 +630,11 @@ test_delay_child (void)
g_settings_get (base, "test-byte", "y", &byte);
g_assert_cmpuint (byte, ==, 36);
+ /* apply the child and the changes should be saved */
+ g_settings_apply (child);
+ g_settings_get (base, "test-byte", "y", &byte);
+ g_assert_cmpuint (byte, ==, 42);
+
g_object_unref (child);
g_object_unref (settings);
g_object_unref (base);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]