From 814c0fcaafd42c622634c7b6a34c126210b17fc2 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Tue, 7 Dec 2010 01:06:33 -0500 Subject: [PATCH 1/5] Pass name_length to walk close function For efficiency and safety. This way we don't need to scan backwards for the path separator (trusting that we will find it properly). --- gvdb-reader.c | 29 ++++++++++++++++++++++++++++- gvdb-reader.h | 3 ++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/gvdb-reader.c b/gvdb-reader.c index fb23393e1..f49ff4e00 100644 --- a/gvdb-reader.c +++ b/gvdb-reader.c @@ -574,6 +574,30 @@ gvdb_table_is_valid (GvdbTable *table) return !!*table->data; } +/** + * gvdb_table_walk: + * @table: a #GvdbTable + * @key: a key corresponding to a list + * @open_func: the #GvdbWalkOpenFunc + * @value_func: the #GvdbWalkValueFunc + * @close_func: the #GvdbWalkCloseFunc + * @user_data: data to pass to the callbacks + * + * Looks up the list at @key and iterate over the items in it. + * + * First, @open_func is called to signal that we are starting to iterate over + * the list. Then the list is iterated. When all items in the list have been + * iterated over, the @close_func is called. + * + * When iterating, if a given item in the list is a value then @value_func is + * called. + * + * If a given item in the list is itself a list then @open_func is called. If + * that function returns %TRUE then the walk begins iterating the items in the + * sublist, until there are no more items, at which point a matching + * @close_func call is made. If @open_func returns %FALSE then no iteration of + * the sublist occurs and no corresponding @close_func call is made. + **/ void gvdb_table_walk (GvdbTable *table, const gchar *key, @@ -585,16 +609,18 @@ gvdb_table_walk (GvdbTable *table, const struct gvdb_hash_item *item; const guint32_le *pointers[64]; const guint32_le *enders[64]; + gsize name_lengths[64]; gint index = 0; item = gvdb_table_lookup (table, key, 'L'); + name_lengths[0] = 0; pointers[0] = NULL; enders[0] = NULL; goto start_here; while (index) { - close_func (user_data); + close_func (name_lengths[index], user_data); index--; while (pointers[index] < enders[index]) @@ -621,6 +647,7 @@ gvdb_table_walk (GvdbTable *table, &pointers[index], &length); enders[index] = pointers[index] + length; + name_lengths[index] = name_len; } } else if (item->type == 'v') diff --git a/gvdb-reader.h b/gvdb-reader.h index 9f302c043..e75c69cb2 100644 --- a/gvdb-reader.h +++ b/gvdb-reader.h @@ -62,7 +62,8 @@ typedef void (*GvdbWalkValueFunc) (const g typedef gboolean (*GvdbWalkOpenFunc) (const gchar *name, gsize name_len, gpointer user_data); -typedef void (*GvdbWalkCloseFunc) (gpointer user_data); +typedef void (*GvdbWalkCloseFunc) (gsize name_len, + gpointer user_data); void gvdb_table_walk (GvdbTable *table, const gchar *key, From 92c22e7ca78670e35df9150169f6837c1dc1d99b Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Wed, 15 Dec 2010 11:36:14 -0500 Subject: [PATCH 2/5] Fix some leaks in the GVDB builder --- gvdb-builder.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gvdb-builder.c b/gvdb-builder.c index fdd0ef4c9..4b48d804e 100644 --- a/gvdb-builder.c +++ b/gvdb-builder.c @@ -177,6 +177,14 @@ hash_table_new (gint n_buckets) return table; } +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, @@ -417,6 +425,8 @@ file_builder_add_hash (FileBuilder *fb, index++; } } + + hash_table_free (mytable); } static FileBuilder * @@ -472,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); From ba5619ba7f69025f40bf5e77d667a2a84b61d1a7 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Mon, 17 Jan 2011 15:15:46 -0500 Subject: [PATCH 3/5] C++ify the reader header --- gvdb-reader.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gvdb-reader.h b/gvdb-reader.h index e75c69cb2..d7512570b 100644 --- a/gvdb-reader.h +++ b/gvdb-reader.h @@ -26,6 +26,8 @@ typedef struct _GvdbTable GvdbTable; +G_BEGIN_DECLS + G_GNUC_INTERNAL GvdbTable * gvdb_table_new (const gchar *filename, gboolean trusted, @@ -72,5 +74,6 @@ void gvdb_table_walk (GvdbTab GvdbWalkCloseFunc close_func, gpointer user_data); +G_END_DECLS #endif /* __gvdb_reader_h__ */ From a2918d6c3e676e2656a87b5a5ee974dc5777eb59 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Mon, 17 Jan 2011 15:17:34 -0500 Subject: [PATCH 4/5] Fix some harmless sign compare warnings --- gvdb-reader.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gvdb-reader.c b/gvdb-reader.c index f49ff4e00..264e87d15 100644 --- a/gvdb-reader.c +++ b/gvdb-reader.c @@ -230,7 +230,7 @@ gvdb_table_check_name (GvdbTable *file, return FALSE; parent = guint32_from_le (item->parent); - if (key_length == 0 && parent == -1) + if (key_length == 0 && parent == 0xffffffffu) return TRUE; if G_LIKELY (parent < file->n_hash_items && this_size > 0) @@ -340,7 +340,7 @@ gvdb_table_list (GvdbTable *file, const guint32_le *list; gchar **strv; guint length; - gint i; + guint i; if ((item = gvdb_table_lookup (file, key, 'L')) == NULL) return NULL; From 03b6b9fb9775387c3ec5eedb9e5d2152d6468147 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Tue, 25 Jan 2011 18:26:21 -0500 Subject: [PATCH 5/5] Mark a symbol as G_GNUC_INTERNAL --- gvdb-reader.h | 1 + 1 file changed, 1 insertion(+) diff --git a/gvdb-reader.h b/gvdb-reader.h index d7512570b..e6921e9e8 100644 --- a/gvdb-reader.h +++ b/gvdb-reader.h @@ -67,6 +67,7 @@ typedef gboolean (*GvdbWalkOpenFunc) (const g typedef void (*GvdbWalkCloseFunc) (gsize name_len, gpointer user_data); +G_GNUC_INTERNAL void gvdb_table_walk (GvdbTable *table, const gchar *key, GvdbWalkOpenFunc open_func,