GSettings: fix check for delaying backend subscription
[platform/upstream/glib.git] / gio / gvdb / gvdb-builder.c
index 7cca13f..48fe3e4 100644 (file)
@@ -12,9 +12,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  *
  * Author: Ryan Lortie <desrt@desrt.ca>
  */
@@ -24,7 +22,9 @@
 
 #include <glib.h>
 #include <fcntl.h>
+#if !defined(G_OS_WIN32) || !defined(_MSC_VER)
 #include <unistd.h>
+#endif
 #include <string.h>
 
 
@@ -36,7 +36,6 @@ struct _GvdbItem
   GvdbItem *parent;
   GvdbItem *sibling;
   GvdbItem *next;
-  GVariant *options;
 
   /* one of:
    * this:
@@ -60,9 +59,6 @@ gvdb_item_free (gpointer data)
   if (item->value)
     g_variant_unref (item->value);
 
-  if (item->options)
-    g_variant_unref (item->options);
-
   if (item->table)
     g_hash_table_unref (item->table);
 
@@ -95,7 +91,7 @@ djb_hash (const gchar *key)
   guint32 hash_value = 5381;
 
   while (*key)
-    hash_value = hash_value * 33 + *key++;
+    hash_value = hash_value * 33 + *(signed char *)key++;
 
   return hash_value;
 }
@@ -136,15 +132,6 @@ gvdb_item_set_value (GvdbItem *item,
 }
 
 void
-gvdb_item_set_options (GvdbItem *item,
-                       GVariant *options)
-{
-  g_return_if_fail (!item->options);
-
-  item->options = g_variant_ref_sink (options);
-}
-
-void
 gvdb_item_set_hash_table (GvdbItem   *item,
                           GHashTable *table)
 {
@@ -178,7 +165,7 @@ typedef struct
   gint n_buckets;
 } HashTable;
 
-HashTable *
+static HashTable *
 hash_table_new (gint n_buckets)
 {
   HashTable *table;
@@ -191,6 +178,14 @@ hash_table_new (gint n_buckets)
 }
 
 static void
+hash_table_free (HashTable *table)
+{
+  g_free (table->buckets);
+
+  g_slice_free (HashTable, table);
+}
+
+static void
 hash_table_insert (gpointer key,
                    gpointer value,
                    gpointer data)
@@ -282,33 +277,6 @@ file_builder_add_value (FileBuilder         *fb,
 }
 
 static void
-file_builder_add_options (FileBuilder         *fb,
-                          GVariant            *options,
-                          struct gvdb_pointer *pointer)
-{
-  GVariant *normal;
-  gpointer data;
-  gsize size;
-
-  if (options)
-    {
-      if (fb->byteswap)
-        {
-          options = g_variant_byteswap (options);
-          normal = g_variant_get_normal_form (options);
-          g_variant_unref (options);
-        }
-      else
-        normal = g_variant_get_normal_form (options);
-
-      size = g_variant_get_size (normal);
-      data = file_builder_allocate (fb, 8, size, pointer);
-      g_variant_store (normal, data);
-      g_variant_unref (normal);
-    }
-}
-
-static void
 file_builder_add_string (FileBuilder *fb,
                          const gchar *string,
                          guint32_le  *start,
@@ -424,13 +392,12 @@ file_builder_add_hash (FileBuilder         *fb,
               g_assert (item->child == NULL && item->table == NULL);
 
               file_builder_add_value (fb, item->value, &entry->value.pointer);
-              file_builder_add_options (fb, item->options, &entry->options);
               entry->type = 'v';
             }
 
           if (item->child != NULL)
             {
-              guint32 children = 0;
+              guint32 children = 0, i = 0;
               guint32_le *offsets;
               GvdbItem *child;
 
@@ -444,9 +411,9 @@ file_builder_add_hash (FileBuilder         *fb,
               entry->type = 'L';
 
               for (child = item->child; child; child = child->sibling)
-                offsets[--children] = child->assigned_index;
+                offsets[i++] = child->assigned_index;
 
-              g_assert (children == 0);
+              g_assert (children == i);
             }
 
           if (item->table != NULL)
@@ -458,6 +425,8 @@ file_builder_add_hash (FileBuilder         *fb,
           index++;
         }
     }
+
+  hash_table_free (mytable);
 }
 
 static FileBuilder *
@@ -513,6 +482,8 @@ file_builder_serialise (FileBuilder          *fb,
 
       g_string_append_len (result, chunk->data, chunk->size);
       g_free (chunk->data);
+
+      g_slice_free (FileChunk, chunk);
     }
 
   g_queue_free (fb->chunks);