2012-02-03 19:42:56 +01:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
|
|
|
* GObject introspection: Typelib creation
|
2008-08-09 14:46:48 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Matthias Clasen
|
|
|
|
*
|
|
|
|
* 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 <stdio.h>
|
|
|
|
#include <string.h>
|
2010-02-11 23:18:28 +01:00
|
|
|
#include <stdlib.h>
|
2008-08-09 14:46:48 +02:00
|
|
|
|
|
|
|
#include "girmodule.h"
|
2010-10-25 19:33:01 +02:00
|
|
|
#include "gitypelib-internal.h"
|
2008-08-09 14:46:48 +02:00
|
|
|
#include "girnode.h"
|
|
|
|
|
|
|
|
#define ALIGN_VALUE(this, boundary) \
|
|
|
|
(( ((unsigned long)(this)) + (((unsigned long)(boundary)) -1)) & (~(((unsigned long)(boundary))-1)))
|
|
|
|
|
2010-10-25 19:33:01 +02:00
|
|
|
#define NUM_SECTIONS 2
|
2008-08-09 14:46:48 +02:00
|
|
|
|
|
|
|
GIrModule *
|
2010-11-16 21:08:33 +01:00
|
|
|
_g_ir_module_new (const gchar *name,
|
|
|
|
const gchar *version,
|
|
|
|
const gchar *shared_library,
|
|
|
|
const gchar *c_prefix)
|
2008-08-09 14:46:48 +02:00
|
|
|
{
|
|
|
|
GIrModule *module;
|
2010-03-24 19:00:06 +01:00
|
|
|
|
2010-05-20 16:33:49 +02:00
|
|
|
module = g_slice_new0 (GIrModule);
|
2008-08-09 14:46:48 +02:00
|
|
|
|
|
|
|
module->name = g_strdup (name);
|
2008-10-12 06:51:48 +02:00
|
|
|
module->version = g_strdup (version);
|
2008-08-09 14:46:48 +02:00
|
|
|
if (shared_library)
|
|
|
|
module->shared_library = g_strdup (shared_library);
|
|
|
|
else
|
|
|
|
module->shared_library = NULL;
|
2009-02-13 00:42:47 +01:00
|
|
|
module->c_prefix = g_strdup (c_prefix);
|
2008-08-30 22:31:07 +02:00
|
|
|
module->dependencies = NULL;
|
2008-08-09 14:46:48 +02:00
|
|
|
module->entries = NULL;
|
|
|
|
|
2008-11-12 18:17:01 +01:00
|
|
|
module->include_modules = NULL;
|
|
|
|
module->aliases = NULL;
|
|
|
|
|
2008-08-09 14:46:48 +02:00
|
|
|
return module;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-11-16 21:08:33 +01:00
|
|
|
_g_ir_module_free (GIrModule *module)
|
2008-08-09 14:46:48 +02:00
|
|
|
{
|
|
|
|
GList *e;
|
|
|
|
|
|
|
|
g_free (module->name);
|
|
|
|
|
|
|
|
for (e = module->entries; e; e = e->next)
|
2010-11-16 21:08:33 +01:00
|
|
|
_g_ir_node_free ((GIrNode *)e->data);
|
2008-08-09 14:46:48 +02:00
|
|
|
|
|
|
|
g_list_free (module->entries);
|
2008-08-30 22:31:07 +02:00
|
|
|
/* Don't free dependencies, we inherit that from the parser */
|
2008-08-09 14:46:48 +02:00
|
|
|
|
2008-11-11 01:48:17 +01:00
|
|
|
g_list_free (module->include_modules);
|
|
|
|
|
2008-11-12 18:17:01 +01:00
|
|
|
g_hash_table_destroy (module->aliases);
|
|
|
|
g_hash_table_destroy (module->disguised_structures);
|
|
|
|
|
2010-05-20 16:33:49 +02:00
|
|
|
g_slice_free (GIrModule, module);
|
2008-08-09 14:46:48 +02:00
|
|
|
}
|
|
|
|
|
2010-02-11 23:18:28 +01:00
|
|
|
/**
|
2010-11-16 21:08:33 +01:00
|
|
|
* _g_ir_module_fatal:
|
2010-07-26 22:26:46 +02:00
|
|
|
* @build: Current build
|
2010-02-11 23:18:28 +01:00
|
|
|
* @line: Origin line number, or 0 if unknown
|
|
|
|
* @msg: printf-format string
|
|
|
|
* @args: Remaining arguments
|
|
|
|
*
|
|
|
|
* Report a fatal error, then exit.
|
|
|
|
*/
|
|
|
|
void
|
2010-11-16 21:08:33 +01:00
|
|
|
_g_ir_module_fatal (GIrTypelibBuild *build,
|
|
|
|
guint line,
|
|
|
|
const char *msg,
|
|
|
|
...)
|
2010-02-11 23:18:28 +01:00
|
|
|
{
|
2010-07-26 22:26:46 +02:00
|
|
|
GString *context;
|
2010-02-11 23:18:28 +01:00
|
|
|
char *formatted;
|
2010-07-26 22:26:46 +02:00
|
|
|
GList *link;
|
2010-02-11 23:18:28 +01:00
|
|
|
|
|
|
|
va_list args;
|
2010-03-24 19:00:06 +01:00
|
|
|
|
2010-02-11 23:18:28 +01:00
|
|
|
va_start (args, msg);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
2010-02-11 23:18:28 +01:00
|
|
|
formatted = g_strdup_vprintf (msg, args);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
2010-07-26 22:26:46 +02:00
|
|
|
context = g_string_new ("");
|
|
|
|
if (line > 0)
|
|
|
|
g_string_append_printf (context, "%d: ", line);
|
|
|
|
if (build->stack)
|
|
|
|
g_string_append (context, "In ");
|
|
|
|
for (link = g_list_last (build->stack); link; link = link->prev)
|
|
|
|
{
|
|
|
|
GIrNode *node = link->data;
|
|
|
|
const char *name = node->name;
|
|
|
|
if (name)
|
|
|
|
g_string_append (context, name);
|
|
|
|
if (link->prev)
|
|
|
|
g_string_append (context, ".");
|
|
|
|
}
|
|
|
|
if (build->stack)
|
|
|
|
g_string_append (context, ": ");
|
|
|
|
|
|
|
|
g_printerr ("%s-%s.gir:%serror: %s\n", build->module->name,
|
|
|
|
build->module->version,
|
|
|
|
context->str, formatted);
|
|
|
|
g_string_free (context, TRUE);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
2010-02-11 23:18:28 +01:00
|
|
|
exit (1);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
2010-02-11 23:18:28 +01:00
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
|
2008-11-12 18:17:01 +01:00
|
|
|
static void
|
|
|
|
add_alias_foreach (gpointer key,
|
|
|
|
gpointer value,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GIrModule *module = data;
|
|
|
|
|
|
|
|
g_hash_table_replace (module->aliases, g_strdup (key), g_strdup (value));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_disguised_structure_foreach (gpointer key,
|
|
|
|
gpointer value,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GIrModule *module = data;
|
|
|
|
|
|
|
|
g_hash_table_replace (module->disguised_structures, g_strdup (key), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-11-16 21:08:33 +01:00
|
|
|
_g_ir_module_add_include_module (GIrModule *module,
|
|
|
|
GIrModule *include_module)
|
2008-11-12 18:17:01 +01:00
|
|
|
{
|
|
|
|
module->include_modules = g_list_prepend (module->include_modules,
|
|
|
|
include_module);
|
|
|
|
|
|
|
|
g_hash_table_foreach (include_module->aliases,
|
|
|
|
add_alias_foreach,
|
|
|
|
module);
|
|
|
|
|
|
|
|
g_hash_table_foreach (include_module->disguised_structures,
|
|
|
|
add_disguised_structure_foreach,
|
|
|
|
module);
|
|
|
|
}
|
|
|
|
|
2009-02-20 03:48:51 +01:00
|
|
|
struct AttributeWriteData
|
|
|
|
{
|
|
|
|
guint count;
|
|
|
|
guchar *databuf;
|
|
|
|
GIrNode *node;
|
|
|
|
GHashTable *strings;
|
|
|
|
guint32 *offset;
|
|
|
|
guint32 *offset2;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
write_attribute (gpointer key, gpointer value, gpointer datap)
|
|
|
|
{
|
|
|
|
struct AttributeWriteData *data = datap;
|
|
|
|
guint32 old_offset = *(data->offset);
|
|
|
|
AttributeBlob *blob = (AttributeBlob*)&(data->databuf[old_offset]);
|
|
|
|
|
|
|
|
*(data->offset) += sizeof (AttributeBlob);
|
|
|
|
|
|
|
|
blob->offset = data->node->offset;
|
2010-11-16 21:08:33 +01:00
|
|
|
blob->name = _g_ir_write_string ((const char*) key, data->strings, data->databuf, data->offset2);
|
|
|
|
blob->value = _g_ir_write_string ((const char*) value, data->strings, data->databuf, data->offset2);
|
2009-02-20 03:48:51 +01:00
|
|
|
|
|
|
|
data->count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
|
|
|
write_attributes (GIrModule *module,
|
|
|
|
GIrNode *node,
|
|
|
|
GHashTable *strings,
|
|
|
|
guchar *data,
|
|
|
|
guint32 *offset,
|
|
|
|
guint32 *offset2)
|
|
|
|
{
|
|
|
|
struct AttributeWriteData wdata;
|
|
|
|
wdata.count = 0;
|
|
|
|
wdata.databuf = data;
|
|
|
|
wdata.node = node;
|
|
|
|
wdata.offset = offset;
|
|
|
|
wdata.offset2 = offset2;
|
|
|
|
wdata.strings = strings;
|
|
|
|
|
|
|
|
g_hash_table_foreach (node->attributes, write_attribute, &wdata);
|
|
|
|
|
|
|
|
return wdata.count;
|
|
|
|
}
|
|
|
|
|
2010-06-15 16:50:42 +02:00
|
|
|
static gint
|
|
|
|
node_cmp_offset_func (gconstpointer a,
|
|
|
|
gconstpointer b)
|
|
|
|
{
|
|
|
|
const GIrNode *na = a;
|
|
|
|
const GIrNode *nb = b;
|
|
|
|
return na->offset - nb->offset;
|
|
|
|
}
|
|
|
|
|
2010-10-25 19:33:01 +02:00
|
|
|
static void
|
|
|
|
alloc_section (guint8 *data, SectionType section_id, guint32 offset)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
Header *header = (Header*)data;
|
|
|
|
Section *section_data = (Section*)&data[header->sections];
|
|
|
|
|
|
|
|
g_assert (section_id != GI_SECTION_END);
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_SECTIONS; i++)
|
|
|
|
{
|
|
|
|
if (section_data->id == GI_SECTION_END)
|
|
|
|
{
|
|
|
|
section_data->id = section_id;
|
|
|
|
section_data->offset = offset;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
section_data++;
|
|
|
|
}
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint8*
|
|
|
|
add_directory_index_section (guint8 *data, GIrModule *module, guint32 *offset2)
|
|
|
|
{
|
|
|
|
DirEntry *entry;
|
|
|
|
Header *header = (Header*)data;
|
|
|
|
GITypelibHashBuilder *dirindex_builder;
|
|
|
|
guint i, n_interfaces;
|
|
|
|
guint16 required_size;
|
|
|
|
guint32 new_offset;
|
|
|
|
|
|
|
|
dirindex_builder = _gi_typelib_hash_builder_new ();
|
|
|
|
|
|
|
|
n_interfaces = ((Header *)data)->n_local_entries;
|
|
|
|
|
|
|
|
for (i = 0; i < n_interfaces; i++)
|
|
|
|
{
|
2012-07-24 10:09:38 +02:00
|
|
|
const char *str;
|
2010-10-25 19:33:01 +02:00
|
|
|
entry = (DirEntry *)&data[header->directory + (i * header->entry_blob_size)];
|
2012-07-24 10:09:38 +02:00
|
|
|
str = (const char *) (&data[entry->name]);
|
2010-10-25 19:33:01 +02:00
|
|
|
_gi_typelib_hash_builder_add_string (dirindex_builder, str, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_gi_typelib_hash_builder_prepare (dirindex_builder))
|
|
|
|
{
|
|
|
|
/* This happens if CMPH couldn't create a perfect hash. So
|
|
|
|
* we just punt and leave no directory index section.
|
|
|
|
*/
|
|
|
|
_gi_typelib_hash_builder_destroy (dirindex_builder);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
alloc_section (data, GI_SECTION_DIRECTORY_INDEX, *offset2);
|
|
|
|
|
|
|
|
required_size = _gi_typelib_hash_builder_get_buffer_size (dirindex_builder);
|
2013-12-29 01:37:18 +01:00
|
|
|
required_size = ALIGN_VALUE (required_size, 4);
|
2010-10-25 19:33:01 +02:00
|
|
|
|
2013-12-29 01:37:18 +01:00
|
|
|
new_offset = *offset2 + required_size;
|
2010-10-25 19:33:01 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2010-06-15 16:50:42 +02:00
|
|
|
|
2010-08-31 22:36:06 +02:00
|
|
|
GITypelib *
|
2010-11-16 21:08:33 +01:00
|
|
|
_g_ir_module_build_typelib (GIrModule *module)
|
2008-08-09 14:46:48 +02:00
|
|
|
{
|
2010-07-14 17:59:11 +02:00
|
|
|
GError *error = NULL;
|
2010-08-31 22:36:06 +02:00
|
|
|
GITypelib *typelib;
|
2008-08-09 14:46:48 +02:00
|
|
|
gsize length;
|
2008-10-22 16:31:58 +02:00
|
|
|
guint i;
|
2008-08-09 14:46:48 +02:00
|
|
|
GList *e;
|
|
|
|
Header *header;
|
|
|
|
DirEntry *entry;
|
|
|
|
guint32 header_size;
|
|
|
|
guint32 dir_size;
|
|
|
|
guint32 n_entries;
|
|
|
|
guint32 n_local_entries;
|
|
|
|
guint32 size, offset, offset2, old_offset;
|
|
|
|
GHashTable *strings;
|
|
|
|
GHashTable *types;
|
2010-06-15 16:50:42 +02:00
|
|
|
GList *nodes_with_attributes;
|
2008-08-30 22:31:07 +02:00
|
|
|
char *dependencies;
|
2008-08-09 14:46:48 +02:00
|
|
|
guchar *data;
|
2010-10-25 19:33:01 +02:00
|
|
|
Section *section;
|
2008-08-09 14:46:48 +02:00
|
|
|
|
|
|
|
header_size = ALIGN_VALUE (sizeof (Header), 4);
|
|
|
|
n_local_entries = g_list_length (module->entries);
|
|
|
|
|
2008-08-30 22:31:07 +02:00
|
|
|
/* Serialize dependencies into one string; this is convenient
|
|
|
|
* and not a major change to the typelib format. */
|
|
|
|
{
|
|
|
|
GString *dependencies_str = g_string_new ("");
|
|
|
|
GList *link;
|
|
|
|
for (link = module->dependencies; link; link = link->next)
|
|
|
|
{
|
|
|
|
const char *dependency = link->data;
|
|
|
|
if (!strcmp (dependency, module->name))
|
|
|
|
continue;
|
|
|
|
g_string_append (dependencies_str, dependency);
|
|
|
|
if (link->next)
|
|
|
|
g_string_append_c (dependencies_str, '|');
|
|
|
|
}
|
|
|
|
dependencies = g_string_free (dependencies_str, FALSE);
|
|
|
|
if (!dependencies[0])
|
|
|
|
{
|
|
|
|
g_free (dependencies);
|
|
|
|
dependencies = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-09 14:46:48 +02:00
|
|
|
restart:
|
Bug 556543 – reduce compiler warnings
2008-10-16 Tommi Komulainen <tommi.komulainen@iki.fi>
Bug 556543 – reduce compiler warnings
* girepository/ginfo.c:
* girepository/girepository.c (register_internal,
count_interfaces, find_interface, find_namespace_version,
parse_version, g_irepository_require):
* girepository/girmodule.c (g_ir_module_build_typelib):
* girepository/girnode.c (init_stats, dump_stats,
_g_irnode_init_stats, _g_irnode_dump_stats,
g_ir_node_can_have_member):
* girepository/girparser.c (firstpass_end_element_handler,
locate_gir, parse_basic, parse_type_internal, resolve_aliases,
start_alias, start_type, end_type_top, parse_include, cleanup,
post_filter):
* girepository/gtypelib.c (validate_function_blob, validate_enum_blob):
* giscanner/giscannermodule.c (directive_get_options,
type_get_child_list):
* giscanner/scannerlexer.l (parse_gtkdoc):
* giscanner/scannerparser.y (ctype_free):
* giscanner/sourcescanner.c:
* giscanner/sourcescanner.h (gi_source_scanner_parse_macros):
* tests/types/gitesttypes.c:
* tools/compiler.c (main):
* tools/generate.c (write_repository): Remove unused variables
and code, add missing includes, declarations and case
statements.
svn path=/trunk/; revision=730
2008-10-16 19:07:05 +02:00
|
|
|
_g_irnode_init_stats ();
|
2008-08-09 14:46:48 +02:00
|
|
|
strings = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
types = g_hash_table_new (g_str_hash, g_str_equal);
|
2010-06-15 16:50:42 +02:00
|
|
|
nodes_with_attributes = NULL;
|
2008-08-09 14:46:48 +02:00
|
|
|
n_entries = g_list_length (module->entries);
|
|
|
|
|
2008-08-30 22:31:07 +02:00
|
|
|
g_message ("%d entries (%d local), %d dependencies\n", n_entries, n_local_entries,
|
|
|
|
g_list_length (module->dependencies));
|
2010-03-24 19:00:06 +01:00
|
|
|
|
2009-02-12 05:36:31 +01:00
|
|
|
dir_size = n_entries * sizeof (DirEntry);
|
2008-08-09 14:46:48 +02:00
|
|
|
size = header_size + dir_size;
|
|
|
|
|
|
|
|
size += ALIGN_VALUE (strlen (module->name) + 1, 4);
|
|
|
|
|
|
|
|
for (e = module->entries; e; e = e->next)
|
|
|
|
{
|
|
|
|
GIrNode *node = e->data;
|
2010-03-24 19:00:06 +01:00
|
|
|
|
2010-11-16 21:08:33 +01:00
|
|
|
size += _g_ir_node_get_full_size (node);
|
2009-02-20 03:48:51 +01:00
|
|
|
|
|
|
|
/* Also reset the offset here */
|
|
|
|
node->offset = 0;
|
2008-08-09 14:46:48 +02:00
|
|
|
}
|
|
|
|
|
2008-08-21 02:42:23 +02:00
|
|
|
/* Adjust size for strings allocated in header below specially */
|
2009-02-13 00:42:47 +01:00
|
|
|
size += ALIGN_VALUE (strlen (module->name) + 1, 4);
|
2010-03-24 19:00:06 +01:00
|
|
|
if (module->shared_library)
|
2009-02-13 00:42:47 +01:00
|
|
|
size += ALIGN_VALUE (strlen (module->shared_library) + 1, 4);
|
2008-08-30 22:31:07 +02:00
|
|
|
if (dependencies != NULL)
|
2009-02-13 00:42:47 +01:00
|
|
|
size += ALIGN_VALUE (strlen (dependencies) + 1, 4);
|
|
|
|
if (module->c_prefix != NULL)
|
|
|
|
size += ALIGN_VALUE (strlen (module->c_prefix) + 1, 4);
|
2008-08-21 02:42:23 +02:00
|
|
|
|
2010-10-25 19:33:01 +02:00
|
|
|
size += sizeof (Section) * NUM_SECTIONS;
|
|
|
|
|
2010-03-24 19:00:06 +01:00
|
|
|
g_message ("allocating %d bytes (%d header, %d directory, %d entries)\n",
|
2008-08-09 14:46:48 +02:00
|
|
|
size, header_size, dir_size, size - header_size - dir_size);
|
|
|
|
|
|
|
|
data = g_malloc0 (size);
|
|
|
|
|
|
|
|
/* fill in header */
|
|
|
|
header = (Header *)data;
|
|
|
|
memcpy (header, G_IR_MAGIC, 16);
|
2010-07-27 12:16:37 +02:00
|
|
|
header->major_version = 4;
|
2008-08-09 14:46:48 +02:00
|
|
|
header->minor_version = 0;
|
|
|
|
header->reserved = 0;
|
|
|
|
header->n_entries = n_entries;
|
|
|
|
header->n_local_entries = n_local_entries;
|
2009-02-20 03:48:51 +01:00
|
|
|
header->n_attributes = 0;
|
|
|
|
header->attributes = 0; /* filled in later */
|
2009-02-13 00:42:47 +01:00
|
|
|
/* NOTE: When writing strings to the typelib here, you should also update
|
|
|
|
* the size calculations above.
|
|
|
|
*/
|
2008-08-30 22:31:07 +02:00
|
|
|
if (dependencies != NULL)
|
2010-11-16 21:08:33 +01:00
|
|
|
header->dependencies = _g_ir_write_string (dependencies, strings, data, &header_size);
|
2008-08-30 22:31:07 +02:00
|
|
|
else
|
|
|
|
header->dependencies = 0;
|
2008-08-09 14:46:48 +02:00
|
|
|
header->size = 0; /* filled in later */
|
2010-11-16 21:08:33 +01:00
|
|
|
header->namespace = _g_ir_write_string (module->name, strings, data, &header_size);
|
|
|
|
header->nsversion = _g_ir_write_string (module->version, strings, data, &header_size);
|
2008-08-09 14:46:48 +02:00
|
|
|
header->shared_library = (module->shared_library?
|
2010-11-16 21:08:33 +01:00
|
|
|
_g_ir_write_string (module->shared_library, strings, data, &header_size)
|
2008-08-09 14:46:48 +02:00
|
|
|
: 0);
|
2009-02-13 00:42:47 +01:00
|
|
|
if (module->c_prefix != NULL)
|
2010-11-16 21:08:33 +01:00
|
|
|
header->c_prefix = _g_ir_write_string (module->c_prefix, strings, data, &header_size);
|
2009-02-13 00:42:47 +01:00
|
|
|
else
|
|
|
|
header->c_prefix = 0;
|
2009-02-12 05:36:31 +01:00
|
|
|
header->entry_blob_size = sizeof (DirEntry);
|
2008-11-25 23:29:20 +01:00
|
|
|
header->function_blob_size = sizeof (FunctionBlob);
|
2009-02-12 05:36:31 +01:00
|
|
|
header->callback_blob_size = sizeof (CallbackBlob);
|
|
|
|
header->signal_blob_size = sizeof (SignalBlob);
|
|
|
|
header->vfunc_blob_size = sizeof (VFuncBlob);
|
|
|
|
header->arg_blob_size = sizeof (ArgBlob);
|
|
|
|
header->property_blob_size = sizeof (PropertyBlob);
|
|
|
|
header->field_blob_size = sizeof (FieldBlob);
|
|
|
|
header->value_blob_size = sizeof (ValueBlob);
|
|
|
|
header->constant_blob_size = sizeof (ConstantBlob);
|
2011-05-19 22:12:03 +02:00
|
|
|
header->error_domain_blob_size = 16; /* No longer used */
|
2009-02-20 03:48:51 +01:00
|
|
|
header->attribute_blob_size = sizeof (AttributeBlob);
|
2009-02-12 05:36:31 +01:00
|
|
|
header->signature_blob_size = sizeof (SignatureBlob);
|
|
|
|
header->enum_blob_size = sizeof (EnumBlob);
|
|
|
|
header->struct_blob_size = sizeof (StructBlob);
|
2009-02-06 19:37:13 +01:00
|
|
|
header->object_blob_size = sizeof(ObjectBlob);
|
2009-02-12 05:36:31 +01:00
|
|
|
header->interface_blob_size = sizeof (InterfaceBlob);
|
|
|
|
header->union_blob_size = sizeof (UnionBlob);
|
2008-08-09 14:46:48 +02:00
|
|
|
|
2010-10-25 19:33:01 +02:00
|
|
|
offset2 = ALIGN_VALUE (header_size, 4);
|
|
|
|
header->sections = offset2;
|
|
|
|
|
|
|
|
/* Initialize all the sections to _END/0; we fill them in later using
|
|
|
|
* alloc_section(). (Right now there's just the directory index
|
|
|
|
* though, note)
|
|
|
|
*/
|
|
|
|
for (i = 0; i < NUM_SECTIONS; i++)
|
|
|
|
{
|
|
|
|
section = (Section*) &data[offset2];
|
|
|
|
section->id = GI_SECTION_END;
|
|
|
|
section->offset = 0;
|
|
|
|
offset2 += sizeof(Section);
|
|
|
|
}
|
|
|
|
header->directory = offset2;
|
|
|
|
|
2008-08-09 14:46:48 +02:00
|
|
|
/* fill in directory and content */
|
|
|
|
entry = (DirEntry *)&data[header->directory];
|
|
|
|
|
2010-10-25 19:33:01 +02:00
|
|
|
offset2 += dir_size;
|
2008-08-09 14:46:48 +02:00
|
|
|
|
|
|
|
for (e = module->entries, i = 0; e; e = e->next, i++)
|
|
|
|
{
|
2009-02-20 17:05:53 +01:00
|
|
|
GIrTypelibBuild build;
|
2008-08-09 14:46:48 +02:00
|
|
|
GIrNode *node = e->data;
|
|
|
|
|
|
|
|
if (strchr (node->name, '.'))
|
|
|
|
{
|
|
|
|
g_error ("Names may not contain '.'");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we picked up implicit xref nodes, start over */
|
|
|
|
if (i == n_entries)
|
|
|
|
{
|
2009-02-20 03:48:51 +01:00
|
|
|
GList *link;
|
2008-08-09 14:46:48 +02:00
|
|
|
g_message ("Found implicit cross references, starting over");
|
|
|
|
|
|
|
|
g_hash_table_destroy (strings);
|
|
|
|
g_hash_table_destroy (types);
|
2009-02-20 03:48:51 +01:00
|
|
|
|
|
|
|
/* Reset the cached offsets */
|
2010-06-15 16:50:42 +02:00
|
|
|
for (link = nodes_with_attributes; link; link = link->next)
|
2009-02-20 03:48:51 +01:00
|
|
|
((GIrNode *) link->data)->offset = 0;
|
|
|
|
|
2010-06-15 16:50:42 +02:00
|
|
|
g_list_free (nodes_with_attributes);
|
2008-08-09 14:46:48 +02:00
|
|
|
strings = NULL;
|
|
|
|
|
|
|
|
g_free (data);
|
|
|
|
data = NULL;
|
|
|
|
|
|
|
|
goto restart;
|
|
|
|
}
|
2010-03-24 19:00:06 +01:00
|
|
|
|
2008-08-09 14:46:48 +02:00
|
|
|
offset = offset2;
|
|
|
|
|
|
|
|
if (node->type == G_IR_NODE_XREF)
|
|
|
|
{
|
2008-08-30 22:31:07 +02:00
|
|
|
const char *namespace = ((GIrNodeXRef*)node)->namespace;
|
2010-03-24 19:00:06 +01:00
|
|
|
|
2008-08-09 14:46:48 +02:00
|
|
|
entry->blob_type = 0;
|
|
|
|
entry->local = FALSE;
|
2010-11-16 21:08:33 +01:00
|
|
|
entry->offset = _g_ir_write_string (namespace, strings, data, &offset2);
|
|
|
|
entry->name = _g_ir_write_string (node->name, strings, data, &offset2);
|
2008-08-09 14:46:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
old_offset = offset;
|
2010-11-16 21:08:33 +01:00
|
|
|
offset2 = offset + _g_ir_node_get_size (node);
|
2008-08-09 14:46:48 +02:00
|
|
|
|
|
|
|
entry->blob_type = node->type;
|
|
|
|
entry->local = TRUE;
|
|
|
|
entry->offset = offset;
|
2010-11-16 21:08:33 +01:00
|
|
|
entry->name = _g_ir_write_string (node->name, strings, data, &offset2);
|
2008-08-09 14:46:48 +02:00
|
|
|
|
2010-07-26 22:26:46 +02:00
|
|
|
memset (&build, 0, sizeof (build));
|
2009-02-20 17:05:53 +01:00
|
|
|
build.module = module;
|
|
|
|
build.strings = strings;
|
|
|
|
build.types = types;
|
2010-06-15 16:50:42 +02:00
|
|
|
build.nodes_with_attributes = nodes_with_attributes;
|
2009-02-20 03:48:51 +01:00
|
|
|
build.n_attributes = header->n_attributes;
|
2009-02-20 17:05:53 +01:00
|
|
|
build.data = data;
|
2010-11-16 21:08:33 +01:00
|
|
|
_g_ir_node_build_typelib (node, NULL, &build, &offset, &offset2);
|
2008-08-09 14:46:48 +02:00
|
|
|
|
2010-06-15 16:50:42 +02:00
|
|
|
nodes_with_attributes = build.nodes_with_attributes;
|
2009-02-20 03:48:51 +01:00
|
|
|
header->n_attributes = build.n_attributes;
|
|
|
|
|
2010-11-16 21:08:33 +01:00
|
|
|
if (offset2 > old_offset + _g_ir_node_get_full_size (node))
|
|
|
|
g_error ("left a hole of %d bytes\n", offset2 - old_offset - _g_ir_node_get_full_size (node));
|
2008-08-09 14:46:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
entry++;
|
|
|
|
}
|
|
|
|
|
2010-06-15 16:50:42 +02:00
|
|
|
/* GIBaseInfo expects the AttributeBlob array to be sorted on the field (offset) */
|
|
|
|
nodes_with_attributes = g_list_sort (nodes_with_attributes, node_cmp_offset_func);
|
2009-02-20 03:48:51 +01:00
|
|
|
|
|
|
|
g_message ("header: %d entries, %d attributes", header->n_entries, header->n_attributes);
|
|
|
|
|
Bug 556543 – reduce compiler warnings
2008-10-16 Tommi Komulainen <tommi.komulainen@iki.fi>
Bug 556543 – reduce compiler warnings
* girepository/ginfo.c:
* girepository/girepository.c (register_internal,
count_interfaces, find_interface, find_namespace_version,
parse_version, g_irepository_require):
* girepository/girmodule.c (g_ir_module_build_typelib):
* girepository/girnode.c (init_stats, dump_stats,
_g_irnode_init_stats, _g_irnode_dump_stats,
g_ir_node_can_have_member):
* girepository/girparser.c (firstpass_end_element_handler,
locate_gir, parse_basic, parse_type_internal, resolve_aliases,
start_alias, start_type, end_type_top, parse_include, cleanup,
post_filter):
* girepository/gtypelib.c (validate_function_blob, validate_enum_blob):
* giscanner/giscannermodule.c (directive_get_options,
type_get_child_list):
* giscanner/scannerlexer.l (parse_gtkdoc):
* giscanner/scannerparser.y (ctype_free):
* giscanner/sourcescanner.c:
* giscanner/sourcescanner.h (gi_source_scanner_parse_macros):
* tests/types/gitesttypes.c:
* tools/compiler.c (main):
* tools/generate.c (write_repository): Remove unused variables
and code, add missing includes, declarations and case
statements.
svn path=/trunk/; revision=730
2008-10-16 19:07:05 +02:00
|
|
|
_g_irnode_dump_stats ();
|
2008-08-09 14:46:48 +02:00
|
|
|
|
2009-02-20 03:48:51 +01:00
|
|
|
/* Write attributes after the blobs */
|
|
|
|
offset = offset2;
|
|
|
|
header->attributes = offset;
|
|
|
|
offset2 = offset + header->n_attributes * header->attribute_blob_size;
|
|
|
|
|
2010-06-15 16:50:42 +02:00
|
|
|
for (e = nodes_with_attributes; e; e = e->next)
|
2009-02-20 03:48:51 +01:00
|
|
|
{
|
|
|
|
GIrNode *node = e->data;
|
|
|
|
write_attributes (module, node, strings, data, &offset, &offset2);
|
|
|
|
}
|
2010-03-24 19:00:06 +01:00
|
|
|
|
2008-08-09 14:46:48 +02:00
|
|
|
g_message ("reallocating to %d bytes", offset2);
|
|
|
|
|
2008-08-21 02:42:23 +02:00
|
|
|
data = g_realloc (data, offset2);
|
|
|
|
header = (Header*) data;
|
2010-10-25 19:33:01 +02:00
|
|
|
|
|
|
|
data = add_directory_index_section (data, module, &offset2);
|
|
|
|
header = (Header *)data;
|
|
|
|
|
2008-08-09 14:46:48 +02:00
|
|
|
length = header->size = offset2;
|
2010-07-14 17:59:11 +02:00
|
|
|
typelib = g_typelib_new_from_memory (data, length, &error);
|
|
|
|
if (!typelib)
|
|
|
|
{
|
|
|
|
g_error ("error building typelib: %s",
|
|
|
|
error->message);
|
|
|
|
}
|
2008-08-21 02:42:23 +02:00
|
|
|
|
|
|
|
g_hash_table_destroy (strings);
|
|
|
|
g_hash_table_destroy (types);
|
2010-06-15 16:50:42 +02:00
|
|
|
g_list_free (nodes_with_attributes);
|
2008-08-21 02:42:23 +02:00
|
|
|
|
|
|
|
return typelib;
|
2008-08-09 14:46:48 +02:00
|
|
|
}
|
|
|
|
|