Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/girepository/gtypelib.h
blob: ee7442f3752a83a9a459dcc6098dd0d7fd8187bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
/* GObject introspection: struct definitions for the binary
 * typelib format, validation
 *
 * 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.
 */

#ifndef __G_TYPELIB_H__
#define __G_TYPELIB_H__

#include <gmodule.h>
#include "girepository.h"

G_BEGIN_DECLS

#define G_IR_MAGIC "GOBJ\nMETADATA\r\n\032"

enum 
{
  BLOB_TYPE_INVALID,
  BLOB_TYPE_FUNCTION,
  BLOB_TYPE_CALLBACK,
  BLOB_TYPE_STRUCT,
  BLOB_TYPE_BOXED,
  BLOB_TYPE_ENUM,
  BLOB_TYPE_FLAGS,
  BLOB_TYPE_OBJECT,
  BLOB_TYPE_INTERFACE,
  BLOB_TYPE_CONSTANT,
  BLOB_TYPE_ERROR_DOMAIN,
  BLOB_TYPE_UNION
};

#define BLOB_IS_REGISTERED_TYPE(blob)               \
        ((blob)->blob_type == BLOB_TYPE_STRUCT ||   \
         (blob)->blob_type == BLOB_TYPE_UNION  ||   \
         (blob)->blob_type == BLOB_TYPE_ENUM   ||   \
         (blob)->blob_type == BLOB_TYPE_OBJECT ||   \
         (blob)->blob_type == BLOB_TYPE_INTERFACE)

typedef struct
{
  gchar   magic[16];
  guint8  major_version;
  guint8  minor_version;
  guint16 reserved;
  guint16 n_entries;
  guint16 n_local_entries;
  guint32 directory;
  guint32 n_annotations;
  guint32 annotations;

  guint32 dependencies;

  guint32 size;
  guint32 namespace;
  guint32 nsversion;
  guint32 shared_library;

  guint16 entry_blob_size;
  guint16 function_blob_size;
  guint16 callback_blob_size;
  guint16 signal_blob_size;
  guint16 vfunc_blob_size;
  guint16 arg_blob_size;
  guint16 property_blob_size;
  guint16 field_blob_size;
  guint16 value_blob_size;
  guint16 annotation_blob_size;
  guint16 constant_blob_size;
  guint16 error_domain_blob_size;

  guint16 signature_blob_size;
  guint16 enum_blob_size;
  guint16 struct_blob_size;
  guint16 object_blob_size;
  guint16 interface_blob_size;
  guint16 union_blob_size;
  
  guint16 padding[7];
} Header;

typedef struct
{
  guint16 blob_type;

  guint16 local    : 1;
  guint16 reserved :15;

  guint32 name;
  guint32 offset;
} DirEntry;


typedef union
{
  struct 
  {
    guint reserved   : 8;
    guint reserved2  :16;
    guint pointer    : 1;
    guint reserved3  : 2;
    guint tag        : 5;    
  };
  guint32    offset;
} SimpleTypeBlob;


typedef struct
{
  guint32        name;

  guint          in                           : 1;
  guint          out                          : 1;
  guint          dipper                       : 1;
  guint          allow_none                   : 1;
  guint          optional                     : 1;
  guint          transfer_ownership           : 1;
  guint          transfer_container_ownership : 1;
  guint          return_value                 : 1;
  guint          scope                        : 3;
  guint          reserved                     :21;

  gint8        closure;
  gint8        destroy;

  SimpleTypeBlob arg_type;
} ArgBlob;

typedef struct 
{
  SimpleTypeBlob return_type;

  guint16        may_return_null              : 1;
  guint16        caller_owns_return_value     : 1;
  guint16        caller_owns_return_container : 1;
  guint16        reserved                     :13;

  guint16        n_arguments;

  ArgBlob        arguments[];
} SignatureBlob;

typedef struct
{
  guint16 blob_type;  /* 1 */

  guint16 deprecated : 1;
  guint16 reserved   :15;

  guint32 name;
} CommonBlob;

