~ubuntu-branches/ubuntu/trusty/gobject-introspection/trusty

« back to all changes in this revision

Viewing changes to girepository/gibaseinfo.c

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2011-03-22 00:32:36 UTC
  • mfrom: (1.4.1 upstream) (3.3.33 multiarch)
  • Revision ID: james.westby@ubuntu.com-20110322003236-4spdgfk1vai6xay1
Tags: 0.10.4-2
Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* GObject introspection: Repository implementation
 
1
/* GObject introspection: Base struct implementation
2
2
 *
3
3
 * Copyright (C) 2005 Matthias Clasen
4
4
 * Copyright (C) 2008,2009 Red Hat, Inc.
26
26
#include <glib-object.h>
27
27
 
28
28
#include "gitypelib-internal.h"
29
 
#include "ginfo.h"
30
29
#include "girepository-private.h"
31
30
 
32
31
#define INVALID_REFCOUNT 0x7FFFFFFF
33
32
 
 
33
/* GBoxed registration of BaseInfo. */
 
34
GType
 
35
g_base_info_gtype_get_type (void)
 
36
{
 
37
  static GType our_type = 0;
 
38
  
 
39
  if (our_type == 0)
 
40
    our_type =
 
41
        g_boxed_type_register_static ("GIBaseInfo",
 
42
                                      (GBoxedCopyFunc) g_base_info_ref,
 
43
                                      (GBoxedFreeFunc) g_base_info_unref);
 
44
 
 
45
  return our_type;
 
46
}
 
47
 
34
48
/* info creation */
35
49
GIBaseInfo *
36
 
g_info_new_full (GIInfoType     type,
37
 
                 GIRepository  *repository,
38
 
                 GIBaseInfo    *container,
39
 
                 GTypelib      *typelib,
40
 
                 guint32        offset)
 
50
_g_info_new_full (GIInfoType     type,
 
51
                  GIRepository  *repository,
 
52
                  GIBaseInfo    *container,
 
53
                  GITypelib      *typelib,
 
54
                  guint32        offset)
41
55
{
42
56
  GIRealInfo *info;
43
57
 
59
73
GIBaseInfo *
60
74
g_info_new (GIInfoType     type,
61
75
            GIBaseInfo    *container,
62
 
            GTypelib      *typelib,
 
76
            GITypelib      *typelib,
63
77
            guint32        offset)
64
78
{
65
 
  return g_info_new_full (type, ((GIRealInfo*)container)->repository, container, typelib, offset);
 
79
  return _g_info_new_full (type, ((GIRealInfo*)container)->repository, container, typelib, offset);
66
80
}
67
81
 
68
82
void
70
84
              GIInfoType      type,
71
85
              GIRepository   *repository,
72
86
              GIBaseInfo     *container,
73
 
              GTypelib       *typelib,
 
87
              GITypelib       *typelib,
74
88
              guint32         offset)
