summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2010-10-25 07:56:05 -0400
committerColin Walters <walters@verbum.org>2010-10-25 07:56:05 -0400
commit8138562c88e200965c610f55e9491047c0862137 (patch)
treef4c4bc63cba6e21e8351dc582bf4020368c1506f
parent8c503da876ee6f3e551c51d399e4682b81b839d3 (diff)
downloadgobject-introspection-8138562c88e200965c610f55e9491047c0862137.tar.gz
Sketch out typelib hashing functions built on CMPH
-rw-r--r--girepository/Makefile-girepository.am7
-rw-r--r--girepository/gitypelib-internal.h17
-rw-r--r--girepository/gthash.c106
3 files changed, 128 insertions, 2 deletions
diff --git a/girepository/Makefile-girepository.am b/girepository/Makefile-girepository.am
index aec14161..6292a1a8 100644
--- a/girepository/Makefile-girepository.am
+++ b/girepository/Makefile-girepository.am
@@ -51,10 +51,13 @@ libgirepository_1_0_la_SOURCES = \
gitypelib-internal.h \
glib-compat.h \
giunioninfo.c \
- givfuncinfo.c
+ givfuncinfo.c \
+ gthash.c \
+ $(NULL)
+
libgirepository_1_0_la_CPPFLAGS = $(GIREPO_CFLAGS) -DG_IREPOSITORY_COMPILATION
-libgirepository_1_0_la_LIBADD = $(GIREPO_LIBS)
+libgirepository_1_0_la_LIBADD = libcmph.la $(GIREPO_LIBS)
libgirepository_1_0_la_LDFLAGS = -no-undefined -version-number 1:0:0
libgirepository_parser_la_SOURCES = \
diff --git a/girepository/gitypelib-internal.h b/girepository/gitypelib-internal.h
index 26fd6bfb..9af4fa64 100644
--- a/girepository/gitypelib-internal.h
+++ b/girepository/gitypelib-internal.h
@@ -1143,6 +1143,23 @@ gboolean g_typelib_validate (GITypelib *typelib,
AttributeBlob *_attribute_blob_find_first (GIBaseInfo *info,
guint32 blob_offset);
+typedef struct _GITypelibHashBuilder GITypelibHashBuilder;
+
+void _gi_typelib_hash_builder_init (GITypelibHashBuilder *builder);
+
+void _gi_typelib_hash_builder_add_string (GITypelibHashBuilder *builder,
+ const char *str,
+ guint16 value);
+
+guint32 _gi_typelib_hash_builder_get_buffer_size (GITypelibHashBuilder *builder);
+
+void _gi_typelib_hash_builder_pack (GITypelibHashBuilder *builder, guint8* mem);
+
+void _gi_typelib_hash_builder_destroy (GITypelibHashBuilder *builder);
+
+void _gi_typelib_hash_search (guint8* memory, const char *str, guint16 *value);
+
+
G_END_DECLS
#endif /* __G_TYPELIB_H__ */
diff --git a/girepository/gthash.c b/girepository/gthash.c
new file mode 100644
index 00000000..e0ecbdfa
--- /dev/null
+++ b/girepository/gthash.c
@@ -0,0 +1,106 @@
+/* GObject introspection: Typelib hashing
+ *
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * 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.
+ */
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include "cmph/cmph.h"
+#include "gitypelib-internal.h"
+
+struct _GITypelibHashBuilder {
+ cmph_t *c;
+ GHashTable *strings;
+};
+
+void
+_gi_typelib_hash_builder_init (GITypelibHashBuilder *builder)
+{
+ builder->c = NULL;
+ builder->strings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+}
+
+void
+_gi_typelib_hash_builder_add_string (GITypelibHashBuilder *builder,
+ const char *str,
+ guint16 value)
+{
+ g_return_if_fail (builder->c == NULL);
+ g_hash_table_insert (builder->strings, g_strdup (str), GUINT_TO_POINTER ((guint) value));
+}
+
+static void
+_gi_typelib_hash_builder_build (GITypelibHashBuilder *builder)
+{
+ char **strs;
+ GHashTableIter hashiter;
+ gpointer key, value;
+ cmph_io_adapter_t *io;
+ cmph_config_t *config;
+
+ if (builder->c != NULL)
+ return;
+
+ strs = g_new (char *, g_hash_table_size (builder->strings));
+
+ g_hash_table_iter_init (&hashiter, builder->strings);
+ while (g_hash_table_iter_next (&hashiter, &key, &value))
+ {
+ const char *str = key;
+ guint16 strval = (guint16)GPOINTER_TO_UINT(value);
+
+ }
+
+
+ io = cmph_io_vector_adapter (strs, g_hash_table_size (builder->strings));
+ config = cmph_config_new (io);
+ cmph_config_set_algo (config, CMPH_BDZ);
+
+ builder->c = cmph_new (config);
+}
+
+guint32
+_gi_typelib_hash_builder_get_buffer_size (GITypelibHashBuilder *builder)
+{
+ _gi_typelib_hash_builder_build (builder);
+ return cmph_packed_size (builder->c);
+}
+
+void
+_gi_typelib_hash_builder_pack (GITypelibHashBuilder *builder, guint8* mem)
+{
+ cmph_pack (builder->c, mem);
+}
+
+void
+_gi_typelib_hash_builder_destroy (GITypelibHashBuilder *builder)
+{
+ if (builder->c)
+ {
+ cmph_destroy (builder->c);
+ builder->c = NULL;
+ }
+ g_hash_table_destroy (builder->strings);
+}
+
+void
+_gi_typelib_hash_search (guint8* memory, const char *str, guint16 *value)
+{
+}
+