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