5ab2acb389ec3567caebde4c369ecb70df41d9c0
[gnome.gobject-introspection] / girepository / gtypelib.h
1 /* GObject introspection: struct definitions for the binary
2  * typelib format, validation
3  *
4  * Copyright (C) 2005 Matthias Clasen
5  * Copyright (C) 2008,2009 Red Hat, Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #ifndef __G_TYPELIB_H__
24 #define __G_TYPELIB_H__
25
26 #include <gmodule.h>
27 #include "girepository.h"
28
29 G_BEGIN_DECLS
30
31 /**
32  * SECTION:gtypelib
33  * @short_description: Layout and accessors for typelib
34  * @stability: Stable
35  *
36  * The "typelib" is a binary, readonly, memory-mappable database
37  * containing reflective information about a GObject library.
38  * 
39  * The format of GObject typelib is strongly influenced by the Mozilla XPCOM 
40  * format. 
41  *
42  * Some of the differences to XPCOM include:
43  * - Type information is stored not quite as compactly (XPCOM stores it inline 
44  * in function descriptions in variable-sized blobs of 1 to n bytes. We store 
45  * 16 bits of type information for each parameter, which is enough to encode 
46  * simple types inline. Complex (e.g. recursive) types are stored out of line 
47  * in a separate list of types.
48  * - String and complex type data is stored outside of typelib entry blobs, 
49  * references are stored as offsets relative to the start of the typelib. 
50  * One possibility is to store the strings and types in a pools at the end 
51  * of the typelib. 
52  * 
53  * The typelib has the following general format.
54  *
55  * typelib ::= header, directory, blobs, annotations
56  *
57  * directory ::= list of entries
58  *
59  * entry ::= blob type, name, namespace, offset
60  * blob ::= function|callback|struct|boxed|enum|flags|object|interface|constant|errordomain|union
61  * annotations ::= list of annotations, sorted by offset 
62  * annotation ::= offset, key, value
63  *
64  * Details
65  * 
66  * We describe the fragments that make up the typelib in the form of C structs 
67  * (although some fall short of being valid C structs since they contain multiple
68  * flexible arrays).
69  */
70
71 /*
72 TYPELIB HISTORY
73 -----
74 Version 1.0
75
76 Changes since 0.9:
77 - Add padding to structures
78
79 Changes since 0.8:
80 - Add class struct concept to ObjectBlob
81 - Add is_class_struct bit to StructBlob
82
83 Changes since 0.7:
84 - Add dependencies
85
86 Changes since 0.6:
87 - rename metadata to typelib, to follow xpcom terminology
88
89 Changes since 0.5:
90 - basic type cleanup:
91   + remove GString
92   + add [u]int, [u]long, [s]size_t
93   + rename string to utf8, add filename
94 - allow blob_type to be zero for non-local entries
95
96 Changes since 0.4:
97 - add a UnionBlob
98
99 Changes since 0.3:
100 - drop short_name for ValueBlob
101
102 Changes since 0.2:
103 - make inline types 4 bytes after all, remove header->types and allow
104   types to appear anywhere
105 - allow error domains in the directory
106
107 Changes since 0.1:
108
109 - drop comments about _GOBJ_METADATA
110 - drop string pool, strings can appear anywhere
111 - use 'blob' as collective name for the various blob types
112 - rename 'type' field in blobs to 'blob_type'
113 - rename 'type_name' and 'type_init' fields to 'gtype_name', 'gtype_init'
114 - shrink directory entries to 12 bytes 
115 - merge struct and boxed blobs
116 - split interface blobs into enum, object and interface blobs
117 - add an 'unregistered' flag to struct and enum blobs
118 - add a 'wraps_vfunc' flag to function blobs and link them to 
119   the vfuncs they wrap
120 - restrict value blobs to only occur inside enums and flags again
121 - add constant blobs, allow them toplevel, in interfaces and in objects
122 - rename 'receiver_owns_value' and 'receiver_owns_container' to
123   'transfer_ownership' and 'transfer_container_ownership'
124 - add a 'struct_offset' field to virtual function and field blobs
125 - add 'dipper' and 'optional' flags to arg blobs
126 - add a 'true_stops_emit' flag to signal blobs
127 - add variable blob sizes to header
128 - store offsets to signature blobs instead of including them directly
129 - change the type offset to be measured in words rather than bytes
130 */
131
132 /**
133  * G_IR_MAGIC:
134  * 
135  * Identifying prefix for the typelib.  This was inspired by XPCOM, 
136  * which in turn borrowed from PNG.
137  */
138 #define G_IR_MAGIC "GOBJ\nMETADATA\r\n\032"
139
140 /**
141  * GTypelibBlobType:
142  * @BLOB_TYPE_INVALID: Should not appear in code
143  * @BLOB_TYPE_FUNCTION: A #FunctionBlob
144  * @BLOB_TYPE_CALLBACK: A #CallbackBlob
145  * @BLOB_TYPE_STRUCT: A #StructBlob
146  * @BLOB_TYPE_BOXED: Can be either a #StructBlob or #UnionBlob
147  * @BLOB_TYPE_ENUM: An #EnumBlob
148  * @BLOB_TYPE_FLAGS: An #EnumBlob
149  * @BLOB_TYPE_OBJECT: An #ObjectBlob
150  * @BLOB_TYPE_INTERFACE: An #InterfaceBlob
151  * @BLOB_TYPE_CONSTANT: A #ConstantBlob
152  * @BLOB_TYPE_ERROR_DOMAIN: A #ErrorDomainBlob
153  * @BLOB_TYPE_UNION: A #UnionBlob
154  * 
155  * The integral value of this enumeration appears in each "Blob"
156  * component of a typelib to identify its type.
157  */
158 typedef enum {
159   BLOB_TYPE_INVALID,
160   BLOB_TYPE_FUNCTION,
161   BLOB_TYPE_CALLBACK,
162   BLOB_TYPE_STRUCT,
163   BLOB_TYPE_BOXED,
164   BLOB_TYPE_ENUM,
165   BLOB_TYPE_FLAGS,
166   BLOB_TYPE_OBJECT,
167   BLOB_TYPE_INTERFACE,
168   BLOB_TYPE_CONSTANT,
169   BLOB_TYPE_ERROR_DOMAIN,
170   BLOB_TYPE_UNION
171 } GTypelibBlobType;
172
173 #define BLOB_IS_REGISTERED_TYPE(blob)               \
174         ((blob)->blob_type == BLOB_TYPE_STRUCT ||   \
175          (blob)->blob_type == BLOB_TYPE_UNION  ||   \
176          (blob)->blob_type == BLOB_TYPE_ENUM   ||   \
177          (blob)->blob_type == BLOB_TYPE_OBJECT ||   \
178          (blob)->blob_type == BLOB_TYPE_INTERFACE)
179
180 /**
181  * Header:
182  * @magic: See #G_IR_MAGIC.
183  * @major_version: The version of the typelib format. Minor version changes indicate 
184  * compatible changes and should still allow the typelib to be parsed 
185  * by a parser designed for the same major_version.
186  * @minor_version: See major_version.
187  * @n_entries: The number of entries in the directory.
188  * @n_local_entries: The number of entries referring to blobs in this typelib. The
189  * local entries must occur before the unresolved entries.
190  * @directory: Offset of the directory in the typelib.
191  * @n_annotations: Number of annotation blocks
192  * @annotations: Offset of the list of annotations in the typelib. 
193  * @dependencies: Offset of a single string, which is the list of
194  * dependencies, separated by the '|' character.  The
195  * dependencies are required in order to avoid having programs
196  * consuming a typelib check for an "Unresolved" type return
197  * from every API call.
198  * @size: The size in bytes of the typelib. 
199  * @namespace: Offset of the namespace string in the typelib.
200  * @nsversion: Offset of the namespace version string in the typelib.
201  * @shared_library: This field is the set of shared libraries associated
202  * with the typelib.  The entries are separated by the '|' (pipe) character.
203  * @entry_blob_size: The sizes of fixed-size blobs. Recording this information here
204  * allows to write parser which continue to work if the format is
205  * extended by adding new fields to the end of the fixed-size blobs.
206  * @function_blob_size: See above.
207  * @callback_blob_size: See above.
208  * @signal_blob_size: See above.
209  * @vfunc_blob_size: See above.
210  * @arg_blob_size: See above.
211  * @property_blob_size: See above.
212  * @field_blob_size: See above.
213  * @value_blob_size: See above.
214  * @annotation_blob_size: See above.
215  * @constant_blob_size: See above.
216  * @object_blob_size: See above.
217  * @union_blob_size: See above.
218  * @signature_blob_size: See above.
219  * @enum_blob_size: See above.
220  * @struct_blob_size: See above.
221  * @error_domain_blob_size: See above.
222  * @interface_blob_size: For variable-size blobs, the size of the struct up to the first
223  * flexible array member. Recording this information here allows to 
224  * write parser which continue to work if the format is extended by 
225  * adding new fields before the first flexible array member in 
226  * variable-size blobs.
227  * 
228  * The header structure appears exactly once at the beginning of a typelib.  It is a
229  * collection of meta-information, such as the number of entries and dependencies.  
230  */
231 typedef struct {
232   gchar   magic[16];
233   guint8  major_version;
234   guint8  minor_version;
235   guint16 reserved;
236   guint16 n_entries;
237   guint16 n_local_entries;
238   guint32 directory;
239   guint32 n_annotations;
240   guint32 annotations;
241
242   guint32 dependencies;
243
244   guint32 size;
245   guint32 namespace;
246   guint32 nsversion;
247   guint32 shared_library;
248
249   guint16 entry_blob_size;
250   guint16 function_blob_size;
251   guint16 callback_blob_size;
252   guint16 signal_blob_size;
253   guint16 vfunc_blob_size;
254   guint16 arg_blob_size;
255   guint16 property_blob_size;
256   guint16 field_blob_size;
257   guint16 value_blob_size;
258   guint16 annotation_blob_size;
259   guint16 constant_blob_size;
260   guint16 error_domain_blob_size;
261
262   guint16 signature_blob_size;
263   guint16 enum_blob_size;
264   guint16 struct_blob_size;
265   guint16 object_blob_size;
266   guint16 interface_blob_size;
267   guint16 union_blob_size;
268   
269   guint16 padding[7];
270 } Header;
271
272 /**
273  * DirEntry:
274  * @blob_type: A #GTypelibBlobType
275  * @local: Whether this entry refers to a blob in this typelib.
276  * @name: The name of the entry.
277  * @offset:   If is_local is set, this is the offset of the blob in the typelib.
278  * Otherwise, it is the offset of the namespace in which the blob has
279  * to be looked up by name.
280  * 
281  * References to directory entries are stored as 1-based 16-bit indexes.
282  * 
283  * All blobs pointed to by a directory entry start with the same layout for 
284  * the first 8 bytes (the reserved flags may be used by some blob types)
285  */
286 typedef struct {
287   guint16 blob_type;
288
289   guint16 local    : 1;
290   guint16 reserved :15;
291
292   guint32 name;
293   guint32 offset;
294 } DirEntry;
295
296 /**
297  * SimpleTypeBlob:
298  * @is_pointer: Indicates whether the type is passed by reference. 
299  * @tag: A #GITypeTag
300  * @offset:  Offset relative to header->types that points to a TypeBlob. 
301  * Unlike other offsets, this is in words (ie 32bit units) rather
302  * than bytes.
303  */
304 typedef union
305 {
306   struct 
307   {
308     guint reserved   : 8;
309     guint reserved2  :16;
310     guint pointer    : 1;
311     guint reserved3  : 2;
312     guint tag        : 5;    
313   };
314   guint32    offset;
315 } SimpleTypeBlob;
316
317 /*
318  * ArgBlob:
319  * @name: A suggested name for the parameter. 
320  * @in: The parameter is an input to the function
321  * @out: The parameter is used to return an output of the function. 
322  * Parameters can be both in and out. Out parameters implicitly 
323  * add another level of indirection to the parameter type. Ie if 
324  * the type is uint32 in an out parameter, the function actually 
325  * takes an uint32*.
326  * @dipper: The parameter is a pointer to a struct or object that will 
327  * receive an output of the function. 
328  * @allow_none: Only meaningful for types which are passed as pointers.
329  * For an in parameter, indicates if it is ok to pass NULL in, for 
330  * an out parameter, whether it may return NULL. Note that NULL is a 
331  * valid GList and GSList value, thus allow_none will normally be set
332  * for parameters of these types.
333  * @optional: For an out parameter, indicates that NULL may be passed in
334  * if the value is not needed.
335  * @transfer_ownership: For an in parameter, indicates that the function takes over 
336  * ownership of the parameter value. For an out parameter, it 
337  * indicates that the caller is responsible for freeing the return 
338  * value.
339  * @transfer_container_ownership: For container types, indicates that the
340  * ownership of the container,  but not of its contents is transferred. This is typically the case 
341  * for out parameters returning lists of statically allocated things.
342  * @is_return_value: The parameter should be considered the return value of the function. 
343  * Only out parameters can be marked as return value, and there can be 
344  * at most one per function call. If an out parameter is marked as 
345  * return value, the actual return value of the function should be 
346  * either void or a boolean indicating the success of the call.
347  * @scope: A #GIScopeType. If the parameter is of a callback type, this denotes the scope
348  * of the user_data and the callback function pointer itself
349  * (for languages that emit code at run-time).
350  * @closure: Index of the closure (user_data) parameter associated with the callback, 
351  * or -1.
352  * @destroy: Index of the destroy notfication callback parameter associated with 
353  * the callback, or -1.
354  * @arg_type: Describes the type of the parameter. See details below.
355  *
356  * Types are specified by four bytes. If the three high bytes are zero,
357  * the low byte describes a basic type, otherwise the 32bit number is an
358  * offset which points to a TypeBlob.
359  */
360 typedef struct {
361   guint32        name;
362
363   guint          in                           : 1;
364   guint          out                          : 1;
365   guint          dipper                       : 1;
366   guint          allow_none                   : 1;
367   guint          optional                     : 1;
368   guint          transfer_ownership           : 1;
369   guint          transfer_container_ownership : 1;
370   guint          return_value                 : 1;
371   guint          scope                        : 3;
372   guint          reserved                     :21;
373
374   gint8        closure;
375   gint8        destroy;
376
377   SimpleTypeBlob arg_type;
378 } ArgBlob;
379
380 /**
381  * SignatureBlob:
382  * @return_type: Describes the type of the return value. See details below.
383  * @may_return_null: Only relevant for pointer types. Indicates whether the caller
384  * must expect NULL as a return value.
385  * @caller_owns_return_value: If set, the caller is responsible for freeing the return value
386  * if it is no longer needed.
387  * @caller_owns_return_container: This flag is only relevant if the return type is a container type.
388  * If the flag is set, the caller is resonsible for freeing the 
389  * container, but not its contents.
390  * @n_arguments: The number of arguments that this function expects, also the length 
391  * of the array of ArgBlobs.
392  * @arguments: An array of ArgBlob for the arguments of the function.
393  */
394 typedef struct {
395   SimpleTypeBlob return_type;
396
397   guint16        may_return_null              : 1;
398   guint16        caller_owns_return_value     : 1;
399   guint16        caller_owns_return_container : 1;
400   guint16        reserved                     :13;
401
402   guint16        n_arguments;
403
404   ArgBlob        arguments[];
405 } SignatureBlob;
406
407 /**
408  * CommonBlob:
409  * @blob_type: A #GTypelibBlobType
410  * @deprecated: Whether the blob is deprecated.
411  * @name: The name of the blob.
412  * 
413  * The #CommonBlob is shared between #FunctionBlob,
414  * #CallbackBlob, #SignalBlob. 
415  */
416 typedef struct {
417   guint16 blob_type;  /* 1 */
418
419   guint16 deprecated : 1;
420   guint16 reserved   :15;
421
422   guint32 name;
423 } CommonBlob;
424
425 /**
426  * FunctionBlob:
427  * @blob_Type: #BLOB_TYPE_FUNCTION
428  * @symbol:   The symbol which can be used to obtain the function pointer with 
429  * dlsym().
430  * @deprecated: The function is deprecated.
431  * @setter: The function is a setter for a property. Language bindings may 
432  * prefer to not bind individual setters and rely on the generic 
433  * g_object_set().
434  * @getter: The function is a getter for a property. Language bindings may 
435  * prefer to not bind individual getters and rely on the generic 
436  * g_object_get().
437  * @constructor:The function acts as a constructor for the object it is contained 
438  * in.
439  * @wraps_vfunc: The function is a simple wrapper for a virtual function.
440  * @index: Index of the property that this function is a setter or getter of 
441  * in the array of properties of the containing interface, or index
442  * of the virtual function that this function wraps.
443  * @signature: Offset of the SignatureBlob describing the parameter types and the 
444  * return value type.
445  * @is_static: The function is a "static method"; in other words it's a pure
446  * function whose name is conceptually scoped to the object.
447  */
448 typedef struct {
449   guint16 blob_type;  /* 1 */
450
451   guint16 deprecated  : 1;
452   guint16 setter      : 1;
453   guint16 getter      : 1;
454   guint16 constructor : 1;
455   guint16 wraps_vfunc : 1;
456   guint16 throws      : 1;
457   guint16 index       :10;
458   /* Note the bits above need to match CommonBlob
459    * and are thus exhausted, extend things using
460    * the reserved block below. */
461
462   guint32 name;
463   guint32 symbol;
464   guint32 signature;
465
466   guint16 is_static   : 1;
467   guint16 reserved    : 15;
468   guint16 reserved2   : 16;
469 } FunctionBlob;
470
471 /**
472  * CallbackBlob:
473  * @signature: Offset of the #SignatureBlob describing the parameter types and the 
474  * return value type.
475  */
476 typedef struct {
477   guint16 blob_type;  /* 2 */
478
479   guint16 deprecated : 1;
480   guint16 reserved   :15;
481
482   guint32 name;
483   guint32 signature;
484 } CallbackBlob;
485
486 /**
487  * InterfaceTypeBlob:
488  * @pointer: Whether this type represents an indirection
489  * @tag: A #GITypeTag
490  * @interface: Index of the directory entry for the interface.
491  * 
492  * Types which are described by an entry in the typelib have a tag value of 21. 
493  * If the interface is an enum of flags type, is_pointer is 0, otherwise it is 1.
494  */
495 typedef struct {
496   guint8  pointer  :1;
497   guint8  reserved :2;
498   guint8  tag      :5;    
499   guint8  reserved2;
500   guint16 interface;  
501 } InterfaceTypeBlob;
502
503 /**
504  * ArrayTypeBlob:
505  * @zero_terminated: Indicates that the array must be terminated by a suitable #NULL 
506  * value. 
507  * @has_length: Indicates that length points to a parameter specifying the length 
508  * of the array. If both has_length and zero_terminated are set, the 
509  * convention is to pass -1 for the length if the array is 
510  * zero-terminated. 
511  * @length: The index of the parameter which is used to pass the length of the 
512  * array. The parameter must be an integer type and have the same 
513  * direction as this one. 
514  * @type: The type of the array elements.
515  * 
516  * Arrays have a tag value of 20. They are passed by reference, thus is_pointer 
517  * is always 1.
518  */
519 typedef struct {
520   guint16 pointer         :1;
521   guint16 reserved        :2;
522   guint16 tag             :5;    
523
524   guint16 zero_terminated :1;
525   guint16 has_length      :1;
526   guint16 has_size        :1;
527   guint16 reserved2       :5;
528
529   union {
530     guint16 length;
531     guint16 size;
532   };
533
534   SimpleTypeBlob type;
535 } ArrayTypeBlob;
536
537 /**
538  * ParamTypeBlob:
539  * @n_types: The number of parameter types to follow.
540  * @type: Describes the type of the list elements.
541  * 
542  */
543 typedef struct {
544   guint8         pointer  :1;
545   guint8         reserved :2;
546   guint8         tag      :5;    
547
548   guint8         reserved2;
549   guint16        n_types;
550
551   SimpleTypeBlob type[];
552 } ParamTypeBlob;
553
554 /**
555  * ErrorTypeBlob:
556  * @n_domains: The number of domains to follow
557  * @domains:  Indices of the directory entries for the error domains
558  */
559 typedef struct {
560   guint8  pointer  :1;
561   guint8  reserved :2;
562   guint8  tag      :5;    
563
564   guint8  reserved2;
565   guint16 n_domains;
566
567   guint16 domains[];
568 }  ErrorTypeBlob;
569
570 /**
571  * ErrorDomainBlob:
572  * @get_quark: The symbol name of the function which must be called to obtain the 
573  * GQuark for the error domain.
574  * @error_codes: Index of the InterfaceBlob describing the enumeration which lists
575  * the possible error codes.
576  */
577 typedef struct {
578   guint16 blob_type;  /* 10 */
579
580   guint16 deprecated : 1;
581   guint16 reserved   :15;
582   
583   guint32 name;
584
585   guint32 get_quark;
586   guint16 error_codes;
587   guint16 reserved2;
588 } ErrorDomainBlob;
589
590 /**
591  * ValueBlob:
592  * @deprecated: Whether this value is deprecated
593  * @value: The numerical value
594  * @name: Name of blob
595  * 
596  * Values commonly occur in enums and flags.
597  */
598 typedef struct {
599   guint32 deprecated : 1;
600   guint32 reserved   :31;
601   guint32 name;
602   guint32 value;
603 } ValueBlob;
604
605 /**
606  * FieldBlob:
607  * @name: The name of the field.
608  * @readable:
609  * @writable: How the field may be accessed.
610  * @bits: If this field is part of a bitfield, the number of bits which it
611  * uses, otherwise 0.
612  * @struct_offset:
613  * The offset of the field in the struct. The value 0xFFFF indicates
614  * that the struct offset is unknown.
615  * @type: The type of the field.
616  */
617 typedef struct {
618   guint32        name;
619
620   guint8         readable :1; 
621   guint8         writable :1;
622   guint8         reserved :6;
623   guint8         bits;
624
625   guint16        struct_offset;      
626
627   SimpleTypeBlob type;
628 } FieldBlob;
629
630 /**
631  * RegisteredTypeBlob:
632  * @gtype_name: The name under which the type is registered with GType.
633  * @gtype_init: The symbol name of the get_type() function which registers the type.
634  */
635 typedef struct {
636   guint16 blob_type;  
637   guint16 deprecated   : 1; 
638   guint16 unregistered : 1;
639   guint16 reserved :14;
640   guint32 name; 
641
642   guint32 gtype_name;
643   guint32 gtype_init;
644 } RegisteredTypeBlob;
645
646 /**
647  * StructBlob:
648  * @blob_type: #BLOB_TYPE_STRUCT
649  * @deprecated: Whether this structure is deprecated
650  * @unregistered: If this is set, the type is not registered with GType.
651  * @alignment: The byte boundary that the struct is aligned to in memory
652  * @is_class_struct: Whether this structure is the "class structure" for a GObject
653  * @size: The size of the struct in bytes.
654  * @gtype_name: String name of the associated #GType
655  * @gtype_init: String naming the symbol which gets the runtime #GType
656  * @n_fields: 
657  * @n_functions: The lengths of the arrays.
658  * @fields: An array of n_fields FieldBlobs. 
659  * @functions: An array of n_functions FunctionBlobs. The described functions 
660  * should be considered as methods of the struct.
661  */
662 typedef struct {
663   guint16   blob_type;
664
665   guint16   deprecated   : 1;
666   guint16   unregistered : 1;
667   guint16   is_class_struct : 1;
668   guint16   alignment    : 6;  
669   guint16   reserved     : 7;
670
671   guint32   name;
672
673   guint32   gtype_name;
674   guint32   gtype_init;
675
676   guint32   size;
677
678   guint16   n_fields;
679   guint16   n_methods;
680
681 #if 0
682   /* variable-length parts of the blob */
683   FieldBlob    fields[];   
684   FunctionBlob methods[];
685 #endif
686 } StructBlob;
687
688 /**
689  * UnionBlob;
690  * @unregistered: If this is set, the type is not registered with GType.
691  * @discriminated: Is set if the union is discriminated
692  * @alignment: The byte boundary that the union is aligned to in memory
693  * @size: The size of the union in bytes.
694  * @gtype_name: String name of the associated #GType
695  * @gtype_init: String naming the symbol which gets the runtime #GType
696  * @n_fields: Length of the arrays
697  * @discriminator_offset: Offset from the beginning of the union where the
698  * discriminator of a discriminated union is located.
699  * The value 0xFFFF indicates that the discriminator offset
700  * is unknown.
701  * @discriminator_type: Type of the discriminator 
702  * @discriminator_values: On discriminator value per field
703  * @fields: Array of FieldBlobs describing the alternative branches of the union
704  */
705 typedef struct {
706   guint16      blob_type; 
707   guint16      deprecated    : 1;
708   guint16      unregistered  : 1;
709   guint16      discriminated : 1;
710   guint16      alignment     : 6;
711   guint16      reserved      : 7;
712   guint32      name;
713
714   guint32      gtype_name;
715   guint32      gtype_init;
716
717   guint32      size;
718
719   guint16      n_fields;
720   guint16      n_functions;
721
722   gint32       discriminator_offset; 
723   SimpleTypeBlob discriminator_type;
724
725 #if 0
726   FieldBlob    fields[];   
727   FunctionBlob functions[];  
728   ConstantBlob discriminator_values[]
729 #endif
730 } UnionBlob;
731
732 /**
733  * EnumBlob:
734  * @unregistered: If this is set, the type is not registered with GType.
735  * @storage_type: The tag of the type used for the enum in the C ABI
736  * (will be a signed or unsigned integral type)
737  * @gtype_name: String name of the associated #GType
738  * @gtype_init: String naming the symbol which gets the runtime #GType
739  * @n_values: The lengths of the values arrays.
740  * @values: Describes the enum values. 
741  */
742 typedef struct {
743   guint16   blob_type;
744
745   guint16   deprecated   : 1; 
746   guint16   unregistered : 1;
747   guint16   storage_type : 5;
748   guint16   reserved     : 9;
749
750   guint32   name; 
751
752   guint32   gtype_name;
753   guint32   gtype_init;
754
755   guint16   n_values;
756   guint16   reserved2;
757
758   ValueBlob values[];    
759 } EnumBlob;
760
761 /**
762  * PropertyBlob:
763  * @name:     The name of the property. 
764  * @readable:
765  * @writable: 
766  * @construct: 
767  * @construct_only: The ParamFlags used when registering the property.
768  * @type: Describes the type of the property.
769  */
770 typedef struct {
771   guint32        name;
772
773   guint32        deprecated     : 1;
774   guint32        readable       : 1;
775   guint32        writable       : 1;
776   guint32        construct      : 1;
777   guint32        construct_only : 1;
778   guint32        reserved       :27;
779
780   SimpleTypeBlob type;
781
782 } PropertyBlob;
783
784 /**
785  * SignalBlob:
786  * @name: The name of the signal.
787  * @run_first:
788  * @run_last:
789  * @run_cleanup:
790  * @no_recurse:
791  * @detailed:
792  * @action:
793  * @no_hooks: The flags used when registering the signal.
794  * @has_class_closure: Set if the signal has a class closure.
795  * @true_stops_emit: Whether the signal has true-stops-emit semantics
796  * @class_closure: The index of the class closure in the list of virtual functions
797  * of the object or interface on which the signal is defined.
798  * @signature: Offset of the SignatureBlob describing the parameter types and the 
799  * return value type.
800  */
801 typedef struct {
802   guint16 deprecated        : 1;
803   guint16 run_first         : 1;
804   guint16 run_last          : 1;
805   guint16 run_cleanup       : 1;
806   guint16 no_recurse        : 1;
807   guint16 detailed          : 1;
808   guint16 action            : 1;
809   guint16 no_hooks          : 1;
810   guint16 has_class_closure : 1;
811   guint16 true_stops_emit   : 1;
812   guint16 reserved          : 6;
813
814   guint16 class_closure;
815
816   guint32 name;
817
818   guint32 signature;
819 } SignalBlob;
820
821 /**
822  * VFuncBlob:
823  * @name: The name of the virtual function.
824  * @must_chain_up: If set, every implementation of this virtual function must
825  * chain up to the implementation of the parent class. 
826  * @must_be_implemented: If set, every derived class must override this virtual function.
827  * @must_not_be_implemented: If set, derived class must not override this virtual function.
828  * @class_closure: Set if this virtual function is the class closure of a signal.
829  * @signal: The index of the signal in the list of signals of the object or 
830  * interface to which this virtual function belongs.
831  * @struct_offset:
832  * The offset of the function pointer in the class struct. The value
833  * 0xFFFF indicates that the struct offset is unknown.
834  * @signature: 
835  * Offset of the SignatureBlob describing the parameter types and the 
836  * return value type. 
837  */
838 typedef struct {
839   guint32 name;
840
841   guint16 must_chain_up           : 1;
842   guint16 must_be_implemented     : 1;
843   guint16 must_not_be_implemented : 1;
844   guint16 class_closure           : 1;
845   guint16 reserved                :12;
846   guint16 signal;
847
848   guint16 struct_offset;
849   guint16 reserved2;
850   guint32 signature;
851 } VFuncBlob;
852
853 /**
854  * ObjectBlob:
855  * @blob_type: #BLOB_TYPE_OBJECT
856  * @gtype_name: String name of the associated #GType
857  * @gtype_init: String naming the symbol which gets the runtime #GType
858  * @parent: The directory index of the parent type. This is only set for 
859  * objects. If an object does not have a parent, it is zero.
860  * @n_interfaces:
861  * @n_fields: 
862  * @n_properties:
863  * @n_methods:
864  * @n_signals:
865  * @n_vfuncs:
866  * @n_constants: The lengths of the arrays.Up to 16bits of padding may be inserted 
867  * between the arrays to ensure that they start on a 32bit boundary.
868  * @interfaces: An array of indices of directory entries for the implemented 
869  * interfaces.
870  * @fields: Describes the fields. 
871  * @methods: Describes the methods, constructors, setters and getters.
872  * @properties: Describes the properties.
873  * @signals: Describes the signals.
874  * @vfuncs: Describes the virtual functions.
875  * @constants: Describes the constants.
876  */
877 typedef struct {
878   guint16   blob_type;  /* 7 */
879   guint16   deprecated   : 1;
880   guint16   abstract     : 1;
881   guint16   reserved     :14;
882   guint32   name;
883
884   guint32   gtype_name;
885   guint32   gtype_init;
886
887   guint16   parent;
888   guint16   class_struct;
889   guint16   reserved2;
890
891   guint16   n_interfaces;
892   guint16   n_fields;
893   guint16   n_properties;
894   guint16   n_methods;
895   guint16   n_signals;
896   guint16   n_vfuncs;
897   guint16   n_constants;
898
899   guint16   interfaces[];
900  
901 #if 0
902   /* variable-length parts of the blob */
903   FieldBlob           fields[];
904   PropertyBlob        properties[];
905   FunctionBlob        methods[];
906   SignalBlob          signals[];
907   VFuncBlob           vfuncs[];
908   ConstantBlob        constants[];
909 #endif
910 } ObjectBlob;
911
912 /**
913  * InterfaceBlob:
914  * @n_prerequisites: Number of prerequisites
915  * @n_properties: Number of properties
916  * @n_methods: Number of methods
917  * @n_signals: Number of signals
918  * @n_vfuncs: Number of virtual functions
919  * @n_constants: The lengths of the arrays.
920  * Up to 16bits of padding may be inserted between the arrays to ensure that they
921  * start on a 32bit boundary.
922  * @prerequisites: An array of indices of directory entries for required interfaces.
923  * @methods: Describes the methods, constructors, setters and getters.
924  * @properties: Describes the properties.
925  * @signals:  Describes the signals.
926  * @vfuncs: Describes the virtual functions.
927  * @constants: Describes the constants.
928  */
929 typedef struct {
930   guint16 blob_type;  
931   guint16 deprecated   : 1;
932   guint16 reserved     :15;
933   guint32 name; 
934
935   guint32 gtype_name;
936   guint32 gtype_init;
937
938   guint16 n_prerequisites;
939   guint16 n_properties;
940   guint16 n_methods;
941   guint16 n_signals;
942   guint16 n_vfuncs;
943   guint16 n_constants;  
944
945   guint16 prerequisites[];
946
947 #if 0 
948   /* variable-length parts of the blob */
949   PropertyBlob        properties[];
950   FunctionBlob        methods[];
951   SignalBlob          signals[];
952   VFuncBlob           vfuncs[];
953   ConstantBlob        constants[];
954 #endif
955 } InterfaceBlob;
956
957 /**
958  * ConstantBlob:
959  * @type: The type of the value. In most cases this should be a numeric
960  * type or string.
961  * @size: The size of the value in bytes.
962  * @offset: The offset of the value in the typelib.
963  */
964 typedef struct {
965   guint16        blob_type;
966   guint16        deprecated   : 1; 
967   guint16        reserved     :15;
968   guint32        name; 
969
970   SimpleTypeBlob type;
971
972   guint32        size;
973   guint32        offset;
974 } ConstantBlob;
975
976 /**
977  * AnnotationBlob:
978  * @offset: The offset of the typelib entry to which this annotation refers.
979  * Annotations are kept sorted by offset, so that the annotations
980  * of an entry can be found by a binary search.
981  * @name: The name of the annotation, a string.
982  * @value: The value of the annotation (also a string)
983  */
984 typedef struct {
985   guint32 offset;
986   guint32 name;
987   guint32 value;
988 } AnnotationBlob;
989
990 struct _GTypelib {
991   guchar *data;
992   gsize len;
993   gboolean owns_memory;
994   GMappedFile *mfile;
995   GList *modules;
996 };
997
998 DirEntry *g_typelib_get_dir_entry (GTypelib *typelib,
999                                    guint16   index);
1000
1001 void      g_typelib_check_sanity (void);
1002
1003 #define   g_typelib_get_string(typelib,offset) ((const gchar*)&(typelib->data)[(offset)])
1004
1005
1006 typedef enum
1007 {
1008   G_TYPELIB_ERROR_INVALID,
1009   G_TYPELIB_ERROR_INVALID_HEADER,
1010   G_TYPELIB_ERROR_INVALID_DIRECTORY,
1011   G_TYPELIB_ERROR_INVALID_ENTRY,
1012   G_TYPELIB_ERROR_INVALID_BLOB
1013 } GTypelibError;
1014
1015 #define G_TYPELIB_ERROR (g_typelib_error_quark ())
1016
1017 GQuark g_typelib_error_quark (void);
1018
1019 gboolean g_typelib_validate (GTypelib  *typelib,
1020                              GError    **error);
1021
1022
1023 G_END_DECLS
1024
1025 #endif  /* __G_TYPELIB_H__ */
1026