2008-08-09 14:55:32 +02:00
|
|
|
/* 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>
|
|
|
|
|
|
|
|
#include "girmodule.h"
|
|
|
|
#include "girnode.h"
|
|
|
|
|
|
|
|
#define ALIGN_VALUE(this, boundary) \
|
|
|
|
(( ((unsigned long)(this)) + (((unsigned long)(boundary)) -1)) & (~(((unsigned long)(boundary))-1)))
|
|
|
|
|
|
|
|
|
|
|
|
GIrModule *
|
2008-10-12 06:51:48 +02:00
|
|
|
g_ir_module_new (const gchar *name,
|
|
|
|
const gchar *version,
|
|
|
|
const gchar *shared_library)
|
2008-08-09 14:46:48 +02:00
|
|
|
{
|
|
|
|
GIrModule *module;
|
|
|
|
|
2008-08-30 22:31:07 +02:00
|
|
|
module = g_new0 (GIrModule, 1);
|
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;
|
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
|
|
|
|
g_ir_module_free (GIrModule *module)
|
|
|
|
{
|
|
|
|
GList *e;
|
|
|
|
|
|
|
|
g_free (module->name);
|
|
|
|
|
|
|
|
for (e = module->entries; e; e = e->next)
|
|
|
|
g_ir_node_free ((GIrNode *)e->data);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2008-08-09 14:46:48 +02:00
|
|
|
g_free (module);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
g_ir_module_add_include_module (GIrModule *module,
|
|
|
|
GIrModule *include_module)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-08-09 14:46:48 +02:00
|
|
|
GTypelib *
|
2008-08-09 14:55:32 +02:00
|
|
|
g_ir_module_build_typelib (GIrModule *module,
|
2008-08-09 14:46:48 +02:00
|
|
|
GList *modules)
|
|
|
|
{
|
2008-08-21 02:42:23 +02:00
|
|
|
GTypelib *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;
|
2008-08-30 22:31:07 +02:00
|
|
|
char *dependencies;
|
2008-08-09 14:46:48 +02:00
|
|
|
guchar *data;
|
|
|
|
|
|
|
|
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);
|
|
|
|
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));
|
2008-08-09 14:46:48 +02:00
|
|
|
|
|
|
|
dir_size = n_entries * 12;
|
|
|
|
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;
|
|
|
|
|
|
|
|
size += g_ir_node_get_full_size (node);
|
|
|
|
}
|
|
|
|
|
2008-08-21 02:42:23 +02:00
|
|
|
/* Adjust size for strings allocated in header below specially */
|
|
|
|
size += strlen (module->name);
|
2008-08-21 18:15:55 +02:00
|
|
|
if (module->shared_library)
|
2008-08-21 18:25:42 +02:00
|
|
|
size += strlen (module->shared_library);
|
2008-08-30 22:31:07 +02:00
|
|
|
if (dependencies != NULL)
|
|
|
|
size += strlen (dependencies);
|
2008-08-21 02:42:23 +02:00
|
|
|
|
2008-08-09 14:46:48 +02:00
|
|
|
g_message ("allocating %d bytes (%d header, %d directory, %d entries)\n",
|
|
|
|
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);
|
Bug 556489 – callback annotations
2008-01-03 Andreas Rottmann <a.rottmann@gmx.at>
Bug 556489 – callback annotations
* giscanner/transformer.py
* tools/generate.c (write_callable_info): Write out the new scope,
closure and destroy attributes.
* giscanner/transformer.py (Transformer._type_is_callback): New
method, checking if a given type is a callback.
(Transformer._augment_callback_params): New method; adds
information (closure, destroy) to callback parameters.
(Transformer._handle_closure, Transformer._handle_destroy): New methods,
auxiliary to _augment_callback_params.
(Transformer._create_function): Call _augment_callback_params().
(Transformer._create_parameter): Handle scope option.
(Transformer._create_typedef_callback): New method, creates a
callback, and registers it in the typedef namespace
(Transformer._create_typedef): Use _create_typedef_callback()
instead of the plain _create_callback().
* giscanner/ast.py (Parameter): Added callback-related fields.
* giscanner/girwriter.py: Write out new Parameter fields.
* girepository/girnode.h (GIrNodeParam): Added fields scope,
closure and destroy.
* girepository/gtypelib.h (ArgBlob): Ditto.
* girepository/girparser.c (start_parameter): Handle new fields.
* girepository/girmodule.c (g_ir_module_build_typelib): Adjust
arg_blob_size, bump major version due to this change.
* girepository/girnode.c (g_ir_node_get_full_size_internal)
(g_ir_node_build_typelib)
* girepository/gtypelib.c (g_typelib_check_sanity): ArgBlob size
adjustments.
(g_ir_node_build_typelib): Fill in new ArgBlob flags from param.
* girepository/girepository.h (GIScope): New enumeration, listing
the different possible scopes for callbacks.
* girepository/ginfo.c (g_arg_info_get_scope)
(g_arg_info_get_closure, g_arg_info_get_destroy): Accessors for
callback-related argument indices (callback scope, closure for a
callback, destroy notification for a callback).
* tests/scanner/: Added testcases for new features.
svn path=/trunk/; revision=998
2009-01-03 14:44:42 +01:00
|
|
|
header->major_version = 2;
|
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;
|
|
|
|
header->n_annotations = 0;
|
|
|
|
header->annotations = 0; /* filled in later */
|
2008-08-30 22:31:07 +02:00
|
|
|
if (dependencies != NULL)
|
|
|
|
header->dependencies = write_string (dependencies, strings, data, &header_size);
|
|
|
|
else
|
|
|
|
header->dependencies = 0;
|
2008-08-09 14:46:48 +02:00
|
|
|
header->size = 0; /* filled in later */
|
|
|
|
header->namespace = write_string (module->name, strings, data, &header_size);
|
2008-10-12 06:51:48 +02:00
|
|
|
header->nsversion = write_string (module->version, strings, data, &header_size);
|
2008-08-09 14:46:48 +02:00
|
|
|
header->shared_library = (module->shared_library?
|
|
|
|
write_string (module->shared_library, strings, data, &header_size)
|
|
|
|
: 0);
|
|
|
|
header->directory = ALIGN_VALUE (header_size, 4);
|
|
|
|
header->entry_blob_size = 12;
|
2008-11-25 23:29:20 +01:00
|
|
|
header->function_blob_size = sizeof (FunctionBlob);
|
2008-08-09 14:46:48 +02:00
|
|
|
header->callback_blob_size = 12;
|
|
|
|
header->signal_blob_size = 12;
|
|
|
|
header->vfunc_blob_size = 16;
|
Bug 556489 – callback annotations
2008-01-03 Andreas Rottmann <a.rottmann@gmx.at>
Bug 556489 – callback annotations
* giscanner/transformer.py
* tools/generate.c (write_callable_info): Write out the new scope,
closure and destroy attributes.
* giscanner/transformer.py (Transformer._type_is_callback): New
method, checking if a given type is a callback.
(Transformer._augment_callback_params): New method; adds
information (closure, destroy) to callback parameters.
(Transformer._handle_closure, Transformer._handle_destroy): New methods,
auxiliary to _augment_callback_params.
(Transformer._create_function): Call _augment_callback_params().
(Transformer._create_parameter): Handle scope option.
(Transformer._create_typedef_callback): New method, creates a
callback, and registers it in the typedef namespace
(Transformer._create_typedef): Use _create_typedef_callback()
instead of the plain _create_callback().
* giscanner/ast.py (Parameter): Added callback-related fields.
* giscanner/girwriter.py: Write out new Parameter fields.
* girepository/girnode.h (GIrNodeParam): Added fields scope,
closure and destroy.
* girepository/gtypelib.h (ArgBlob): Ditto.
* girepository/girparser.c (start_parameter): Handle new fields.
* girepository/girmodule.c (g_ir_module_build_typelib): Adjust
arg_blob_size, bump major version due to this change.
* girepository/girnode.c (g_ir_node_get_full_size_internal)
(g_ir_node_build_typelib)
* girepository/gtypelib.c (g_typelib_check_sanity): ArgBlob size
adjustments.
(g_ir_node_build_typelib): Fill in new ArgBlob flags from param.
* girepository/girepository.h (GIScope): New enumeration, listing
the different possible scopes for callbacks.
* girepository/ginfo.c (g_arg_info_get_scope)
(g_arg_info_get_closure, g_arg_info_get_destroy): Accessors for
callback-related argument indices (callback scope, closure for a
callback, destroy notification for a callback).
* tests/scanner/: Added testcases for new features.
svn path=/trunk/; revision=998
2009-01-03 14:44:42 +01:00
|
|
|
header->arg_blob_size = 16;
|
2008-08-09 14:46:48 +02:00
|
|
|
header->property_blob_size = 12;
|
|
|
|
header->field_blob_size = 12;
|
|
|
|
header->value_blob_size = 12;
|
|
|
|
header->constant_blob_size = 20;
|
|
|
|
header->error_domain_blob_size = 16;
|
|
|
|
header->annotation_blob_size = 12;
|
|
|
|
header->signature_blob_size = 8;
|
|
|
|
header->enum_blob_size = 20;
|
2008-11-16 22:15:54 +01:00
|
|
|
header->struct_blob_size = 24;
|
2008-08-09 14:46:48 +02:00
|
|
|
header->object_blob_size = 32;
|
|
|
|
header->interface_blob_size = 28;
|
2008-11-16 22:15:54 +01:00
|
|
|
header->union_blob_size = 32;
|
2008-08-09 14:46:48 +02:00
|
|
|
|
|
|
|
/* fill in directory and content */
|
|
|
|
entry = (DirEntry *)&data[header->directory];
|
|
|
|
|
|
|
|
offset2 = header->directory + dir_size;
|
|
|
|
|
|
|
|
for (e = module->entries, i = 0; e; e = e->next, i++)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
g_message ("Found implicit cross references, starting over");
|
|
|
|
|
|
|
|
g_hash_table_destroy (strings);
|
|
|
|
g_hash_table_destroy (types);
|
|
|
|
strings = NULL;
|
|
|
|
|
|
|
|
g_free (data);
|
|
|
|
data = NULL;
|
|
|
|
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = offset2;
|
|
|
|
|
|
|
|
if (node->type == G_IR_NODE_XREF)
|
|
|
|
{
|
2008-08-30 22:31:07 +02:00
|
|
|
const char *namespace = ((GIrNodeXRef*)node)->namespace;
|
|
|
|
|
2008-08-09 14:46:48 +02:00
|
|
|
entry->blob_type = 0;
|
|
|
|
entry->local = FALSE;
|
2008-08-30 22:31:07 +02:00
|
|
|
entry->offset = write_string (namespace, strings, data, &offset2);
|
2008-08-09 14:46:48 +02:00
|
|
|
entry->name = write_string (node->name, strings, data, &offset2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
old_offset = offset;
|
|
|
|
offset2 = offset + g_ir_node_get_size (node);
|
|
|
|
|
|
|
|
entry->blob_type = node->type;
|
|
|
|
entry->local = TRUE;
|
|
|
|
entry->offset = offset;
|
|
|
|
entry->name = write_string (node->name, strings, data, &offset2);
|
|
|
|
|
2008-08-09 14:55:32 +02:00
|
|
|
g_ir_node_build_typelib (node, module, modules,
|
2008-08-09 14:46:48 +02:00
|
|
|
strings, types, data, &offset, &offset2);
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
entry++;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
header->annotations = offset2;
|
|
|
|
|
|
|
|
g_message ("reallocating to %d bytes", offset2);
|
|
|
|
|
2008-08-21 02:42:23 +02:00
|
|
|
data = g_realloc (data, offset2);
|
|
|
|
header = (Header*) data;
|
2008-08-09 14:46:48 +02:00
|
|
|
length = header->size = offset2;
|
2008-08-21 02:42:23 +02:00
|
|
|
typelib = g_typelib_new_from_memory (data, length);
|
|
|
|
|
|
|
|
g_hash_table_destroy (strings);
|
|
|
|
g_hash_table_destroy (types);
|
|
|
|
|
|
|
|
return typelib;
|
2008-08-09 14:46:48 +02:00
|
|
|
}
|
|
|
|
|