Merge remote branch 'gvdb/master'

This commit is contained in:
Ryan Lortie 2010-10-03 21:11:17 -04:00
commit 63adeda086
2 changed files with 47 additions and 6 deletions

View File

@ -34,11 +34,11 @@ struct _GvdbTable {
gboolean byteswapped;
gboolean trusted;
const guint32 *bloom_words;
const guint32_le *bloom_words;
guint32 n_bloom_words;
guint bloom_shift;
const guint32 *hash_buckets;
const guint32_le *hash_buckets;
guint32 n_buckets;
struct gvdb_hash_item *hash_items;
@ -206,7 +206,7 @@ gvdb_table_bloom_filter (GvdbTable *file,
mask = 1 << (hash_value & 31);
mask |= 1 << ((hash_value >> file->bloom_shift) & 31);
return (file->bloom_words[word] & mask) == mask;
return (guint32_from_le (file->bloom_words[word]) & mask) == mask;
}
static gboolean
@ -262,10 +262,10 @@ gvdb_table_lookup (GvdbTable *file,
return NULL;
bucket = hash_value % file->n_buckets;
itemno = file->hash_buckets[bucket];
itemno = guint32_from_le (file->hash_buckets[bucket]);
if (bucket == file->n_buckets - 1 ||
(lastno = file->hash_buckets[bucket + 1]) > file->n_hash_items)
(lastno = guint32_from_le(file->hash_buckets[bucket + 1])) > file->n_hash_items)
lastno = file->n_hash_items;
while G_LIKELY (itemno < lastno)
@ -438,11 +438,23 @@ gvdb_table_get_value (GvdbTable *file,
const gchar *key)
{
const struct gvdb_hash_item *item;
GVariant *value;
if ((item = gvdb_table_lookup (file, key, 'v')) == NULL)
return NULL;
return gvdb_table_value_from_item (file, item);
value = gvdb_table_value_from_item (file, item);
if (value && file->byteswapped)
{
GVariant *tmp;
tmp = g_variant_byteswap (value);
g_variant_unref (value);
value = tmp;
}
return value;
}
/**
@ -522,6 +534,23 @@ gvdb_table_unref (GvdbTable *file)
}
}
/**
* gvdb_table_is_valid:
* @table: a #GvdbTable
* @returns: %TRUE if @table is still valid
*
* Checks if the table is still valid.
*
* An on-disk GVDB can be marked as invalid. This happens when the file
* has been replaced. The appropriate action is typically to reopen the
* file.
**/
gboolean
gvdb_table_is_valid (GvdbTable *table)
{
return !!*table->data;
}
void
gvdb_table_walk (GvdbTable *table,
const gchar *key,
@ -579,6 +608,15 @@ gvdb_table_walk (GvdbTable *table,
if (value != NULL)
{
if (table->byteswapped)
{
GVariant *tmp;
tmp = g_variant_byteswap (value);
g_variant_unref (value);
value = tmp;
}
value_func (name, name_len, value, user_data);
g_variant_unref (value);
}

View File

@ -49,6 +49,9 @@ G_GNUC_INTERNAL
gboolean gvdb_table_has_value (GvdbTable *table,
const gchar *key);
G_GNUC_INTERNAL
gboolean gvdb_table_is_valid (GvdbTable *table);
typedef void (*GvdbWalkValueFunc) (const gchar *name,
gsize name_len,
GVariant *value,