typedef struct 
{
  guint16 blob_type;  /* 1 */

  guint16 deprecated  : 1;
  guint16 setter      : 1;
  guint16 getter      : 1;
  guint16 constructor : 1;
  guint16 wraps_vfunc : 1;
  guint16 throws      : 1;
  guint16 index       :10;
  /* Note the bits above need to match CommonBlob
   * and are thus exhausted, extend things using
   * the reserved block below. */

  guint32 name;
  guint32 symbol;
  guint32 signature;

  guint16 is_static   : 1;
  guint16 reserved    : 15;
  guint16 reserved2   : 16;
} FunctionBlob;

typedef struct 
{
  guint16 blob_type;  /* 2 */

  guint16 deprecated : 1;
  guint16 reserved   :15;

  guint32 name;
  guint32 signature;
} CallbackBlob;

typedef struct 
{
  guint8  pointer  :1;
  guint8  reserved :2;
  guint8  tag      :5;    
  guint8  reserved2;
  guint16 interface;  
} InterfaceTypeBlob;

typedef struct
{
  guint16 pointer         :1;
  guint16 reserved        :2;
  guint16 tag             :5;    

  guint16 zero_terminated :1;
  guint16 has_length      :1;
  guint16 has_size        :1;
  guint16 reserved2       :5;

  union {
    guint16 length;
    guint16 size;
  };

  SimpleTypeBlob type;
} ArrayTypeBlob;

typedef struct
{
  guint8  	 pointer  :1;
  guint8  	 reserved :2;
  guint8  	 tag      :5;    

  guint8  	 reserved2;
  guint16 	 n_types;

  SimpleTypeBlob type[];
} ParamTypeBlob;

typedef struct
{
  guint8  pointer  :1;
  guint8  reserved :2;
  guint8  tag      :5;    

  guint8  reserved2;
  guint16 n_domains;

  guint16 domains[];
}  ErrorTypeBlob;

typedef struct
{
  guint16 blob_type;  /* 10 */

  guint16 deprecated : 1;
  guint16 reserved   :15;
  
  guint32 name;

  guint32 get_quark;
  guint16 error_codes;
  guint16 reserved2;
} ErrorDomainBlob;

typedef struct
{
  guint32 deprecated : 1;
  guint32 reserved   :31;
  guint32 name;
  guint32 value;
} ValueBlob;

typedef struct 
{
  guint32        name;

  guint8         readable :1; 
  guint8         writable :1;
  guint8         reserved :6;
  guint8         bits;

  guint16        struct_offset;      

  SimpleTypeBlob type;
} FieldBlob;

typedef struct
{
  guint16 blob_type;  
  guint16 deprecated   : 1; 
  guint16 unregistered : 1;
  guint16 reserved :14;
  guint32 name; 

  guint32 gtype_name;
  guint32 gtype_init;
} RegisteredTypeBlob;

typedef struct
{
  guint16   blob_type;

  guint16   deprecated   : 1;
  guint16   unregistered : 1;
  guint16   is_class_struct : 1;
  guint16   alignment    : 6;  
  guint16   reserved     : 7;

  guint32   name;

  guint32   gtype_name;
  guint32   gtype_init;

  guint32   size;

  guint16   n_fields;
  guint16   n_methods;

#if 0
  /* variable-length parts of the blob */
  FieldBlob    fields[];   
  FunctionBlob methods[];
#endif
} StructBlob;

typedef struct 
{  
  guint16      blob_type; 
  guint16      deprecated    : 1;
  guint16      unregistered  : 1;
  guint16      discriminated : 1;
  guint16      alignment     : 6;
  guint16      reserved      : 7;
  guint32      name;

  guint32      gtype_name;
  guint32      gtype_init;

  guint32      size;

  guint16      n_fields;
  guint16      n_functions;

  gint32       discriminator_offset; 
  SimpleTypeBlob discriminator_type;

#if 0
  FieldBlob    fields[];   
  FunctionBlob functions[];  
  ConstantBlob discriminator_values[]
#endif
} UnionBlob;

typedef struct
{
  guint16   blob_type;

  guint16   deprecated   : 1; 
  guint16   unregistered : 1;
  guint16   storage_type : 5;
  guint16   reserved     : 9;

  guint32   name; 

  guint32   gtype_name;
  guint32   gtype_init;

  guint16   n_values;
  guint16   reserved2;

  ValueBlob values[];    
} EnumBlob;

