[glib: 3/3] GSettings big endian tweaks



commit c84441fbb3b2eb14775e8467a07cda4eff4502e1
Author: Ryan Lortie <desrt desrt ca>
Date:   Sun Oct 3 23:04:00 2010 -0400

    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.

 gio/gsettings.c       |   15 +++++++++++++++
 gio/gsettingsschema.c |   12 +-----------
 2 files changed, 16 insertions(+), 11 deletions(-)
---
diff --git a/gio/gsettings.c b/gio/gsettings.c
index 31361c1..34a69ce 100644
--- a/gio/gsettings.c
+++ b/gio/gsettings.c
@@ -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:
diff --git a/gio/gsettingsschema.c b/gio/gsettingsschema.c
index 187956e..9ffa6ed 100644
--- a/gio/gsettingsschema.c
+++ b/gio/gsettingsschema.c
@@ -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);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]