Revert "GSettings: don't abort on missing schemas"

This reverts commit c841c2ce3fda6f754c88ae2c9099f36dff2f0814.

This approach has been an unmitigated disaster.  We're getting all sorts
of crashes due to functions that are returning NULL because they can't
find the schema for the default value.  The people who get these crashes
are then confused about the root cause of the problem and waste a lot of
time trying to figure it out.

Until we find a better solution, we should go back to what we had
before.

https://bugzilla.gnome.org/show_bug.cgi?id=655366
This commit is contained in:
Ryan Lortie 2011-10-03 10:19:14 -04:00
parent 9d989c7b8a
commit 3106391694
3 changed files with 17 additions and 91 deletions

View File

@ -498,28 +498,18 @@ g_settings_constructed (GObject *object)
const gchar *schema_path;
settings->priv->schema = g_settings_schema_new (settings->priv->schema_name);
if (settings->priv->schema == NULL)
goto broken;
schema_path = g_settings_schema_get_path (settings->priv->schema);
if (settings->priv->path && schema_path && strcmp (settings->priv->path, schema_path) != 0)
{
g_critical ("settings object created with schema '%s' and path '%s', but "
"path '%s' is specified by schema",
settings->priv->schema_name, settings->priv->path, schema_path);
goto broken;
}
g_error ("settings object created with schema '%s' and path '%s', but "
"path '%s' is specified by schema",
settings->priv->schema_name, settings->priv->path, schema_path);
if (settings->priv->path == NULL)
{
if (schema_path == NULL)
{
g_critical ("attempting to create schema '%s' without a path",
settings->priv->schema_name);
goto broken;
}
g_error ("attempting to create schema '%s' without a path",
settings->priv->schema_name);
settings->priv->path = g_strdup (schema_path);
}
@ -532,19 +522,6 @@ g_settings_constructed (GObject *object)
settings->priv->main_context);
g_settings_backend_subscribe (settings->priv->backend,
settings->priv->path);
return;
broken:
if (settings->priv->schema != NULL)
g_object_unref (settings->priv->schema);
settings->priv->schema = NULL;
g_free (settings->priv->path);
settings->priv->path = NULL;
if (settings->priv->backend != NULL)
g_object_unref (settings->priv->backend);
settings->priv->backend = NULL;
}
static void
@ -916,7 +893,7 @@ endian_fixup (GVariant **value)
#endif
}
static gboolean
static void
g_settings_get_key_info (GSettingsKeyInfo *info,
GSettings *settings,
const gchar *key)
@ -925,8 +902,6 @@ g_settings_get_key_info (GSettingsKeyInfo *info,
GVariant *data;
guchar code;
g_return_val_if_fail (settings->priv->schema != NULL, FALSE);
memset (info, 0, sizeof *info);
iter = g_settings_schema_get_value (settings->priv->schema, key);
@ -978,8 +953,6 @@ g_settings_get_key_info (GSettingsKeyInfo *info,
}
g_variant_iter_free (iter);
return TRUE;
}
static void
@ -1287,9 +1260,7 @@ g_settings_get_value (GSettings *settings,
g_return_val_if_fail (G_IS_SETTINGS (settings), NULL);
g_return_val_if_fail (key != NULL, NULL);
if (!g_settings_get_key_info (&info, settings, key))
return NULL;
g_settings_get_key_info (&info, settings, key);
value = g_settings_read_from_backend (&info);
if (value == NULL)
@ -1335,8 +1306,7 @@ g_settings_get_enum (GSettings *settings,
g_return_val_if_fail (G_IS_SETTINGS (settings), -1);
g_return_val_if_fail (key != NULL, -1);
if (!g_settings_get_key_info (&info, settings, key))
return 0;
g_settings_get_key_info (&info, settings, key);
if (!info.is_enum)
{
@ -1391,8 +1361,7 @@ g_settings_set_enum (GSettings *settings,
g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
g_return_val_if_fail (key != NULL, FALSE);
if (!g_settings_get_key_info (&info, settings, key))
return FALSE;
g_settings_get_key_info (&info, settings, key);
if (!info.is_enum)
{
@ -1448,8 +1417,7 @@ g_settings_get_flags (GSettings *settings,
g_return_val_if_fail (G_IS_SETTINGS (settings), -1);
g_return_val_if_fail (key != NULL, -1);
if (!g_settings_get_key_info (&info, settings, key))
return 0;
g_settings_get_key_info (&info, settings, key);
if (!info.is_flags)
{
@ -1505,8 +1473,7 @@ g_settings_set_flags (GSettings *settings,
g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
g_return_val_if_fail (key != NULL, FALSE);
if (!g_settings_get_key_info (&info, settings, key))
return FALSE;
g_settings_get_key_info (&info, settings, key);
if (!info.is_flags)
{
@ -1558,8 +1525,7 @@ g_settings_set_value (GSettings *settings,
g_return_val_if_fail (G_IS_SETTINGS (settings), FALSE);
g_return_val_if_fail (key != NULL, FALSE);
if (!g_settings_get_key_info (&info, settings, key))
return FALSE;
g_settings_get_key_info (&info, settings, key);
if (!g_settings_type_check (&info, value))
{
@ -1711,8 +1677,7 @@ g_settings_get_mapped (GSettings *settings,
g_return_val_if_fail (key != NULL, NULL);
g_return_val_if_fail (mapping != NULL, NULL);
if (!g_settings_get_key_info (&info, settings, key))
return FALSE;
g_settings_get_key_info (&info, settings, key);
if ((value = g_settings_read_from_backend (&info)))
{
@ -2437,8 +2402,7 @@ g_settings_get_range (GSettings *settings,
const gchar *type;
GVariant *range;
if (!g_settings_get_key_info (&info, settings, key))
return NULL;
g_settings_get_key_info (&info, settings, key);
if (info.minimum)
{
@ -2488,9 +2452,7 @@ g_settings_range_check (GSettings *settings,
GSettingsKeyInfo info;
gboolean good;
if (!g_settings_get_key_info (&info, settings, key))
return FALSE;
g_settings_get_key_info (&info, settings, key);
good = g_settings_type_check (&info, value) &&
g_settings_key_info_range_check (&info, value);
g_settings_free_key_info (&info);
@ -2795,14 +2757,7 @@ g_settings_bind_with_mapping (GSettings *settings,
objectclass = G_OBJECT_GET_CLASS (object);
binding = g_slice_new0 (GSettingsBinding);
if (!g_settings_get_key_info (&binding->info, settings, key))
{
if (destroy)
(* destroy) (user_data);
g_slice_free (GSettingsBinding, binding);
return;
}
g_settings_get_key_info (&binding->info, settings, key);
binding->object = object;
binding->property = g_object_class_find_property (objectclass, property);
binding->user_data = user_data;

View File

@ -280,10 +280,7 @@ g_settings_schema_new (const gchar *name)
}
if (table == NULL)
{
g_critical ("Settings schema '%s' is not installed\n", name);
return NULL;
}
g_error ("Settings schema '%s' is not installed\n", name);
schema = g_object_new (G_TYPE_SETTINGS_SCHEMA, NULL);
schema->priv->name = g_strdup (name);

View File

@ -1887,31 +1887,6 @@ test_get_range (void)
g_object_unref (settings);
}
static gboolean
ignore_criticals (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer user_data)
{
return (log_level & G_LOG_LEVEL_MASK) != G_LOG_LEVEL_CRITICAL;
}
static void
test_missing_schema (void)
{
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
{
GSettings *settings;
g_test_log_set_fatal_handler (ignore_criticals, NULL);
settings = g_settings_new ("schema.does.not.exist");
g_settings_get_value (settings, "some-key");
g_error ("i'm doing science and i'm still alive");
}
g_test_trap_assert_failed ();
g_test_trap_assert_stderr ("*still alive*");
}
int
main (int argc, char *argv[])
{
@ -1996,7 +1971,6 @@ main (int argc, char *argv[])
g_test_add_func ("/gsettings/list-schemas", test_list_schemas);
g_test_add_func ("/gsettings/mapped", test_get_mapped);
g_test_add_func ("/gsettings/get-range", test_get_range);
g_test_add_func ("/gsettings/missing-schema", test_missing_schema);
result = g_test_run ();