GSettings big endian tweaks
authorRyan Lortie <desrt@desrt.ca>
Mon, 4 Oct 2010 03:04:00 +0000 (23:04 -0400)
committerRyan Lortie <desrt@desrt.ca>
Mon, 4 Oct 2010 03:04:00 +0000 (23:04 -0400)
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.

gio/gsettings.c
gio/gsettingsschema.c

index 31361c1..34a69ce 100644 (file)
@@ -813,6 +813,18 @@ typedef struct
   GVariant *default_value;
 } 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
 g_settings_get_key_info (GSettingsKeyInfo *info,
                          GSettings        *settings,
@@ -827,6 +839,7 @@ g_settings_get_key_info (GSettingsKeyInfo *info,
   iter = g_settings_schema_get_value (settings->priv->schema, key);
 
   info->default_value = g_variant_iter_next_value (iter);
+  endian_fixup (&info->default_value);
   info->type = g_variant_get_type (info->default_value);
   info->settings = g_object_ref (settings);
   info->key = g_intern_string (key);
@@ -859,6 +872,8 @@ g_settings_get_key_info (GSettingsKeyInfo *info,
 
         case 'r':
           g_variant_get (data, "(**)", &info->minimum, &info->maximum);
+          endian_fixup (&info->minimum);
+          endian_fixup (&info->maximum);
           break;
 
         default:
index 187956e..9ffa6ed 100644 (file)
@@ -249,7 +249,7 @@ g_settings_schema_get_string (GSettingsSchema *schema,
   const gchar *result = NULL;
   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);
       g_variant_unref (value);
@@ -304,16 +304,6 @@ g_settings_schema_get_value (GSettingsSchema *schema,
   if G_UNLIKELY (value == NULL)
     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);
   g_variant_unref (value);