GSettings big endian tweaks

GSettings relies on parts of the schema infromation remaining
unbyteswapped (the strinfo database, for example) while requiring other
parts to be in native order (the default value, constraints, etc.).

Lift the byteswapping into a place where we can do it selectively.
This commit is contained in:
Ryan Lortie 2010-10-03 23:04:00 -04:00
parent 73ca8b4754
commit c84441fbb3
2 changed files with 16 additions and 11 deletions

View File

@ -813,6 +813,18 @@ typedef struct
GVariant *default_value; GVariant *default_value;
} GSettingsKeyInfo; } GSettingsKeyInfo;
static inline void
endian_fixup (GVariant **value)
{
#if G_BYTE_ORDER == G_BIG_ENDIAN
GVariant *tmp;
tmp = g_variant_byteswap (*value);
g_variant_unref (*value);
*value = tmp;
#endif
}
static void static void
g_settings_get_key_info (GSettingsKeyInfo *info, g_settings_get_key_info (GSettingsKeyInfo *info,
GSettings *settings, GSettings *settings,
@ -827,6 +839,7 @@ g_settings_get_key_info (GSettingsKeyInfo *info,
iter = g_settings_schema_get_value (settings->priv->schema, key); iter = g_settings_schema_get_value (settings->priv->schema, key);
info->default_value = g_variant_iter_next_value (iter); info->default_value = g_variant_iter_next_value (iter);
endian_fixup (&info->default_value);
info->type = g_variant_get_type (info->default_value); info->type = g_variant_get_type (info->default_value);
info->settings = g_object_ref (settings); info->settings = g_object_ref (settings);
info->key = g_intern_string (key); info->key = g_intern_string (key);
@ -859,6 +872,8 @@ g_settings_get_key_info (GSettingsKeyInfo *info,
case 'r': case 'r':
g_variant_get (data, "(**)", &info->minimum, &info->maximum); g_variant_get (data, "(**)", &info->minimum, &info->maximum);
endian_fixup (&info->minimum);
endian_fixup (&info->maximum);
break; break;
default: default:

View File

@ -249,7 +249,7 @@ g_settings_schema_get_string (GSettingsSchema *schema,
const gchar *result = NULL; const gchar *result = NULL;
GVariant *value; GVariant *value;
if ((value = gvdb_table_get_value (schema->priv->table, key))) if ((value = gvdb_table_get_raw_value (schema->priv->table, key)))
{ {
result = g_variant_get_string (value, NULL); result = g_variant_get_string (value, NULL);
g_variant_unref (value); g_variant_unref (value);
@ -304,16 +304,6 @@ g_settings_schema_get_value (GSettingsSchema *schema,
if G_UNLIKELY (value == NULL) if G_UNLIKELY (value == NULL)
g_error ("schema does not contain a key named '%s'", key); g_error ("schema does not contain a key named '%s'", key);
#if G_BYTE_ORDER == G_BIG_ENDIAN
{
GVariant *tmp;
tmp = g_variant_byteswap (value);
g_variant_unref (value);
value = tmp;
}
#endif
iter = g_variant_iter_new (value); iter = g_variant_iter_new (value);
g_variant_unref (value); g_variant_unref (value);