diff options
author | Colin Walters <walters@verbum.org> | 2009-02-19 21:48:51 -0500 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2009-03-03 17:26:37 -0500 |
commit | d5215b23315e7c9c22c6a32218bb6f8027a9dd4c (patch) | |
tree | e8d9e360099c756677ad23a1039f4d05533008b9 /girepository/girnode.c | |
parent | 2bdd2bf9303ae0e718c00ec84078336e722138f1 (diff) | |
download | gobject-introspection-d5215b23315e7c9c22c6a32218bb6f8027a9dd4c.tar.gz |
Bug 571548 - Generic attributes
We now support an extensible mechanism where arbitrary key-value
pairs may be associated with almost all items, including objects,
methods, and properties.
These attributes appear in both the .gir and the .typelib.
Diffstat (limited to 'girepository/girnode.c')
-rw-r--r-- | girepository/girnode.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/girepository/girnode.c b/girepository/girnode.c index fb96d8dd..22c0aee0 100644 --- a/girepository/girnode.c +++ b/girepository/girnode.c @@ -1,6 +1,7 @@ /* GObject introspection: Typelib creation * * Copyright (C) 2005 Matthias Clasen + * Copyright (C) 2008,2009 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 @@ -184,6 +185,9 @@ g_ir_node_new (GIrNodeTypeId type) } node->type = type; + node->offset = 0; + node->attributes = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, g_free); return node; } @@ -400,6 +404,8 @@ g_ir_node_free (GIrNode *node) break; } + g_hash_table_destroy (node->attributes); + g_free (node); } @@ -540,6 +546,18 @@ g_ir_node_get_size (GIrNode *node) return size; } +static void +add_attribute_size (gpointer key, gpointer value, gpointer data) +{ + const gchar *key_str = key; + const gchar *value_str = value; + gint *size_p = data; + + *size_p += sizeof (AttributeBlob); + *size_p += ALIGN_VALUE (strlen (key_str) + 1, 4); + *size_p += ALIGN_VALUE (strlen (value_str) + 1, 4); +} + /* returns the full size of the blob including variable-size parts */ static guint32 g_ir_node_get_full_size_internal (GIrNode *parent, @@ -851,6 +869,14 @@ g_ir_node_get_full_size (GIrNode *node) return g_ir_node_get_full_size_internal (NULL, node); } +guint32 +g_ir_node_get_attribute_size (GIrNode *node) +{ + guint32 size = 0; + g_hash_table_foreach (node->attributes, add_attribute_size, &size); + return size; +} + int g_ir_node_cmp (GIrNode *node, GIrNode *other) @@ -1364,6 +1390,15 @@ g_ir_node_build_typelib (GIrNode *node, g_ir_node_compute_offsets (node, module, modules); + /* We should only be building each node once. If we do a typelib expansion, we also + * reset the offset in girmodule.c. + */ + g_assert (node->offset == 0); + node->offset = *offset; + build->offset_ordered_nodes = g_list_prepend (build->offset_ordered_nodes, node); + + build->n_attributes += g_hash_table_size (node->attributes); + switch (node->type) { case G_IR_NODE_TYPE: @@ -2232,7 +2267,8 @@ g_ir_node_build_typelib (GIrNode *node, old_offset, *offset, old_offset2, *offset2); if (*offset2 - old_offset2 + *offset - old_offset > g_ir_node_get_full_size (node)) - g_error ("exceeding space reservation !!"); + g_error ("exceeding space reservation; offset: %d (prev %d) offset2: %d (prev %d) nodesize: %d", + *offset, old_offset, *offset2, old_offset2, g_ir_node_get_full_size (node)); } /* if str is already in the pool, return previous location, otherwise write str |