summaryrefslogtreecommitdiff
path: root/girepository/girmodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'girepository/girmodule.c')
-rw-r--r--girepository/girmodule.c74
1 files changed, 73 insertions, 1 deletions
diff --git a/girepository/girmodule.c b/girepository/girmodule.c
index 68ee64b3..d236e81f 100644
--- a/girepository/girmodule.c
+++ b/girepository/girmodule.c
@@ -23,11 +23,13 @@
#include <stdlib.h>
#include "girmodule.h"
+#include "gitypelib-internal.h"
#include "girnode.h"
#define ALIGN_VALUE(this, boundary) \
(( ((unsigned long)(this)) + (((unsigned long)(boundary)) -1)) & (~(((unsigned long)(boundary))-1)))
+#define NUM_SECTIONS 2
GIrModule *
g_ir_module_new (const gchar *name,
@@ -220,6 +222,56 @@ node_cmp_offset_func (gconstpointer a,
return na->offset - nb->offset;
}
+static Section*
+get_section (guint8 *data, SectionType section)
+{
+ Header *header = (Header*)data;
+ Section *start = (Section*)&data[header->sections];
+
+ g_assert (section != GI_SECTION_END);
+
+ return start + (section - 1);
+}
+
+static guint8*
+add_directory_index_section (guint8 *data, GIrModule *module, guint32 *offset2)
+{
+ DirEntry *entry;
+ Header *header = (Header*)data;
+ Section *section;
+ GITypelibHashBuilder *dirindex_builder;
+ guint i, n_interfaces;
+ guint16 required_size;
+ guint32 new_offset;
+
+ dirindex_builder = _gi_typelib_hash_builder_new ();
+
+ section = get_section (data, GI_SECTION_DIRECTORY_INDEX);
+ /* Initialize the offset */
+ section->offset = *offset2;
+
+ n_interfaces = ((Header *)data)->n_local_entries;
+
+ for (i = 0; i < n_interfaces; i++)
+ {
+ entry = (DirEntry *)&data[header->directory + (i * header->entry_blob_size)];
+ const char *str = (const char *) (&data[entry->name]);
+ _gi_typelib_hash_builder_add_string (dirindex_builder, str, i);
+ }
+
+ required_size = _gi_typelib_hash_builder_get_buffer_size (dirindex_builder);
+
+ new_offset = *offset2 + ALIGN_VALUE (required_size, 4);
+
+ data = g_realloc (data, new_offset);
+
+ _gi_typelib_hash_builder_pack (dirindex_builder, ((guint8*)data) + *offset2, required_size);
+
+ *offset2 = new_offset;
+
+ _gi_typelib_hash_builder_destroy (dirindex_builder);
+ return data;
+}
GITypelib *
g_ir_module_build_typelib (GIrModule *module)
@@ -241,6 +293,7 @@ g_ir_module_build_typelib (GIrModule *module)
GList *nodes_with_attributes;
char *dependencies;
guchar *data;
+ Section *section;
header_size = ALIGN_VALUE (sizeof (Header), 4);
n_local_entries = g_list_length (module->entries);
@@ -301,6 +354,8 @@ g_ir_module_build_typelib (GIrModule *module)
if (module->c_prefix != NULL)
size += ALIGN_VALUE (strlen (module->c_prefix) + 1, 4);
+ size += sizeof (Section) * NUM_SECTIONS;
+
g_message ("allocating %d bytes (%d header, %d directory, %d entries)\n",
size, header_size, dir_size, size - header_size - dir_size);
@@ -333,7 +388,6 @@ g_ir_module_build_typelib (GIrModule *module)
header->c_prefix = write_string (module->c_prefix, strings, data, &header_size);
else
header->c_prefix = 0;
- header->directory = ALIGN_VALUE (header_size, 4);
header->entry_blob_size = sizeof (DirEntry);
header->function_blob_size = sizeof (FunctionBlob);
header->callback_blob_size = sizeof (CallbackBlob);
@@ -353,6 +407,20 @@ g_ir_module_build_typelib (GIrModule *module)
header->interface_blob_size = sizeof (InterfaceBlob);
header->union_blob_size = sizeof (UnionBlob);
+ /* Right now, just the GI_SECTION_DIRECTORY_INDEX */
+ offset2 = ALIGN_VALUE (header_size, 4);
+ header->sections = offset2;
+
+ section = (Section*) &data[offset2];
+ section->id = GI_SECTION_DIRECTORY_INDEX;
+ section->offset = 0; /* Will fill in later */
+ offset2 += sizeof(Section);
+ section = (Section*) &data[offset2];
+ section->id = GI_SECTION_END;
+ section->offset = 0;
+
+ header->directory = offset2;
+
/* fill in directory and content */
entry = (DirEntry *)&data[header->directory];
@@ -452,6 +520,10 @@ g_ir_module_build_typelib (GIrModule *module)
data = g_realloc (data, offset2);
header = (Header*) data;
+
+ data = add_directory_index_section (data, module, &offset2);
+ header = (Header *)data;
+
length = header->size = offset2;
typelib = g_typelib_new_from_memory (data, length, &error);
if (!typelib)