typedef struct
{
  guint32        name;

  guint32        deprecated     : 1;
  guint32        readable       : 1;
  guint32        writable       : 1;
  guint32        construct      : 1;
  guint32        construct_only : 1;
  guint32        reserved       :27;

  SimpleTypeBlob type;

} PropertyBlob;

typedef struct
{
  guint16 deprecated        : 1;
  guint16 run_first         : 1;
  guint16 run_last          : 1;
  guint16 run_cleanup       : 1;
  guint16 no_recurse        : 1;
  guint16 detailed          : 1;
  guint16 action            : 1;
  guint16 no_hooks          : 1;
  guint16 has_class_closure : 1;
  guint16 true_stops_emit   : 1;
  guint16 reserved          : 6;

  guint16 class_closure;

  guint32 name;

  guint32 signature;
} SignalBlob;

typedef struct 
{
  guint32 name;

  guint16 must_chain_up           : 1;
  guint16 must_be_implemented     : 1;
  guint16 must_not_be_implemented : 1;
  guint16 class_closure           : 1;
  guint16 reserved                :12;
  guint16 signal;

  guint16 struct_offset;
  guint16 reserved2;
  guint32 signature;
} VFuncBlob;

typedef struct
{
  guint16   blob_type;  /* 7 */
  guint16   deprecated   : 1;
  guint16   abstract     : 1;
  guint16   reserved     :14;
  guint32   name;

  guint32   gtype_name;
  guint32   gtype_init;

  guint16   parent;
  guint16   class_struct;
  guint16   reserved2;

  guint16   n_interfaces;
  guint16   n_fields;
  guint16   n_properties;
  guint16   n_methods;
  guint16   n_signals;
  guint16   n_vfuncs;
  guint16   n_constants;

  guint16   interfaces[];
 
#if 0
  /* variable-length parts of the blob */
  FieldBlob           fields[];
  PropertyBlob        properties[];
  FunctionBlob        methods[];
  SignalBlob          signals[];
  VFuncBlob           vfuncs[];
  ConstantBlob        constants[];
#endif
} ObjectBlob;

typedef struct 
{
  guint16 blob_type;  
  guint16 deprecated   : 1;
  guint16 reserved     :15;
  guint32 name; 

  guint32 gtype_name;
  guint32 gtype_init;

  guint16 n_prerequisites;
  guint16 n_properties;
  guint16 n_methods;
  guint16 n_signals;
  guint16 n_vfuncs;
  guint16 n_constants;  

  guint16 prerequisites[];

#if 0 
  /* variable-length parts of the blob */
  PropertyBlob        properties[];
  FunctionBlob        methods[];
  SignalBlob          signals[];
  VFuncBlob           vfuncs[];
  ConstantBlob        constants[];
#endif
} InterfaceBlob;


typedef struct
{
  guint16        blob_type;
  guint16        deprecated   : 1; 
  guint16        reserved     :15;
  guint32        name; 

  SimpleTypeBlob type;

  guint32        size;
  guint32        offset;
} ConstantBlob;

typedef struct
{ 
  guint32 offset;
  guint32 name;
  guint32 value;
} AnnotationBlob;


struct _GTypelib {
  guchar *data;
  gsize len;
  gboolean owns_memory;
  GMappedFile *mfile;
  GList *modules;
};

DirEntry *g_typelib_get_dir_entry (GTypelib *typelib,
				   guint16   index);

void      g_typelib_check_sanity (void);

#define   g_typelib_get_string(typelib,offset) ((const gchar*)&(typelib->data)[(offset)])


typedef enum
{
  G_TYPELIB_ERROR_INVALID,
  G_TYPELIB_ERROR_INVALID_HEADER,
  G_TYPELIB_ERROR_INVALID_DIRECTORY,
  G_TYPELIB_ERROR_INVALID_ENTRY,
  G_TYPELIB_ERROR_INVALID_BLOB
} GTypelibError;

#define G_TYPELIB_ERROR (g_typelib_error_quark ())

GQuark g_typelib_error_quark (void);

gboolean g_typelib_validate (GTypelib  *typelib,
			     GError    **error);


G_END_DECLS

#endif  /* __G_TYPELIB_H__ */