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