Bug 551738 - Associate classes with their structs
[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  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 #ifndef __G_TYPELIB_H__
23 #define __G_TYPELIB_H__
24
25 #include <gmodule.h>
26 #include "girepository.h"
27
28 G_BEGIN_DECLS
29
30 #define G_IR_MAGIC "GOBJ\nMETADATA\r\n\032"
31
32 enum 
33 {
34   BLOB_TYPE_INVALID,
35   BLOB_TYPE_FUNCTION,
36   BLOB_TYPE_CALLBACK,
37   BLOB_TYPE_STRUCT,
38   BLOB_TYPE_BOXED,
39   BLOB_TYPE_ENUM,
40   BLOB_TYPE_FLAGS,
41   BLOB_TYPE_OBJECT,
42   BLOB_TYPE_INTERFACE,
43   BLOB_TYPE_CONSTANT,
44   BLOB_TYPE_ERROR_DOMAIN,
45   BLOB_TYPE_UNION
46 };
47
48 #define BLOB_IS_REGISTERED_TYPE(blob)               \
49         ((blob)->blob_type == BLOB_TYPE_STRUCT ||   \
50          (blob)->blob_type == BLOB_TYPE_UNION  ||   \
51          (blob)->blob_type == BLOB_TYPE_ENUM   ||   \
52          (blob)->blob_type == BLOB_TYPE_OBJECT ||   \
53          (blob)->blob_type == BLOB_TYPE_INTERFACE)
54
55 typedef struct
56 {
57   gchar   magic[16];
58   guint8  major_version;
59   guint8  minor_version;
60   guint16 reserved;
61   guint16 n_entries;
62   guint16 n_local_entries;
63   guint32 directory;
64   guint32 n_annotations;
65   guint32 annotations;
66
67   guint32 dependencies;
68
69   guint32 size;
70   guint32 namespace;
71   guint32 nsversion;
72   guint32 shared_library;
73
74   guint16 entry_blob_size;
75   guint16 function_blob_size;
76   guint16 callback_blob_size;
77   guint16 signal_blob_size;
78   guint16 vfunc_blob_size;
79   guint16 arg_blob_size;
80   guint16 property_blob_size;
81   guint16 field_blob_size;
82   guint16 value_blob_size;
83   guint16 annotation_blob_size;
84   guint16 constant_blob_size;
85   guint16 error_domain_blob_size;
86
87   guint16 signature_blob_size;
88   guint16 enum_blob_size;
89   guint16 struct_blob_size;
90   guint16 object_blob_size;
91   guint16 interface_blob_size;
92   guint16 union_blob_size;
93   
94   guint16 padding[7];
95 } Header;
96
97 typedef struct
98 {
99   guint16 blob_type;
100
101   guint16 local    : 1;
102   guint16 reserved :15;
103
104   guint32 name;
105   guint32 offset;
106 } DirEntry;
107
108
109 typedef union
110 {
111   struct 
112   {
113     guint reserved   : 8;
114     guint reserved2  :16;
115     guint pointer    : 1;
116     guint reserved3  : 2;
117     guint tag        : 5;    
118   };
119   guint32    offset;
120 } SimpleTypeBlob;
121
122
123 typedef struct
124 {
125   guint32        name;
126
127   guint          in                           : 1;
128   guint          out                          : 1;
129   guint          dipper                       : 1;
130   guint          allow_none                   : 1;
131   guint          optional                     : 1;
132   guint          transfer_ownership           : 1;
133   guint          transfer_container_ownership : 1;
134   guint          return_value                 : 1;
135   guint          scope                        : 3;
136   guint          reserved                     :21;
137
138   gint8        closure;
139   gint8        destroy;
140
141   SimpleTypeBlob arg_type;
142 } ArgBlob;
143
144 typedef struct 
145 {
146   SimpleTypeBlob return_type;
147
148   guint16        may_return_null              : 1;
149   guint16        caller_owns_return_value     : 1;
150   guint16        caller_owns_return_container : 1;
151   guint16        reserved                     :13;
152
153   guint16        n_arguments;
154
155   ArgBlob        arguments[];
156 } SignatureBlob;
157
158 typedef struct
159 {
160   guint16 blob_type;  /* 1 */
161
162   guint16 deprecated : 1;
163   guint16 reserved   :15;
164
165   guint32 name;
166 } CommonBlob;
167
168 typedef struct 
169 {
170   guint16 blob_type;  /* 1 */
171
172   guint16 deprecated  : 1;
173   guint16 setter      : 1;
174   guint16 getter      : 1;
175   guint16 constructor : 1;
176   guint16 wraps_vfunc : 1;
177   guint16 throws      : 1;
178   guint16 index       :10;
179   /* Note the bits above need to match CommonBlob
180    * and are thus exhausted, extend things using
181    * the reserved block below. */
182
183   guint32 name;
184   guint32 symbol;
185   guint32 signature;
186
187   guint16 is_static   : 1;
188   guint16 reserved    : 15;
189   guint16 reserved2   : 16;
190 } FunctionBlob;
191
192 typedef struct 
193 {
194   guint16 blob_type;  /* 2 */
195
196   guint16 deprecated : 1;
197   guint16 reserved   :15;
198
199   guint32 name;
200   guint32 signature;
201 } CallbackBlob;
202
203 typedef struct 
204 {
205   guint8  pointer  :1;
206   guint8  reserved :2;
207   guint8  tag      :5;    
208   guint8  reserved2;
209   guint16 interface;  
210 } InterfaceTypeBlob;
211
212 typedef struct
213 {
214   guint16 pointer         :1;
215   guint16 reserved        :2;
216   guint16 tag             :5;    
217
218   guint16 zero_terminated :1;
219   guint16 has_length      :1;
220   guint16 has_size        :1;
221   guint16 reserved2       :5;
222
223   union {
224     guint16 length;
225     guint16 size;
226   };
227
228   SimpleTypeBlob type;
229 } ArrayTypeBlob;
230
231 typedef struct
232 {
233   guint8         pointer  :1;
234   guint8         reserved :2;
235   guint8         tag      :5;    
236
237   guint8         reserved2;
238   guint16        n_types;
239
240   SimpleTypeBlob type[];
241 } ParamTypeBlob;
242
243 typedef struct
244 {
245   guint8  pointer  :1;
246   guint8  reserved :2;
247   guint8  tag      :5;    
248
249   guint8  reserved2;
250   guint16 n_domains;
251
252   guint16 domains[];
253 }  ErrorTypeBlob;
254
255 typedef struct
256 {
257   guint16 blob_type;  /* 10 */
258
259   guint16 deprecated : 1;
260   guint16 reserved   :15;
261   
262   guint32 name;
263
264   guint32 get_quark;
265   guint16 error_codes;
266   guint16 reserved2;
267 } ErrorDomainBlob;
268
269 typedef struct
270 {
271   guint32 deprecated : 1;
272   guint32 reserved   :31;
273   guint32 name;
274   guint32 value;
275 } ValueBlob;
276
277 typedef struct 
278 {
279   guint32        name;
280
281   guint8         readable :1; 
282   guint8         writable :1;
283   guint8         reserved :6;
284   guint8         bits;
285
286   guint16        struct_offset;      
287
288   SimpleTypeBlob type;
289 } FieldBlob;
290
291 typedef struct
292 {
293   guint16 blob_type;  
294   guint16 deprecated   : 1; 
295   guint16 unregistered : 1;
296   guint16 reserved :14;
297   guint32 name; 
298
299   guint32 gtype_name;
300   guint32 gtype_init;
301 } RegisteredTypeBlob;
302
303 typedef struct
304 {
305   guint16   blob_type;
306
307   guint16   deprecated   : 1;
308   guint16   unregistered : 1;
309   guint16   is_class_struct : 1;
310   guint16   alignment    : 6;  
311   guint16   reserved     : 7;
312
313   guint32   name;
314
315   guint32   gtype_name;
316   guint32   gtype_init;
317
318   guint32   size;
319
320   guint16   n_fields;
321   guint16   n_methods;
322
323 #if 0
324   /* variable-length parts of the blob */
325   FieldBlob    fields[];   
326   FunctionBlob methods[];
327 #endif
328 } StructBlob;
329
330 typedef struct 
331 {  
332   guint16      blob_type; 
333   guint16      deprecated    : 1;
334   guint16      unregistered  : 1;
335   guint16      discriminated : 1;
336   guint16      alignment     : 6;
337   guint16      reserved      : 7;
338   guint32      name;
339
340   guint32      gtype_name;
341   guint32      gtype_init;
342
343   guint32      size;
344
345   guint16      n_fields;
346   guint16      n_functions;
347
348   gint32       discriminator_offset; 
349   SimpleTypeBlob discriminator_type;
350
351 #if 0
352   FieldBlob    fields[];   
353   FunctionBlob functions[];  
354   ConstantBlob discriminator_values[]
355 #endif
356 } UnionBlob;
357
358 typedef struct
359 {
360   guint16   blob_type;
361
362   guint16   deprecated   : 1; 
363   guint16   unregistered : 1;
364   guint16   storage_type : 5;
365   guint16   reserved     : 9;
366
367   guint32   name; 
368
369   guint32   gtype_name;
370   guint32   gtype_init;
371
372   guint16   n_values;
373   guint16   reserved2;
374
375   ValueBlob values[];    
376 } EnumBlob;
377
378 typedef struct
379 {
380   guint32        name;
381
382   guint32        deprecated     : 1;
383   guint32        readable       : 1;
384   guint32        writable       : 1;
385   guint32        construct      : 1;
386   guint32        construct_only : 1;
387   guint32        reserved       :27;
388
389   SimpleTypeBlob type;
390
391 } PropertyBlob;
392
393 typedef struct
394 {
395   guint16 deprecated        : 1;
396   guint16 run_first         : 1;
397   guint16 run_last          : 1;
398   guint16 run_cleanup       : 1;
399   guint16 no_recurse        : 1;
400   guint16 detailed          : 1;
401   guint16 action            : 1;
402   guint16 no_hooks          : 1;
403   guint16 has_class_closure : 1;
404   guint16 true_stops_emit   : 1;
405   guint16 reserved          : 6;
406
407   guint16 class_closure;
408
409   guint32 name;
410
411   guint32 signature;
412 } SignalBlob;
413
414 typedef struct 
415 {
416   guint32 name;
417
418   guint16 must_chain_up           : 1;
419   guint16 must_be_implemented     : 1;
420   guint16 must_not_be_implemented : 1;
421   guint16 class_closure           : 1;
422   guint16 reserved                :12;
423   guint16 signal;
424
425   guint16 struct_offset;
426   guint16 reserved2;
427   guint32 signature;
428 } VFuncBlob;
429
430 typedef struct
431 {
432   guint16   blob_type;  /* 7 */
433   guint16   deprecated   : 1;
434   guint16   abstract     : 1;
435   guint16   reserved     :14;
436   guint32   name;
437
438   guint32   gtype_name;
439   guint32   gtype_init;
440
441   guint16   parent;
442   guint16   class_struct;
443   guint16   reserved2;
444
445   guint16   n_interfaces;
446   guint16   n_fields;
447   guint16   n_properties;
448   guint16   n_methods;
449   guint16   n_signals;
450   guint16   n_vfuncs;
451   guint16   n_constants;
452
453   guint16   interfaces[];
454  
455 #if 0
456   /* variable-length parts of the blob */
457   FieldBlob           fields[];
458   PropertyBlob        properties[];
459   FunctionBlob        methods[];
460   SignalBlob          signals[];
461   VFuncBlob           vfuncs[];
462   ConstantBlob        constants[];
463 #endif
464 } ObjectBlob;
465
466 typedef struct 
467 {
468   guint16 blob_type;  
469   guint16 deprecated   : 1;
470   guint16 reserved     :15;
471   guint32 name; 
472
473   guint32 gtype_name;
474   guint32 gtype_init;
475
476   guint16 n_prerequisites;
477   guint16 n_properties;
478   guint16 n_methods;
479   guint16 n_signals;
480   guint16 n_vfuncs;
481   guint16 n_constants;  
482
483   guint16 prerequisites[];
484
485 #if 0 
486   /* variable-length parts of the blob */
487   PropertyBlob        properties[];
488   FunctionBlob        methods[];
489   SignalBlob          signals[];
490   VFuncBlob           vfuncs[];
491   ConstantBlob        constants[];
492 #endif
493 } InterfaceBlob;
494
495
496 typedef struct
497 {
498   guint16        blob_type;
499   guint16        deprecated   : 1; 
500   guint16        reserved     :15;
501   guint32        name; 
502
503   SimpleTypeBlob type;
504
505   guint32        size;
506   guint32        offset;
507 } ConstantBlob;
508
509 typedef struct
510
511   guint32 offset;
512   guint32 name;
513   guint32 value;
514 } AnnotationBlob;
515
516
517 struct _GTypelib {
518   guchar *data;
519   gsize len;
520   gboolean owns_memory;
521   GMappedFile *mfile;
522   GList *modules;
523 };
524
525 DirEntry *g_typelib_get_dir_entry (GTypelib *typelib,
526                                    guint16   index);
527
528 void      g_typelib_check_sanity (void);
529
530 #define   g_typelib_get_string(typelib,offset) ((const gchar*)&(typelib->data)[(offset)])
531
532
533 typedef enum
534 {
535   G_TYPELIB_ERROR_INVALID,
536   G_TYPELIB_ERROR_INVALID_HEADER,
537   G_TYPELIB_ERROR_INVALID_DIRECTORY,
538   G_TYPELIB_ERROR_INVALID_ENTRY,
539   G_TYPELIB_ERROR_INVALID_BLOB
540 } GTypelibError;
541
542 #define G_TYPELIB_ERROR (g_typelib_error_quark ())
543
544 GQuark g_typelib_error_quark (void);
545
546 gboolean g_typelib_validate (GTypelib  *typelib,
547                              GError    **error);
548
549
550 G_END_DECLS
551
552 #endif  /* __G_TYPELIB_H__ */
553