Bug 552858: versioning
[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 typedef struct
49 {
50   gchar   magic[16];
51   guint8  major_version;
52   guint8  minor_version;
53   guint16 reserved;
54   guint16 n_entries;
55   guint16 n_local_entries;
56   guint32 directory;
57   guint32 n_annotations;
58   guint32 annotations;
59
60   guint32 dependencies;
61
62   guint32 size;
63   guint32 namespace;
64   guint32 nsversion;
65   guint32 shared_library;
66
67   guint16 entry_blob_size;
68   guint16 function_blob_size;
69   guint16 callback_blob_size;
70   guint16 signal_blob_size;
71   guint16 vfunc_blob_size;
72   guint16 arg_blob_size;
73   guint16 property_blob_size;
74   guint16 field_blob_size;
75   guint16 value_blob_size;
76   guint16 annotation_blob_size;
77   guint16 constant_blob_size;
78   guint16 error_domain_blob_size;
79
80   guint16 signature_blob_size;
81   guint16 enum_blob_size;
82   guint16 struct_blob_size;
83   guint16 object_blob_size;
84   guint16 interface_blob_size;
85   guint16 union_blob_size;
86   
87   guint16 padding[7];
88 } Header;
89
90 typedef struct
91 {
92   guint16 blob_type;
93
94   guint16 local    : 1;
95   guint16 reserved :15;
96
97   guint32 name;
98   guint32 offset;
99 } DirEntry;
100
101
102 typedef union
103 {
104   struct 
105   {
106     guint reserved   : 8;
107     guint reserved2  :16;
108     guint pointer    : 1;
109     guint reserved3  : 2;
110     guint tag        : 5;    
111   };
112   guint32    offset;
113 } SimpleTypeBlob;
114
115
116 typedef struct
117 {
118   guint32        name;
119
120   guint          in                           : 1;
121   guint          out                          : 1;
122   guint          dipper                       : 1;
123   guint          null_ok                      : 1;
124   guint          optional                     : 1;
125   guint          transfer_ownership           : 1;
126   guint          transfer_container_ownership : 1;
127   guint          return_value                 : 1;
128   guint          reserved                     :24;
129
130   SimpleTypeBlob arg_type;
131 } ArgBlob;
132
133 typedef struct 
134 {
135   SimpleTypeBlob return_type;
136
137   guint16        may_return_null              : 1;
138   guint16        caller_owns_return_value     : 1;
139   guint16        caller_owns_return_container : 1;
140   guint16        reserved                     :13;
141
142   guint16        n_arguments;
143
144   ArgBlob        arguments[];
145 } SignatureBlob;
146
147 typedef struct
148 {
149   guint16 blob_type;  /* 1 */
150
151   guint16 deprecated : 1;
152   guint16 reserved   :15;
153
154   guint32 name;
155 } CommonBlob;
156
157 typedef struct 
158 {
159   guint16 blob_type;  /* 1 */
160
161   guint16 deprecated  : 1;
162   guint16 setter      : 1; 
163   guint16 getter      : 1;
164   guint16 constructor : 1;
165   guint16 wraps_vfunc : 1;
166   guint16 reserved    : 1;
167   guint16 index       :10;
168
169   guint32 name;
170   guint32 symbol;
171   guint32 signature;
172 } FunctionBlob;
173
174 typedef struct 
175 {
176   guint16 blob_type;  /* 2 */
177
178   guint16 deprecated : 1;
179   guint16 reserved   :15;
180
181   guint32 name;
182   guint32 signature;
183 } CallbackBlob;
184
185 typedef struct 
186 {
187   guint8  pointer  :1;
188   guint8  reserved :2;
189   guint8  tag      :5;    
190   guint8  reserved2;
191   guint16 interface;  
192 } InterfaceTypeBlob;
193
194 typedef struct
195 {
196   guint16 pointer         :1;
197   guint16 reserved        :2;
198   guint16 tag             :5;    
199
200   guint16 zero_terminated :1;
201   guint16 has_length      :1;
202   guint16 reserved2       :6;
203
204   guint16 length;
205
206   SimpleTypeBlob type;
207 } ArrayTypeBlob;
208
209 typedef struct
210 {
211   guint8         pointer  :1;
212   guint8         reserved :2;
213   guint8         tag      :5;    
214
215   guint8         reserved2;
216   guint16        n_types;
217
218   SimpleTypeBlob type[];
219 } ParamTypeBlob;
220
221 typedef struct
222 {
223   guint8  pointer  :1;
224   guint8  reserved :2;
225   guint8  tag      :5;    
226
227   guint8  reserved2;
228   guint16 n_domains;
229
230   guint16 domains[];
231 }  ErrorTypeBlob;
232
233 typedef struct
234 {
235   guint16 blob_type;  /* 10 */
236
237   guint16 deprecated : 1;
238   guint16 reserved   :15;
239   
240   guint32 name;
241
242   guint32 get_quark;
243   guint16 error_codes;
244   guint16 reserved2;
245 } ErrorDomainBlob;
246
247 typedef struct
248 {
249   guint32 deprecated : 1;
250   guint32 reserved   :31;
251   guint32 name;
252   guint32 value;
253 } ValueBlob;
254
255 typedef struct 
256 {
257   guint32        name;
258
259   guint8         readable :1; 
260   guint8         writable :1;
261   guint8         reserved :6;
262   guint8         bits;
263
264   guint16        struct_offset;      
265
266   SimpleTypeBlob type;
267 } FieldBlob;
268
269 typedef struct
270 {
271   guint16 blob_type;  
272   guint16 deprecated   : 1; 
273   guint16 unregistered :15;
274   guint32 name; 
275
276   guint32 gtype_name;
277   guint32 gtype_init;
278 } RegisteredTypeBlob;
279
280 typedef struct
281 {
282   guint16   blob_type;
283
284   guint16   deprecated   : 1;
285   guint16   unregistered : 1;
286   guint16   reserved     :14;
287
288   guint32   name;
289
290   guint32   gtype_name;
291   guint32   gtype_init;
292
293   guint16   n_fields;
294   guint16   n_methods;
295
296 #if 0
297   /* variable-length parts of the blob */
298   FieldBlob    fields[];   
299   FunctionBlob methods[];
300 #endif
301 } StructBlob;
302
303 typedef struct 
304 {  
305   guint16      blob_type; 
306   guint16      deprecated    : 1;
307   guint16      unregistered  : 1;
308   guint16      discriminated : 1;
309   guint16      reserved      :13;
310   guint32      name;
311
312   guint32      gtype_name;
313   guint32      gtype_init;
314
315   guint16      n_fields;
316   guint16      n_functions;
317
318   gint32       discriminator_offset; 
319   SimpleTypeBlob discriminator_type;
320
321 #if 0
322   FieldBlob    fields[];   
323   FunctionBlob functions[];  
324   ConstantBlob discriminator_values[]
325 #endif
326 } UnionBlob;
327
328 typedef struct
329 {
330   guint16   blob_type;
331
332   guint16   deprecated   : 1; 
333   guint16   unregistered : 1;
334   guint16   reserved     :14;
335
336   guint32   name; 
337
338   guint32   gtype_name;
339   guint32   gtype_init;
340
341   guint16   n_values;
342   guint16   reserved2;
343
344   ValueBlob values[];    
345 } EnumBlob;
346
347 typedef struct
348 {
349   guint32        name;
350
351   guint32        deprecated     : 1;
352   guint32        readable       : 1;
353   guint32        writable       : 1;
354   guint32        construct      : 1;
355   guint32        construct_only : 1;
356   guint32        reserved       :27;
357
358   SimpleTypeBlob type;
359
360 } PropertyBlob;
361
362 typedef struct
363 {
364   guint16 deprecated        : 1;
365   guint16 run_first         : 1;
366   guint16 run_last          : 1;
367   guint16 run_cleanup       : 1;
368   guint16 no_recurse        : 1;
369   guint16 detailed          : 1;
370   guint16 action            : 1;
371   guint16 no_hooks          : 1;
372   guint16 has_class_closure : 1;
373   guint16 true_stops_emit   : 1;
374   guint16 reserved          : 6;
375
376   guint16 class_closure;
377
378   guint32 name;
379
380   guint32 signature;
381 } SignalBlob;
382
383 typedef struct 
384 {
385   guint32 name;
386
387   guint16 must_chain_up           : 1;
388   guint16 must_be_implemented     : 1;
389   guint16 must_not_be_implemented : 1;
390   guint16 class_closure           : 1;
391   guint16 reserved                :12;
392   guint16 signal;
393
394   guint16 struct_offset;
395   guint16 reserved2;
396   guint32 signature;
397 } VFuncBlob;
398
399 typedef struct
400 {
401   guint16   blob_type;  /* 7 */
402   guint16   deprecated   : 1; 
403   guint16   reserved     :15;
404   guint32   name; 
405
406   guint32   gtype_name;
407   guint32   gtype_init;
408
409   guint16   parent;
410
411   guint16   n_interfaces;
412   guint16   n_fields;
413   guint16   n_properties;
414   guint16   n_methods;
415   guint16   n_signals;
416   guint16   n_vfuncs;
417   guint16   n_constants;
418
419   guint16   interfaces[];
420  
421 #if 0
422   /* variable-length parts of the blob */
423   FieldBlob           fields[];
424   PropertyBlob        properties[];
425   FunctionBlob        methods[];
426   SignalBlob          signals[];
427   VFuncBlob           vfuncs[];
428   ConstantBlob        constants[];
429 #endif
430 } ObjectBlob;
431
432 typedef struct 
433 {
434   guint16 blob_type;  
435   guint16 deprecated   : 1; 
436   guint16 reserved     :15;
437   guint32 name; 
438
439   guint32 gtype_name;
440   guint32 gtype_init;
441
442   guint16 n_prerequisites;
443   guint16 n_properties;
444   guint16 n_methods;
445   guint16 n_signals;
446   guint16 n_vfuncs;
447   guint16 n_constants;  
448
449   guint16 prerequisites[];
450
451 #if 0 
452   /* variable-length parts of the blob */
453   PropertyBlob        properties[];
454   FunctionBlob        methods[];
455   SignalBlob          signals[];
456   VFuncBlob           vfuncs[];
457   ConstantBlob        constants[];
458 #endif
459 } InterfaceBlob;
460
461
462 typedef struct
463 {
464   guint16        blob_type;
465   guint16        deprecated   : 1; 
466   guint16        reserved     :15;
467   guint32        name; 
468
469   SimpleTypeBlob type;
470
471   guint32        size;
472   guint32        offset;
473 } ConstantBlob;
474
475 typedef struct
476
477   guint32 offset;
478   guint32 name;
479   guint32 value;
480 } AnnotationBlob;
481
482
483 struct _GTypelib {
484   guchar *data;
485   gsize len;
486   gboolean owns_memory;
487   GMappedFile *mfile;
488   GList *modules;
489 };
490
491 DirEntry *g_typelib_get_dir_entry (GTypelib *typelib,
492                                    guint16   index);
493
494 void      g_typelib_check_sanity (void);
495
496 #define   g_typelib_get_string(typelib,offset) ((const gchar*)&(typelib->data)[(offset)])
497
498
499 typedef enum
500 {
501   G_TYPELIB_ERROR_INVALID,
502   G_TYPELIB_ERROR_INVALID_HEADER,
503   G_TYPELIB_ERROR_INVALID_DIRECTORY,
504   G_TYPELIB_ERROR_INVALID_ENTRY,
505   G_TYPELIB_ERROR_INVALID_BLOB
506 } GTypelibError;
507
508 #define G_TYPELIB_ERROR (g_typelib_error_quark ())
509
510 GQuark g_typelib_error_quark (void);
511
512 gboolean g_typelib_validate (GTypelib  *typelib,
513                              GError    **error);
514
515
516 G_END_DECLS
517
518 #endif  /* __G_TYPELIB_H__ */
519