mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-27 17:52:58 +02:00
GSettings: make _sync() a no-op if uninitialised
If GSettings is uninitialised then g_settings_sync() should very obviously just return right away (rather than attempting to initialise GSettings first).
This commit is contained in:
@@ -45,6 +45,13 @@ struct _GSettingsBackendPrivate
|
|||||||
GStaticMutex lock;
|
GStaticMutex lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* For g_settings_backend_sync_default(), we only want to actually do
|
||||||
|
* the sync if the backend already exists. This avoids us creating an
|
||||||
|
* entire GSettingsBackend in order to call a do-nothing sync()
|
||||||
|
* operation on it. This variable lets us avoid that.
|
||||||
|
*/
|
||||||
|
static gboolean g_settings_has_backend;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SECTION:gsettingsbackend
|
* SECTION:gsettingsbackend
|
||||||
* @title: GSettingsBackend
|
* @title: GSettingsBackend
|
||||||
@@ -982,6 +989,7 @@ g_settings_backend_get_default (void)
|
|||||||
|
|
||||||
extension_type = g_io_extension_get_type (extension);
|
extension_type = g_io_extension_get_type (extension);
|
||||||
instance = g_object_new (extension_type, NULL);
|
instance = g_object_new (extension_type, NULL);
|
||||||
|
g_settings_has_backend = TRUE;
|
||||||
|
|
||||||
g_once_init_leave (&backend, (gsize) instance);
|
g_once_init_leave (&backend, (gsize) instance);
|
||||||
}
|
}
|
||||||
@@ -1021,12 +1029,15 @@ g_settings_backend_get_permission (GSettingsBackend *backend,
|
|||||||
void
|
void
|
||||||
g_settings_backend_sync_default (void)
|
g_settings_backend_sync_default (void)
|
||||||
{
|
{
|
||||||
GSettingsBackendClass *class;
|
if (g_settings_has_backend)
|
||||||
GSettingsBackend *backend;
|
{
|
||||||
|
GSettingsBackendClass *class;
|
||||||
|
GSettingsBackend *backend;
|
||||||
|
|
||||||
backend = g_settings_backend_get_default ();
|
backend = g_settings_backend_get_default ();
|
||||||
class = G_SETTINGS_BACKEND_GET_CLASS (backend);
|
class = G_SETTINGS_BACKEND_GET_CLASS (backend);
|
||||||
|
|
||||||
if (class->sync)
|
if (class->sync)
|
||||||
class->sync (backend);
|
class->sync (backend);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user