75
89
{
76
90
  memset (info, 0, sizeof (GIRealInfo));
91
105
 
92
106
GIBaseInfo *
93
107
_g_info_from_entry (GIRepository *repository,
94
 
                    GTypelib     *typelib,
 
108
                    GITypelib     *typelib,
95
109
                    guint16       index)
96
110
{
97
111
  GIBaseInfo *result;
98
112
  DirEntry *entry = g_typelib_get_dir_entry (typelib, index);
99
113
 
100
114
  if (entry->local)
101
 
    result = g_info_new_full (entry->blob_type, repository, NULL, typelib, entry->offset);
 
115
    result = _g_info_new_full (entry->blob_type, repository, NULL, typelib, entry->offset);
102
116
  else
103
117
    {
104
118
      const gchar *namespace = g_typelib_get_string (typelib, entry->offset);
126
140
  return (GIBaseInfo *)result;
127
141
}
128
142
 
 
143
GITypeInfo *
 
144
_g_type_info_new (GIBaseInfo    *container,
 
145
                 GITypelib      *typelib,
 
146
                 guint32        offset)
 
147
{
 
148
  SimpleTypeBlob *type = (SimpleTypeBlob *)&typelib->data[offset];
 
149
 
 
150
  return (GITypeInfo *) g_info_new (GI_INFO_TYPE_TYPE, container, typelib,
 
151
                                    (type->flags.reserved == 0 && type->flags.reserved2 == 0) ? offset : type->offset);
 
152
}
 
153
 
 
154
void
 
155
_g_type_info_init (GIBaseInfo *info,
 
156
                   GIBaseInfo *container,
 
157
                   GITypelib   *typelib,
 
158
                   guint32     offset)
 
159
{
 
160
  GIRealInfo *rinfo = (GIRealInfo*)container;
 
161
  SimpleTypeBlob *type = (SimpleTypeBlob *)&typelib->data[offset];
 
162
 
 
163
  _g_info_init ((GIRealInfo*)info, GI_INFO_TYPE_TYPE, rinfo->repository, container, typelib,
 
164
                (type->flags.reserved == 0 && type->flags.reserved2 == 0) ? offset : type->offset);
 
165
}
 
166
 
129
167
/* GIBaseInfo functions */
130
168
 
131
169
/**
132
170
 * SECTION:gibaseinfo
133
 
 * @Short_description: Base struct for all GTypelib structs
 
171
 * @Short_description: Base struct for all GITypelib structs
134
172
 * @Title: GIBaseInfo
135
173
 *
136
174
 * GIBaseInfo is the common base struct of all other *Info structs
157
195
 * </programlisting>
158
196
 * </example>
159
197
 *
 
198
 * <refsect1 id="gi-gibaseinfo.struct-hierarchy" role="struct_hierarchy">
 
199
 * <title role="struct_hierarchy.title">Struct hierarchy</title>
 
200
 * <synopsis>
 
201
 *   GIBaseInfo
 
202
 *    +----<link linkend="gi-GIArgInfo">GIArgInfo</link>
 
203
 *    +----<link linkend="gi-GICallableInfo">GICallableInfo</link>
 
204
 *    +----<link linkend="gi-GIConstantInfo">GIConstantInfo</link>
 
205
 *    +----<link linkend="gi-GIErrorDomainInfo">GIErrorDomainInfo</link>
 
206
 *    +----<link linkend="gi-GIFieldInfo">GIFieldInfo</link>
 
207
 *    +----<link linkend="gi-GIPropertyInfo">GIPropertyInfo</link>
 
208
 *    +----<link linkend="gi-GIRegisteredTypeInfo">GIRegisteredTypeInfo</link>
 
209
 *    +----<link linkend="gi-GITypeInfo">GITypeInfo</link>
 
210
 * </synopsis>
 
211
 * </refsect1>
 
212
 *
160
213
 */
161
214
 
162
215
/**
163
 
 * g_base_info_ref:
 
216
 * g_base_info_ref: (skip)
164
217
 * @info: a #GIBaseInfo
165
218
 *
166
219
 * Increases the reference count of @info.
179
232
}
180
233
 
181
234
/**
182
 
 * g_base_info_unref:
 
235
 * g_base_info_unref: (skip)
183
236
 * @info: a #GIBaseInfo
184
237
 *
185
238
 * Decreases the reference count of @info. When its reference count
437
490
 
438
491
static int
439
492
cmp_attribute (const void *av,
440
 
                const void *bv)
 
493
               const void *bv)
441
494
{
442
495
  const AttributeBlob *a = av;
443
496
  const AttributeBlob *b = bv;
450
503
    return 1;
451
504
}
452
505
 
453
 
static AttributeBlob *
454
 
find_first_attribute (GIRealInfo *rinfo)
 
506
/*
 
507
 * _attribute_blob_find_first:
 
508
 * @GIBaseInfo: A #GIBaseInfo.
 
509
 * @blob_offset: The offset for the blob to find the first attribute for.
 
510
 *
 
511
 * Searches for the first #AttributeBlob for @blob_offset and returns
 
512
 * it if found.
 
513
 *
 
514
 * Returns: A pointer to #AttributeBlob or %NULL if not found.
 
515
 */
 
516
AttributeBlob *
 
517
_attribute_blob_find_first (GIBaseInfo *info,
 
518
                            guint32     blob_offset)
455
519
{
 
520
  GIRealInfo *rinfo = (GIRealInfo *) info;
456
521
  Header *header = (Header *)rinfo->typelib->data;
457
522
  AttributeBlob blob, *first, *res, *previous;
458
523
 
459
 
  blob.offset = rinfo->offset;
 
524
  blob.offset = blob_offset;
460
525
 
461
526
  first = (AttributeBlob *) &rinfo->typelib->data[header->attributes];
462
527
 
467
532
    return NULL;
468
533
 
469
534
  previous = res - 1;
470
 
  while (previous >= first && previous->offset == rinfo->offset)
 
535
  while (previous >= first && previous->offset == blob_offset)
471
536
    {
472
537
      res = previous;
473
538
      previous = res - 1;
525
590
  if (iterator->data != NULL)
526
591
    next = (AttributeBlob *) iterator->data;
527
592
  else
528
 
    next = find_first_attribute (rinfo);
 
593
    next = _attribute_blob_find_first (info, rinfo->offset);
529
594
 
530
595
  if (next == NULL || next->offset != rinfo->offset || next >= after)
531
596
    return FALSE;
561
626
 *
562
627
 * Returns: (transfer none): the typelib.
563
628
 */
564
 
GTypelib *
 
629
GITypelib *
565
630
g_base_info_get_typelib (GIBaseInfo *info)
566
631
{
567
632
  return ((GIRealInfo*)info)->typelib;
589
654
  return rinfo1->typelib->data + rinfo1->offset == rinfo2->typelib->data + rinfo2->offset;
590
655
}
591
656
 
 
657