Imported Upstream version 3.21.91
[platform/upstream/python-gobject.git] / gi / pygi-info.c
1 /* -*- Mode: C; c-basic-offset: 4 -*-
2  * vim: tabstop=4 shiftwidth=4 expandtab
3  *
4  * Copyright (C) 2005-2009 Johan Dahlin <johan@gnome.org>
5  * Copyright (C) 2013 Simon Feltman <sfeltman@gnome.org>
6  *
7  *   pygi-info.c: GI.*Info wrappers.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21  */
22
23 #include "pygi-info.h"
24 #include "pygi-cache.h"
25 #include "pygi-invoke.h"
26 #include "pygi-type.h"
27 #include "pygi-argument.h"
28 #include "pygi-util.h"
29 #include "pygtype.h"
30
31 #include <pyglib-python-compat.h>
32
33
34 /* _generate_doc_string
35  *
36  * C wrapper to call Python implemented "gi.docstring.generate_doc_string"
37  */
38 static PyObject *
39 _generate_doc_string(PyGIBaseInfo *self)
40 {
41     static PyObject *_py_generate_doc_string = NULL;
42
43     if (_py_generate_doc_string == NULL) {
44         PyObject *mod = PyImport_ImportModule ("gi.docstring");
45         if (!mod)
46             return NULL;
47
48         _py_generate_doc_string = PyObject_GetAttrString (mod, "generate_doc_string");
49         if (_py_generate_doc_string == NULL) {
50             Py_DECREF (mod);
51             return NULL;
52         }
53         Py_DECREF (mod);
54     }
55
56     return PyObject_CallFunctionObjArgs (_py_generate_doc_string, self, NULL);
57 }
58
59 static PyObject *
60 _get_info_string (PyGIBaseInfo *self,
61                   const gchar* (*get_info_string)(GIBaseInfo*))
62 {
63     const gchar *value = get_info_string ((GIBaseInfo*)self->info);
64     if (value == NULL) {
65         Py_RETURN_NONE;
66     }
67     return PYGLIB_PyUnicode_FromString (value);
68 }
69
70 static PyObject *
71 _get_child_info (PyGIBaseInfo *self,
72                  GIBaseInfo* (*get_child_info)(GIBaseInfo*))
73 {
74     GIBaseInfo *info;
75     PyObject *py_info;
76
77     info = get_child_info ((GIBaseInfo*)self->info);
78     if (info == NULL) {
79         Py_RETURN_NONE;
80     }
81
82     py_info = _pygi_info_new (info);
83     g_base_info_unref (info);
84     return py_info;
85 }
86
87
88 static PyObject *
89 _get_child_info_by_name (PyGIBaseInfo *self, PyObject *py_name,
90                          GIBaseInfo* (*get_child_info_by_name)(GIBaseInfo*, const gchar*))
91 {
92     GIBaseInfo *info;
93     PyObject *py_info;
94     char *name;
95
96     if (!PYGLIB_PyUnicode_Check (py_name)) {
97         PyErr_SetString (PyExc_TypeError, "expected string name");
98         return NULL;
99     }
100
101     name = PYGLIB_PyUnicode_AsString (py_name);
102     info = get_child_info_by_name ((GIObjectInfo*)self->info, name);
103     if (info == NULL) {
104         Py_RETURN_NONE;
105     }
106
107     py_info = _pygi_info_new (info);
108     g_base_info_unref (info);
109     return py_info;
110 }
111
112
113 /* _make_infos_tuple
114  *
115  * Build a tuple from the common API pattern in GI of having a
116  * function which returns a count and an indexed GIBaseInfo
117  * in the range of 0 to count;
118  */
119 static PyObject *
120 _make_infos_tuple (PyGIBaseInfo *self,
121                    gint (*get_n_infos)(GIBaseInfo*),
122                    GIBaseInfo* (*get_info)(GIBaseInfo*, gint))
123 {
124     gint n_infos;
125     PyObject *infos;
126     gint i;
127
128     n_infos = get_n_infos ( (GIBaseInfo *) self->info);
129
130     infos = PyTuple_New (n_infos);
131     if (infos == NULL) {
132         return NULL;
133     }
134
135     for (i = 0; i < n_infos; i++) {
136         GIBaseInfo *info;
137         PyObject *py_info;
138
139         info = (GIBaseInfo *) get_info (self->info, i);
140         g_assert (info != NULL);
141
142         py_info = _pygi_info_new (info);
143
144         g_base_info_unref (info);
145
146         if (py_info == NULL) {
147             Py_CLEAR (infos);
148             break;
149         }
150
151         PyTuple_SET_ITEM (infos, i, py_info);
152     }
153
154     return infos;
155 }
156
157
158 /* BaseInfo */
159
160 /* We need to be careful about calling g_base_info_get_name because
161  * calling it with a GI_INFO_TYPE_TYPE will crash.
162  * See: https://bugzilla.gnome.org/show_bug.cgi?id=709456
163  */
164 static const char *
165 _safe_base_info_get_name (GIBaseInfo *info)
166 {
167     if (g_base_info_get_type (info) == GI_INFO_TYPE_TYPE) {
168         return "type_type_instance";
169     } else {
170         return g_base_info_get_name (info);
171     }
172 }
173
174 static void
175 _base_info_dealloc (PyGIBaseInfo *self)
176 {
177     if (self->inst_weakreflist != NULL)
178         PyObject_ClearWeakRefs ( (PyObject *) self);
179
180     g_base_info_unref (self->info);
181
182     if (self->cache != NULL)
183         pygi_callable_cache_free ( (PyGICallableCache *) self->cache);
184
185     Py_TYPE (self)->tp_free ((PyObject *)self);
186 }
187
188 static PyObject *
189 _base_info_repr (PyGIBaseInfo *self)
190 {
191
192     return PYGLIB_PyUnicode_FromFormat ("%s(%s)",
193                                         Py_TYPE( (PyObject *) self)->tp_name,
194                                         _safe_base_info_get_name (self->info));
195 }
196
197 static PyObject *
198 _wrap_g_base_info_equal (PyGIBaseInfo *self, PyObject *other)
199 {
200     GIBaseInfo *other_info;
201
202     if (!PyObject_TypeCheck (other, &PyGIBaseInfo_Type)) {
203         Py_INCREF (Py_NotImplemented);
204         return Py_NotImplemented;
205     }
206
207     other_info = ((PyGIBaseInfo *)other)->info;
208     if (g_base_info_equal (self->info, other_info)) {
209         Py_RETURN_TRUE;
210     } else {
211         Py_RETURN_FALSE;
212     }
213 }
214
215 static PyObject *
216 _base_info_richcompare (PyGIBaseInfo *self, PyObject *other, int op)
217 {
218     PyObject *res;
219
220     switch (op) {
221         case Py_EQ:
222             return _wrap_g_base_info_equal (self, other);
223         case Py_NE:
224             res = _wrap_g_base_info_equal (self, other);
225             if (res == Py_True) {
226                 Py_DECREF (res);
227                 Py_RETURN_FALSE;
228             } else {
229                 Py_DECREF (res);
230                 Py_RETURN_TRUE;
231             }
232         default:
233             res = Py_NotImplemented;
234             break;
235     }
236     Py_INCREF(res);
237     return res;
238 }
239
240 PYGLIB_DEFINE_TYPE("gi.BaseInfo", PyGIBaseInfo_Type, PyGIBaseInfo);
241
242 gboolean
243 _pygi_is_python_keyword (const gchar *name)
244 {
245     /* It may be better to use keyword.iskeyword(); keep in sync with
246      * python -c 'import keyword; print(keyword.kwlist)' */
247 #if PY_VERSION_HEX < 0x03000000
248     /* Python 2.x */
249     static const gchar* keywords[] = {"and", "as", "assert", "break", "class",
250         "continue", "def", "del", "elif", "else", "except", "exec", "finally",
251         "for", "from", "global", "if", "import", "in", "is", "lambda", "not",
252         "or", "pass", "print", "raise", "return", "try", "while", "with",
253         "yield", NULL};
254 #elif PY_VERSION_HEX < 0x04000000
255     /* Python 3.x; note that we explicitly keep "print"; it is not a keyword
256      * any more, but we do not want to break API between Python versions */
257     static const gchar* keywords[] = {"False", "None", "True", "and", "as",
258         "assert", "break", "class", "continue", "def", "del", "elif", "else",
259         "except", "finally", "for", "from", "global", "if", "import", "in",
260         "is", "lambda", "nonlocal", "not", "or", "pass", "raise", "return",
261         "try", "while", "with", "yield",
262         "print", NULL};
263 #else
264     #error Need keyword list for this major Python version
265 #endif
266
267     const gchar **i;
268
269     for (i = keywords; *i != NULL; ++i) {
270         if (strcmp (name, *i) == 0) {
271             return TRUE;
272         }
273     }
274
275     return FALSE;
276 }
277
278 static PyObject *
279 _wrap_g_base_info_get_type (PyGIBaseInfo *self)
280 {
281     return PYGLIB_PyLong_FromLong (g_base_info_get_type (self->info));
282 }
283
284 static PyObject *
285 _wrap_g_base_info_get_name (PyGIBaseInfo *self)
286 {
287     const gchar *name;
288
289     name = _safe_base_info_get_name (self->info);
290
291     /* escape keywords */
292     if (_pygi_is_python_keyword (name)) {
293         gchar *escaped = g_strconcat (name, "_", NULL);
294         PyObject *obj = PYGLIB_PyUnicode_FromString (escaped);
295         g_free (escaped);
296         return obj;
297     }
298
299     return PYGLIB_PyUnicode_FromString (name);
300 }
301
302 static PyObject *
303 _wrap_g_base_info_get_name_unescaped (PyGIBaseInfo *self)
304 {
305     return _get_info_string (self, _safe_base_info_get_name);
306 }
307
308 static PyObject *
309 _wrap_g_base_info_get_namespace (PyGIBaseInfo *self)
310 {
311     return _get_info_string (self, g_base_info_get_namespace);
312 }
313
314 static PyObject *
315 _wrap_g_base_info_is_deprecated (PyGIBaseInfo *self)
316 {
317     if (g_base_info_is_deprecated (self->info))
318         Py_RETURN_TRUE;
319     else
320         Py_RETURN_FALSE;
321 }
322
323 static PyObject *
324 _wrap_g_base_info_get_attribute (PyGIBaseInfo *self, PyObject *arg)
325 {
326     char *name;
327     const char *value;
328
329     if (!PYGLIB_PyUnicode_Check (arg)) {
330         PyErr_SetString (PyExc_TypeError, "expected string name");
331         return NULL;
332     }
333
334     name = PYGLIB_PyUnicode_AsString (arg);
335     value = g_base_info_get_attribute (self->info, name);
336     if (value == NULL) {
337         Py_RETURN_NONE;
338     }
339     return PYGLIB_PyUnicode_FromString (value);
340 }
341
342 static PyObject *
343 _wrap_g_base_info_get_container (PyGIBaseInfo *self)
344 {
345     /* Note: don't use _get_child_info because g_base_info_get_container
346      * is marked as [transfer none] and therefore returns a borrowed ref.
347      */
348     GIBaseInfo *info;
349
350     info = g_base_info_get_container (self->info);
351
352     if (info == NULL) {
353         Py_RETURN_NONE;
354     }
355
356     return _pygi_info_new (info);
357 }
358
359
360 static PyMethodDef _PyGIBaseInfo_methods[] = {
361     { "get_type", (PyCFunction) _wrap_g_base_info_get_type, METH_NOARGS },
362     { "get_name", (PyCFunction) _wrap_g_base_info_get_name, METH_NOARGS },
363     { "get_name_unescaped", (PyCFunction) _wrap_g_base_info_get_name_unescaped, METH_NOARGS },
364     { "get_namespace", (PyCFunction) _wrap_g_base_info_get_namespace, METH_NOARGS },
365     { "is_deprecated", (PyCFunction) _wrap_g_base_info_is_deprecated, METH_NOARGS },
366     { "get_attribute", (PyCFunction) _wrap_g_base_info_get_attribute, METH_O },
367     { "get_container", (PyCFunction) _wrap_g_base_info_get_container, METH_NOARGS },
368     { "equal", (PyCFunction) _wrap_g_base_info_equal, METH_O },
369     { NULL, NULL, 0 }
370 };
371
372 /* _base_info_getattro:
373  *
374  * The usage of __getattr__ is needed because the get/set method table
375  * does not work for __doc__.
376  */
377 static PyObject *
378 _base_info_getattro(PyGIBaseInfo *self, PyObject *name)
379 {
380     PyObject *result;
381
382     static PyObject *docstr;
383     if (docstr == NULL) {
384         docstr= PYGLIB_PyUnicode_InternFromString("__doc__");
385         if (docstr == NULL)
386             return NULL;
387     }
388
389     Py_INCREF (name);
390     PYGLIB_PyUnicode_InternInPlace (&name);
391
392     if (name == docstr) {
393         result = _generate_doc_string (self);
394     } else {
395         result = PyObject_GenericGetAttr ((PyObject *)self, name);
396     }
397
398     Py_DECREF (name);
399     return result;
400 }
401
402 static PyObject *
403 _base_info_attr_name(PyGIBaseInfo *self, void *closure)
404 {
405     return _wrap_g_base_info_get_name (self);
406 }
407
408 static PyObject *
409 _base_info_attr_module(PyGIBaseInfo *self, void *closure)
410 {
411     return PYGLIB_PyUnicode_FromFormat ("gi.repository.%s",
412                                         g_base_info_get_namespace (self->info));
413 }
414
415 static PyGetSetDef _base_info_getsets[] = {
416         { "__name__", (getter)_base_info_attr_name, (setter)0, "Name", NULL},
417         { "__module__", (getter)_base_info_attr_module, (setter)0, "Module name", NULL},
418     { NULL, 0, 0 }
419 };
420
421 PyObject *
422 _pygi_info_new (GIBaseInfo *info)
423 {
424     GIInfoType info_type;
425     PyTypeObject *type = NULL;
426     PyGIBaseInfo *self;
427
428     info_type = g_base_info_get_type (info);
429
430     switch (info_type)
431     {
432         case GI_INFO_TYPE_INVALID:
433             PyErr_SetString (PyExc_RuntimeError, "Invalid info type");
434             return NULL;
435         case GI_INFO_TYPE_FUNCTION:
436             type = &PyGIFunctionInfo_Type;
437             break;
438         case GI_INFO_TYPE_CALLBACK:
439             type = &PyGICallbackInfo_Type;
440             break;
441         case GI_INFO_TYPE_STRUCT:
442         case GI_INFO_TYPE_BOXED:
443             type = &PyGIStructInfo_Type;
444             break;
445         case GI_INFO_TYPE_ENUM:
446         case GI_INFO_TYPE_FLAGS:
447             type = &PyGIEnumInfo_Type;
448             break;
449         case GI_INFO_TYPE_OBJECT:
450             type = &PyGIObjectInfo_Type;
451             break;
452         case GI_INFO_TYPE_INTERFACE:
453             type = &PyGIInterfaceInfo_Type;
454             break;
455         case GI_INFO_TYPE_CONSTANT:
456             type = &PyGIConstantInfo_Type;
457             break;
458         case GI_INFO_TYPE_UNION:
459             type = &PyGIUnionInfo_Type;
460             break;
461         case GI_INFO_TYPE_VALUE:
462             type = &PyGIValueInfo_Type;
463             break;
464         case GI_INFO_TYPE_SIGNAL:
465             type = &PyGISignalInfo_Type;
466             break;
467         case GI_INFO_TYPE_VFUNC:
468             type = &PyGIVFuncInfo_Type;
469             break;
470         case GI_INFO_TYPE_PROPERTY:
471             type = &PyGIPropertyInfo_Type;
472             break;
473         case GI_INFO_TYPE_FIELD:
474             type = &PyGIFieldInfo_Type;
475             break;
476         case GI_INFO_TYPE_ARG:
477             type = &PyGIArgInfo_Type;
478             break;
479         case GI_INFO_TYPE_TYPE:
480             type = &PyGITypeInfo_Type;
481             break;
482         case GI_INFO_TYPE_UNRESOLVED:
483             type = &PyGIUnresolvedInfo_Type;
484             break;
485         default:
486             g_assert_not_reached();
487             break;
488     }
489
490     self = (PyGIBaseInfo *) type->tp_alloc (type, 0);
491     if (self == NULL) {
492         return NULL;
493     }
494
495     self->info = g_base_info_ref (info);
496     self->inst_weakreflist = NULL;
497     self->cache = NULL;
498
499     return (PyObject *) self;
500 }
501
502 GIBaseInfo *
503 _pygi_object_get_gi_info (PyObject     *object,
504                           PyTypeObject *type)
505 {
506     PyObject *py_info;
507     GIBaseInfo *info = NULL;
508
509     py_info = PyObject_GetAttrString (object, "__info__");
510     if (py_info == NULL) {
511         return NULL;
512     }
513     if (!PyObject_TypeCheck (py_info, type)) {
514         PyErr_Format (PyExc_TypeError, "attribute '__info__' must be %s, not %s",
515                       type->tp_name, Py_TYPE(py_info)->tp_name);
516         goto out;
517     }
518
519     info = ( (PyGIBaseInfo *) py_info)->info;
520     g_base_info_ref (info);
521
522 out:
523     Py_DECREF (py_info);
524
525     return info;
526 }
527
528
529 /* CallableInfo */
530 PYGLIB_DEFINE_TYPE ("gi.CallableInfo", PyGICallableInfo_Type, PyGICallableInfo);
531
532 /* _callable_info_call:
533  *
534  * Shared wrapper for invoke which can be bound (instance method or class constructor)
535  * or unbound (function or static method).
536  */
537 static PyObject *
538 _callable_info_call (PyGICallableInfo *self, PyObject *args, PyObject *kwargs)
539 {
540     /* Insert the bound arg at the beginning of the invoke method args. */
541     if (self->py_bound_arg) {
542         int i;
543         PyObject *result;
544         Py_ssize_t argcount = PyTuple_Size (args);
545         PyObject *newargs = PyTuple_New (argcount + 1);
546         if (newargs == NULL)
547             return NULL;
548
549         Py_INCREF (self->py_bound_arg);
550         PyTuple_SET_ITEM (newargs, 0, self->py_bound_arg);
551
552         for (i = 0; i < argcount; i++) {
553             PyObject *v = PyTuple_GET_ITEM (args, i);
554             Py_XINCREF (v);
555             PyTuple_SET_ITEM (newargs, i+1, v);
556         }
557
558         /* Invoke with the original GI info struct this wrapper was based upon.
559          * This is necessary to maintain the same cache for all bound versions.
560          */
561         result = _wrap_g_callable_info_invoke ((PyGIBaseInfo *)self->py_unbound_info,
562                                                newargs, kwargs);
563         Py_DECREF (newargs);
564         return result;
565
566     } else {
567         /* We should never have an unbound info when calling when calling invoke
568          * at this point because the descriptor implementation on sub-classes
569          * should return "self" not a copy when there is no bound arg.
570          */
571         g_assert (self->py_unbound_info == NULL);
572         return _wrap_g_callable_info_invoke ((PyGIBaseInfo *)self, args, kwargs);
573     }
574 }
575
576
577 /* _function_info_call:
578  *
579  * Specialization of _callable_info_call for GIFunctionInfo which
580  * handles constructor error conditions.
581  */
582 static PyObject *
583 _function_info_call (PyGICallableInfo *self, PyObject *args, PyObject *kwargs)
584 {
585     if (self->py_bound_arg) {
586         GIFunctionInfoFlags flags;
587
588         /* Ensure constructors are only called as class methods on the class
589          * implementing the constructor and not on sub-classes.
590          */
591         flags = g_function_info_get_flags ( (GIFunctionInfo*) self->base.info);
592         if (flags & GI_FUNCTION_IS_CONSTRUCTOR) {
593             PyObject *py_str_name;
594             const gchar *str_name;
595             GIBaseInfo *container_info = g_base_info_get_container (self->base.info);
596             g_assert (container_info != NULL);
597
598             py_str_name = PyObject_GetAttrString (self->py_bound_arg, "__name__");
599             if (py_str_name == NULL)
600                 return NULL;
601
602             if (PyUnicode_Check (py_str_name) ) {
603                 PyObject *tmp = PyUnicode_AsUTF8String (py_str_name);
604                 Py_DECREF (py_str_name);
605                 py_str_name = tmp;
606             }
607
608 #if PY_VERSION_HEX < 0x03000000
609             str_name = PyString_AsString (py_str_name);
610 #else
611             str_name = PyBytes_AsString (py_str_name);
612 #endif
613
614             if (strcmp (str_name, _safe_base_info_get_name (container_info))) {
615                 PyErr_Format (PyExc_TypeError,
616                               "%s constructor cannot be used to create instances of "
617                               "a subclass %s",
618                               _safe_base_info_get_name (container_info),
619                               str_name);
620                 Py_DECREF (py_str_name);
621                 return NULL;
622             }
623             Py_DECREF (py_str_name);
624         }
625     }
626
627     return _callable_info_call (self, args, kwargs);
628 }
629
630 /* _new_bound_callable_info
631  *
632  * Utility function for sub-classes to create a bound version of themself.
633  */
634 static PyGICallableInfo *
635 _new_bound_callable_info (PyGICallableInfo *self, PyObject *bound_arg)
636 {
637     PyGICallableInfo *new_self;
638
639     /* Return self if this is already bound or there is nothing passed to bind.  */
640     if (self->py_bound_arg != NULL || bound_arg == NULL || bound_arg == Py_None) {
641         Py_INCREF ((PyObject *)self);
642         return self;
643     }
644
645     new_self = (PyGICallableInfo *)_pygi_info_new (self->base.info);
646     if (new_self == NULL)
647         return NULL;
648
649     Py_INCREF ((PyObject *)self);
650     new_self->py_unbound_info = (struct PyGICallableInfo *)self;
651
652     Py_INCREF (bound_arg);
653     new_self->py_bound_arg = bound_arg;
654
655     return new_self;
656 }
657
658 /* _function_info_descr_get
659  *
660  * Descriptor protocol implementation for functions, methods, and constructors.
661  */
662 static PyObject *
663 _function_info_descr_get (PyGICallableInfo *self, PyObject *obj, PyObject *type) {
664     GIFunctionInfoFlags flags;
665     PyObject *bound_arg = NULL;
666
667     flags = g_function_info_get_flags ( (GIFunctionInfo*) self->base.info);
668     if (flags & GI_FUNCTION_IS_CONSTRUCTOR) {
669         if (type == NULL)
670             bound_arg = (PyObject *)(Py_TYPE(obj));
671         else
672             bound_arg = type;
673     } else if (flags & GI_FUNCTION_IS_METHOD) {
674         bound_arg = obj;
675     }
676
677     return (PyObject *)_new_bound_callable_info (self, bound_arg);
678 }
679
680 /* _vfunc_info_descr_get
681  *
682  * Descriptor protocol implementation for virtual functions.
683  */
684 static PyObject *
685 _vfunc_info_descr_get (PyGICallableInfo *self, PyObject *obj, PyObject *type) {
686     PyObject *result;
687     PyObject *bound_arg = NULL;
688
689     bound_arg = PyObject_GetAttrString (type, "__gtype__");
690     if (bound_arg == NULL)
691         return NULL;
692
693     /* _new_bound_callable_info adds its own ref so free the one from GetAttrString */
694     result = (PyObject *)_new_bound_callable_info (self, bound_arg);
695     Py_DECREF (bound_arg);
696     return result;
697 }
698
699 static void
700 _callable_info_dealloc (PyGICallableInfo *self)
701 {
702     Py_CLEAR (self->py_unbound_info);
703     Py_CLEAR (self->py_bound_arg);
704
705     PyGIBaseInfo_Type.tp_dealloc ((PyObject *) self);
706 }
707
708 static PyObject *
709 _wrap_g_callable_info_get_arguments (PyGIBaseInfo *self)
710 {
711     return _make_infos_tuple (self, g_callable_info_get_n_args, g_callable_info_get_arg);
712 }
713
714 static PyObject *
715 _wrap_g_callable_info_get_return_type (PyGIBaseInfo *self)
716 {
717     return _get_child_info (self, g_callable_info_get_return_type);
718 }
719
720 static PyObject *
721 _wrap_g_callable_info_get_caller_owns (PyGIBaseInfo *self)
722 {
723     return PYGLIB_PyLong_FromLong (
724             g_callable_info_get_caller_owns (self->info) );
725 }
726
727 static PyObject *
728 _wrap_g_callable_info_may_return_null (PyGIBaseInfo *self)
729 {
730     return PyBool_FromLong (
731             g_callable_info_may_return_null (self->info) );
732 }
733
734 static PyObject *
735 _wrap_g_callable_info_skip_return (PyGIBaseInfo *self)
736 {
737     return PyBool_FromLong (g_callable_info_skip_return (self->info));
738 }
739
740 static PyObject *
741 _wrap_g_callable_info_get_return_attribute (PyGIBaseInfo *self, PyObject *py_name)
742 {
743     gchar *name;
744     const gchar *attr;
745
746     if (!PYGLIB_PyUnicode_Check (py_name)) {
747         PyErr_SetString (PyExc_TypeError, "expected string name");
748         return NULL;
749     }
750
751     name = PYGLIB_PyUnicode_AsString (py_name);
752     attr = g_callable_info_get_return_attribute (self->info, name);
753     if (attr) {
754         return PYGLIB_PyUnicode_FromString (
755                 g_callable_info_get_return_attribute (self->info, name));
756     } else {
757         PyErr_Format(PyExc_AttributeError, "return attribute %s not found", name);
758         return NULL;
759     }
760 }
761
762 static PyObject *
763 _wrap_g_callable_info_can_throw_gerror (PyGIBaseInfo *self)
764 {
765     if (g_callable_info_can_throw_gerror (self->info))
766         Py_RETURN_TRUE;
767     else
768         Py_RETURN_FALSE;
769 }
770
771 static PyMethodDef _PyGICallableInfo_methods[] = {
772     { "invoke", (PyCFunction) _wrap_g_callable_info_invoke, METH_VARARGS | METH_KEYWORDS },
773     { "get_arguments", (PyCFunction) _wrap_g_callable_info_get_arguments, METH_NOARGS },
774     { "get_return_type", (PyCFunction) _wrap_g_callable_info_get_return_type, METH_NOARGS },
775     { "get_caller_owns", (PyCFunction) _wrap_g_callable_info_get_caller_owns, METH_NOARGS },
776     { "may_return_null", (PyCFunction) _wrap_g_callable_info_may_return_null, METH_NOARGS },
777     { "skip_return", (PyCFunction) _wrap_g_callable_info_skip_return, METH_NOARGS },
778     { "get_return_attribute", (PyCFunction) _wrap_g_callable_info_get_return_attribute, METH_O },
779     { "can_throw_gerror", (PyCFunction) _wrap_g_callable_info_can_throw_gerror, METH_NOARGS },
780     { NULL, NULL, 0 }
781 };
782
783 /* CallbackInfo */
784 PYGLIB_DEFINE_TYPE ("gi.CallbackInfo", PyGICallbackInfo_Type, PyGICallableInfo);
785
786 static PyMethodDef _PyGICallbackInfo_methods[] = {
787     { NULL, NULL, 0 }
788 };
789
790 /* ErrorDomainInfo */
791 PYGLIB_DEFINE_TYPE ("gi.ErrorDomainInfo", PyGIErrorDomainInfo_Type, PyGIBaseInfo);
792
793 static PyMethodDef _PyGIErrorDomainInfo_methods[] = {
794     { NULL, NULL, 0 }
795 };
796
797 /* SignalInfo */
798 PYGLIB_DEFINE_TYPE ("gi.SignalInfo", PyGISignalInfo_Type, PyGICallableInfo);
799
800 static PyObject *
801 _wrap_g_signal_info_get_flags (PyGIBaseInfo *self)
802 {
803     return PYGLIB_PyLong_FromLong (
804             g_signal_info_get_flags ((GISignalInfo *)self->info) );
805 }
806
807 static PyObject *
808 _wrap_g_signal_info_get_class_closure (PyGIBaseInfo *self)
809 {
810     return _get_child_info (self, g_signal_info_get_class_closure);
811 }
812
813 static PyObject *
814 _wrap_g_signal_info_true_stops_emit (PyGIBaseInfo *self)
815 {
816     return PyBool_FromLong (
817             g_signal_info_true_stops_emit ((GISignalInfo *)self->info) );
818 }
819
820 static PyMethodDef _PyGISignalInfo_methods[] = {
821     { "get_flags", (PyCFunction) _wrap_g_signal_info_get_flags, METH_NOARGS },
822     { "get_class_closure", (PyCFunction) _wrap_g_signal_info_get_class_closure, METH_NOARGS },
823     { "true_stops_emit", (PyCFunction) _wrap_g_signal_info_true_stops_emit, METH_NOARGS },
824     { NULL, NULL, 0 }
825 };
826
827 /* PropertyInfo */
828 PYGLIB_DEFINE_TYPE ("gi.PropertyInfo", PyGIPropertyInfo_Type, PyGIBaseInfo);
829
830 static PyObject *
831 _wrap_g_property_info_get_flags (PyGIBaseInfo *self)
832 {
833     return PYGLIB_PyLong_FromLong (
834             g_property_info_get_flags ((GIPropertyInfo *)self->info) );
835 }
836
837 static PyObject *
838 _wrap_g_property_info_get_type (PyGIBaseInfo *self)
839 {
840     return _get_child_info (self, g_property_info_get_type);
841 }
842
843 static PyObject *
844 _wrap_g_property_info_get_ownership_transfer (PyGIBaseInfo *self)
845 {
846     return PYGLIB_PyLong_FromLong (
847             g_property_info_get_ownership_transfer ((GIPropertyInfo *)self->info) );
848 }
849
850 static PyMethodDef _PyGIPropertyInfo_methods[] = {
851     { "get_flags", (PyCFunction) _wrap_g_property_info_get_flags, METH_NOARGS },
852     { "get_type", (PyCFunction) _wrap_g_property_info_get_type, METH_NOARGS },
853     { "get_ownership_transfer", (PyCFunction) _wrap_g_property_info_get_ownership_transfer, METH_NOARGS },
854     { NULL, NULL, 0 }
855 };
856
857
858 /* ArgInfo */
859 PYGLIB_DEFINE_TYPE ("gi.ArgInfo", PyGIArgInfo_Type, PyGIBaseInfo);
860
861 static PyObject *
862 _wrap_g_arg_info_get_direction (PyGIBaseInfo *self)
863 {
864     return PYGLIB_PyLong_FromLong (
865             g_arg_info_get_direction ((GIArgInfo*)self->info) );
866 }
867
868 static PyObject *
869 _wrap_g_arg_info_is_caller_allocates (PyGIBaseInfo *self)
870 {
871     return PyBool_FromLong (
872             g_arg_info_is_caller_allocates ((GIArgInfo*)self->info) );
873 }
874
875 static PyObject *
876 _wrap_g_arg_info_is_return_value (PyGIBaseInfo *self)
877 {
878     return PyBool_FromLong (
879             g_arg_info_is_return_value ((GIArgInfo*)self->info) );
880 }
881
882 static PyObject *
883 _wrap_g_arg_info_is_optional (PyGIBaseInfo *self)
884 {
885     return PyBool_FromLong (
886             g_arg_info_is_optional ((GIArgInfo*)self->info) );
887 }
888
889 static PyObject *
890 _wrap_g_arg_info_may_be_null (PyGIBaseInfo *self)
891 {
892     return PyBool_FromLong (
893             g_arg_info_may_be_null ((GIArgInfo*)self->info) );
894 }
895
896 static PyObject *
897 _wrap_g_arg_info_get_ownership_transfer (PyGIBaseInfo *self)
898 {
899     return PYGLIB_PyLong_FromLong (
900             g_arg_info_get_ownership_transfer ((GIArgInfo *)self->info) );
901 }
902
903 static PyObject *
904 _wrap_g_arg_info_get_scope (PyGIBaseInfo *self)
905 {
906     return PYGLIB_PyLong_FromLong (
907             g_arg_info_get_scope ((GIArgInfo *)self->info) );
908 }
909
910 static PyObject *
911 _wrap_g_arg_info_get_closure (PyGIBaseInfo *self)
912 {
913     return PYGLIB_PyLong_FromLong (
914             g_arg_info_get_closure ((GIArgInfo *)self->info) );
915 }
916
917 static PyObject *
918 _wrap_g_arg_info_get_destroy (PyGIBaseInfo *self)
919 {
920     return PYGLIB_PyLong_FromLong (
921             g_arg_info_get_destroy ((GIArgInfo *)self->info) );
922 }
923
924 static PyObject *
925 _wrap_g_arg_info_get_type (PyGIBaseInfo *self)
926 {
927     return _get_child_info (self, g_arg_info_get_type);
928 }
929
930 static PyMethodDef _PyGIArgInfo_methods[] = {
931     { "get_direction", (PyCFunction) _wrap_g_arg_info_get_direction, METH_NOARGS },
932     { "is_caller_allocates", (PyCFunction) _wrap_g_arg_info_is_caller_allocates, METH_NOARGS },
933     { "is_return_value", (PyCFunction) _wrap_g_arg_info_is_return_value, METH_NOARGS },
934     { "is_optional", (PyCFunction) _wrap_g_arg_info_is_optional, METH_NOARGS },
935     { "may_be_null", (PyCFunction) _wrap_g_arg_info_may_be_null, METH_NOARGS },
936     { "get_ownership_transfer", (PyCFunction) _wrap_g_arg_info_get_ownership_transfer, METH_NOARGS },
937     { "get_scope", (PyCFunction) _wrap_g_arg_info_get_scope, METH_NOARGS },
938     { "get_closure", (PyCFunction) _wrap_g_arg_info_get_closure, METH_NOARGS },
939     { "get_destroy", (PyCFunction) _wrap_g_arg_info_get_destroy, METH_NOARGS },
940     { "get_type", (PyCFunction) _wrap_g_arg_info_get_type, METH_NOARGS },
941     { NULL, NULL, 0 }
942 };
943
944
945 /* TypeInfo */
946 PYGLIB_DEFINE_TYPE ("gi.TypeInfo", PyGITypeInfo_Type, PyGIBaseInfo);
947
948 static PyObject *
949 _wrap_g_type_info_is_pointer (PyGIBaseInfo *self)
950 {
951     return PyBool_FromLong (g_type_info_is_pointer (self->info));
952 }
953
954 static PyObject *
955 _wrap_g_type_info_get_tag (PyGIBaseInfo *self)
956 {
957     return PYGLIB_PyLong_FromLong (g_type_info_get_tag (self->info));
958 }
959
960 static PyObject *
961 _wrap_g_type_info_get_tag_as_string (PyGIBaseInfo *self)
962 {
963     GITypeTag tag = g_type_info_get_tag (self->info);
964     return PYGLIB_PyUnicode_FromString (g_type_tag_to_string(tag));
965 }
966
967 static PyObject *
968 _wrap_g_type_info_get_param_type (PyGIBaseInfo *self, PyObject *py_n)
969 {
970     GIBaseInfo *info;
971     PyObject *py_info;
972     gint n;
973
974     if (!PYGLIB_PyLong_Check (py_n)) {
975         PyErr_SetString(PyExc_TypeError, "expected integer value");
976         return NULL;
977     }
978
979     n = PYGLIB_PyLong_AsLong (py_n);
980     info = (GIBaseInfo *) g_type_info_get_param_type ( (GITypeInfo *) self->info, n);
981     if (info == NULL) {
982         Py_RETURN_NONE;
983     }
984
985     py_info = _pygi_info_new (info);
986     g_base_info_unref (info);
987     return py_info;
988 }
989
990 static PyObject *
991 _wrap_g_type_info_get_interface (PyGIBaseInfo *self)
992 {
993     return _get_child_info (self, g_type_info_get_interface);
994 }
995
996 static PyObject *
997 _wrap_g_type_info_get_array_length (PyGIBaseInfo *self)
998 {
999     return PYGLIB_PyLong_FromLong (g_type_info_get_array_length (self->info));
1000 }
1001
1002 static PyObject *
1003 _wrap_g_type_info_get_array_fixed_size (PyGIBaseInfo *self)
1004 {
1005     return PYGLIB_PyLong_FromLong (g_type_info_get_array_fixed_size (self->info));
1006 }
1007
1008 static PyObject *
1009 _wrap_g_type_info_is_zero_terminated (PyGIBaseInfo *self)
1010 {
1011     return PyBool_FromLong (g_type_info_is_zero_terminated (self->info));
1012 }
1013
1014 static PyObject *
1015 _wrap_g_type_info_get_array_type (PyGIBaseInfo *self)
1016 {
1017     return PYGLIB_PyLong_FromLong (g_type_info_get_array_type (self->info));
1018 }
1019
1020 static PyMethodDef _PyGITypeInfo_methods[] = {
1021     { "is_pointer", (PyCFunction) _wrap_g_type_info_is_pointer, METH_NOARGS },
1022     { "get_tag", (PyCFunction) _wrap_g_type_info_get_tag, METH_NOARGS },
1023     { "get_tag_as_string", (PyCFunction) _wrap_g_type_info_get_tag_as_string, METH_NOARGS },
1024     { "get_param_type", (PyCFunction) _wrap_g_type_info_get_param_type, METH_O },
1025     { "get_interface", (PyCFunction) _wrap_g_type_info_get_interface, METH_NOARGS },
1026     { "get_array_length", (PyCFunction) _wrap_g_type_info_get_array_length, METH_NOARGS },
1027     { "get_array_fixed_size", (PyCFunction) _wrap_g_type_info_get_array_fixed_size, METH_NOARGS },
1028     { "is_zero_terminated", (PyCFunction) _wrap_g_type_info_is_zero_terminated, METH_NOARGS },
1029     { "get_array_type", (PyCFunction) _wrap_g_type_info_get_array_type, METH_NOARGS },
1030     { NULL, NULL, 0 }
1031 };
1032
1033
1034 /* FunctionInfo */
1035 PYGLIB_DEFINE_TYPE ("gi.FunctionInfo", PyGIFunctionInfo_Type, PyGICallableInfo);
1036
1037 static PyObject *
1038 _wrap_g_function_info_is_constructor (PyGIBaseInfo *self)
1039 {
1040     GIFunctionInfoFlags flags;
1041     gboolean is_constructor;
1042
1043     flags = g_function_info_get_flags ( (GIFunctionInfo*) self->info);
1044     is_constructor = flags & GI_FUNCTION_IS_CONSTRUCTOR;
1045
1046     return PyBool_FromLong (is_constructor);
1047 }
1048
1049 static PyObject *
1050 _wrap_g_function_info_is_method (PyGIBaseInfo *self)
1051 {
1052     GIFunctionInfoFlags flags;
1053     gboolean is_method;
1054
1055     flags = g_function_info_get_flags ( (GIFunctionInfo*) self->info);
1056     is_method = flags & GI_FUNCTION_IS_METHOD;
1057
1058     return PyBool_FromLong (is_method);
1059 }
1060
1061 gsize
1062 _pygi_g_type_tag_size (GITypeTag type_tag)
1063 {
1064     gsize size = 0;
1065
1066     switch (type_tag) {
1067         case GI_TYPE_TAG_BOOLEAN:
1068             size = sizeof (gboolean);
1069             break;
1070         case GI_TYPE_TAG_INT8:
1071         case GI_TYPE_TAG_UINT8:
1072             size = sizeof (gint8);
1073             break;
1074         case GI_TYPE_TAG_INT16:
1075         case GI_TYPE_TAG_UINT16:
1076             size = sizeof (gint16);
1077             break;
1078         case GI_TYPE_TAG_INT32:
1079         case GI_TYPE_TAG_UINT32:
1080             size = sizeof (gint32);
1081             break;
1082         case GI_TYPE_TAG_INT64:
1083         case GI_TYPE_TAG_UINT64:
1084             size = sizeof (gint64);
1085             break;
1086         case GI_TYPE_TAG_FLOAT:
1087             size = sizeof (gfloat);
1088             break;
1089         case GI_TYPE_TAG_DOUBLE:
1090             size = sizeof (gdouble);
1091             break;
1092         case GI_TYPE_TAG_GTYPE:
1093             size = sizeof (GType);
1094             break;
1095         case GI_TYPE_TAG_UNICHAR:
1096             size = sizeof (gunichar);
1097             break;
1098         case GI_TYPE_TAG_VOID:
1099         case GI_TYPE_TAG_UTF8:
1100         case GI_TYPE_TAG_FILENAME:
1101         case GI_TYPE_TAG_ARRAY:
1102         case GI_TYPE_TAG_INTERFACE:
1103         case GI_TYPE_TAG_GLIST:
1104         case GI_TYPE_TAG_GSLIST:
1105         case GI_TYPE_TAG_GHASH:
1106         case GI_TYPE_TAG_ERROR:
1107             PyErr_Format (PyExc_TypeError,
1108                           "Unable to know the size (assuming %s is not a pointer)",
1109                           g_type_tag_to_string (type_tag));
1110             break;
1111     }
1112
1113     return size;
1114 }
1115
1116 gsize
1117 _pygi_g_type_info_size (GITypeInfo *type_info)
1118 {
1119     gsize size = 0;
1120
1121     GITypeTag type_tag;
1122
1123     type_tag = g_type_info_get_tag (type_info);
1124     switch (type_tag) {
1125         case GI_TYPE_TAG_BOOLEAN:
1126         case GI_TYPE_TAG_INT8:
1127         case GI_TYPE_TAG_UINT8:
1128         case GI_TYPE_TAG_INT16:
1129         case GI_TYPE_TAG_UINT16:
1130         case GI_TYPE_TAG_INT32:
1131         case GI_TYPE_TAG_UINT32:
1132         case GI_TYPE_TAG_INT64:
1133         case GI_TYPE_TAG_UINT64:
1134         case GI_TYPE_TAG_FLOAT:
1135         case GI_TYPE_TAG_DOUBLE:
1136         case GI_TYPE_TAG_GTYPE:
1137         case GI_TYPE_TAG_UNICHAR:
1138             size = _pygi_g_type_tag_size (type_tag);
1139             g_assert (size > 0);
1140             break;
1141         case GI_TYPE_TAG_INTERFACE:
1142         {
1143             GIBaseInfo *info;
1144             GIInfoType info_type;
1145
1146             info = g_type_info_get_interface (type_info);
1147             info_type = g_base_info_get_type (info);
1148
1149             switch (info_type) {
1150                 case GI_INFO_TYPE_STRUCT:
1151                     if (g_type_info_is_pointer (type_info)) {
1152                         size = sizeof (gpointer);
1153                     } else {
1154                         size = g_struct_info_get_size ( (GIStructInfo *) info);
1155                     }
1156                     break;
1157                 case GI_INFO_TYPE_UNION:
1158                     if (g_type_info_is_pointer (type_info)) {
1159                         size = sizeof (gpointer);
1160                     } else {
1161                         size = g_union_info_get_size ( (GIUnionInfo *) info);
1162                     }
1163                     break;
1164                 case GI_INFO_TYPE_ENUM:
1165                 case GI_INFO_TYPE_FLAGS:
1166                     if (g_type_info_is_pointer (type_info)) {
1167                         size = sizeof (gpointer);
1168                     } else {
1169                         GITypeTag type_tag;
1170
1171                         type_tag = g_enum_info_get_storage_type ( (GIEnumInfo *) info);
1172                         size = _pygi_g_type_tag_size (type_tag);
1173                     }
1174                     break;
1175                 case GI_INFO_TYPE_BOXED:
1176                 case GI_INFO_TYPE_OBJECT:
1177                 case GI_INFO_TYPE_INTERFACE:
1178                 case GI_INFO_TYPE_CALLBACK:
1179                     size = sizeof (gpointer);
1180                     break;
1181                 case GI_INFO_TYPE_VFUNC:
1182                 case GI_INFO_TYPE_INVALID:
1183                 case GI_INFO_TYPE_FUNCTION:
1184                 case GI_INFO_TYPE_CONSTANT:
1185                 case GI_INFO_TYPE_VALUE:
1186                 case GI_INFO_TYPE_SIGNAL:
1187                 case GI_INFO_TYPE_PROPERTY:
1188                 case GI_INFO_TYPE_FIELD:
1189                 case GI_INFO_TYPE_ARG:
1190                 case GI_INFO_TYPE_TYPE:
1191                 case GI_INFO_TYPE_UNRESOLVED:
1192                 default:
1193                     g_assert_not_reached();
1194                     break;
1195             }
1196
1197             g_base_info_unref (info);
1198             break;
1199         }
1200         case GI_TYPE_TAG_ARRAY:
1201         case GI_TYPE_TAG_VOID:
1202         case GI_TYPE_TAG_UTF8:
1203         case GI_TYPE_TAG_FILENAME:
1204         case GI_TYPE_TAG_GLIST:
1205         case GI_TYPE_TAG_GSLIST:
1206         case GI_TYPE_TAG_GHASH:
1207         case GI_TYPE_TAG_ERROR:
1208             size = sizeof (gpointer);
1209             break;
1210     }
1211
1212     return size;
1213 }
1214
1215 static PyObject *
1216 _wrap_g_function_info_get_symbol (PyGIBaseInfo *self)
1217 {
1218     return _get_info_string (self, g_function_info_get_symbol);
1219 }
1220
1221 static PyObject *
1222 _wrap_g_function_info_get_flags (PyGIBaseInfo *self)
1223 {
1224     return PYGLIB_PyLong_FromLong (g_function_info_get_flags (self->info));
1225 }
1226
1227 static PyObject *
1228 _wrap_g_function_info_get_property (PyGIBaseInfo *self)
1229 {
1230     return _get_child_info (self, g_function_info_get_property);
1231 }
1232
1233 static PyObject *
1234 _wrap_g_function_info_get_vfunc (PyGIBaseInfo *self)
1235 {
1236     return _get_child_info (self, g_function_info_get_vfunc);
1237 }
1238
1239 static PyMethodDef _PyGIFunctionInfo_methods[] = {
1240     { "is_constructor", (PyCFunction) _wrap_g_function_info_is_constructor, METH_NOARGS },
1241     { "is_method", (PyCFunction) _wrap_g_function_info_is_method, METH_NOARGS },
1242     { "get_symbol", (PyCFunction) _wrap_g_function_info_get_symbol, METH_NOARGS },
1243     { "get_flags", (PyCFunction) _wrap_g_function_info_get_flags, METH_NOARGS },
1244     { "get_property", (PyCFunction) _wrap_g_function_info_get_property, METH_NOARGS },
1245     { "get_vfunc", (PyCFunction) _wrap_g_function_info_get_vfunc, METH_NOARGS },
1246     { NULL, NULL, 0 }
1247 };
1248
1249 /* RegisteredTypeInfo */
1250 PYGLIB_DEFINE_TYPE ("gi.RegisteredTypeInfo", PyGIRegisteredTypeInfo_Type, PyGIBaseInfo);
1251
1252 static PyObject *
1253 _wrap_g_registered_type_info_get_type_name (PyGIBaseInfo *self)
1254 {
1255     return _get_info_string (self, g_registered_type_info_get_type_name);
1256 }
1257
1258 static PyObject *
1259 _wrap_g_registered_type_info_get_type_init (PyGIBaseInfo *self)
1260 {
1261     return _get_info_string (self, g_registered_type_info_get_type_init);
1262 }
1263
1264 static PyObject *
1265 _wrap_g_registered_type_info_get_g_type (PyGIBaseInfo *self)
1266 {
1267     GType type;
1268
1269     type = g_registered_type_info_get_g_type ( (GIRegisteredTypeInfo *) self->info);
1270
1271     return pyg_type_wrapper_new (type);
1272 }
1273
1274 static PyMethodDef _PyGIRegisteredTypeInfo_methods[] = {
1275     { "get_type_name", (PyCFunction) _wrap_g_registered_type_info_get_type_name, METH_NOARGS },
1276     { "get_type_init", (PyCFunction) _wrap_g_registered_type_info_get_type_init, METH_NOARGS },
1277     { "get_g_type", (PyCFunction) _wrap_g_registered_type_info_get_g_type, METH_NOARGS },
1278     { NULL, NULL, 0 }
1279 };
1280
1281
1282 /* GIStructInfo */
1283 PYGLIB_DEFINE_TYPE ("StructInfo", PyGIStructInfo_Type, PyGIBaseInfo);
1284
1285 static PyObject *
1286 _wrap_g_struct_info_get_fields (PyGIBaseInfo *self)
1287 {
1288     return _make_infos_tuple (self, g_struct_info_get_n_fields, g_struct_info_get_field);
1289 }
1290
1291 static PyObject *
1292 _wrap_g_struct_info_get_methods (PyGIBaseInfo *self)
1293 {
1294     return _make_infos_tuple (self, g_struct_info_get_n_methods, g_struct_info_get_method);
1295 }
1296
1297 static PyObject *
1298 _wrap_g_struct_info_get_size (PyGIBaseInfo *self)
1299 {
1300     return PYGLIB_PyLong_FromSize_t (g_struct_info_get_size (self->info));
1301 }
1302
1303 static PyObject *
1304 _wrap_g_struct_info_get_alignment (PyGIBaseInfo *self)
1305 {
1306     return PYGLIB_PyLong_FromSize_t (g_struct_info_get_alignment (self->info));
1307 }
1308
1309 static PyObject *
1310 _wrap_g_struct_info_is_gtype_struct (PyGIBaseInfo *self)
1311 {
1312     return PyBool_FromLong (g_struct_info_is_gtype_struct (self->info));
1313 }
1314
1315 static PyObject *
1316 _wrap_g_struct_info_is_foreign (PyGIBaseInfo *self)
1317 {
1318     return PyBool_FromLong (g_struct_info_is_foreign (self->info));
1319 }
1320
1321 static PyMethodDef _PyGIStructInfo_methods[] = {
1322     { "get_fields", (PyCFunction) _wrap_g_struct_info_get_fields, METH_NOARGS },
1323     { "get_methods", (PyCFunction) _wrap_g_struct_info_get_methods, METH_NOARGS },
1324     { "get_size", (PyCFunction) _wrap_g_struct_info_get_size, METH_NOARGS },
1325     { "get_alignment", (PyCFunction) _wrap_g_struct_info_get_alignment, METH_NOARGS },
1326     { "is_gtype_struct", (PyCFunction) _wrap_g_struct_info_is_gtype_struct, METH_NOARGS },
1327     { "is_foreign", (PyCFunction) _wrap_g_struct_info_is_foreign, METH_NOARGS },
1328     { NULL, NULL, 0 }
1329 };
1330
1331 gboolean
1332 pygi_g_struct_info_is_simple (GIStructInfo *struct_info)
1333 {
1334     gboolean is_simple;
1335     gsize n_field_infos;
1336     gsize i;
1337
1338     is_simple = TRUE;
1339
1340     n_field_infos = g_struct_info_get_n_fields (struct_info);
1341
1342     for (i = 0; i < n_field_infos && is_simple; i++) {
1343         GIFieldInfo *field_info;
1344         GITypeInfo *field_type_info;
1345         GITypeTag field_type_tag;
1346
1347         field_info = g_struct_info_get_field (struct_info, i);
1348         field_type_info = g_field_info_get_type (field_info);
1349
1350
1351         field_type_tag = g_type_info_get_tag (field_type_info);
1352
1353         switch (field_type_tag) {
1354             case GI_TYPE_TAG_BOOLEAN:
1355             case GI_TYPE_TAG_INT8:
1356             case GI_TYPE_TAG_UINT8:
1357             case GI_TYPE_TAG_INT16:
1358             case GI_TYPE_TAG_UINT16:
1359             case GI_TYPE_TAG_INT32:
1360             case GI_TYPE_TAG_UINT32:
1361             case GI_TYPE_TAG_INT64:
1362             case GI_TYPE_TAG_UINT64:
1363             case GI_TYPE_TAG_FLOAT:
1364             case GI_TYPE_TAG_DOUBLE:
1365             case GI_TYPE_TAG_UNICHAR:
1366                 if (g_type_info_is_pointer (field_type_info)) {
1367                     is_simple = FALSE;
1368                 }
1369                 break;
1370             case GI_TYPE_TAG_VOID:
1371             case GI_TYPE_TAG_GTYPE:
1372             case GI_TYPE_TAG_ERROR:
1373             case GI_TYPE_TAG_UTF8:
1374             case GI_TYPE_TAG_FILENAME:
1375             case GI_TYPE_TAG_ARRAY:
1376             case GI_TYPE_TAG_GLIST:
1377             case GI_TYPE_TAG_GSLIST:
1378             case GI_TYPE_TAG_GHASH:
1379                 is_simple = FALSE;
1380                 break;
1381             case GI_TYPE_TAG_INTERFACE:
1382             {
1383                 GIBaseInfo *info;
1384                 GIInfoType info_type;
1385
1386                 info = g_type_info_get_interface (field_type_info);
1387                 info_type = g_base_info_get_type (info);
1388
1389                 switch (info_type) {
1390                     case GI_INFO_TYPE_STRUCT:
1391                         if (g_type_info_is_pointer (field_type_info)) {
1392                             is_simple = FALSE;
1393                         } else {
1394                             is_simple = pygi_g_struct_info_is_simple ( (GIStructInfo *) info);
1395                         }
1396                         break;
1397                     case GI_INFO_TYPE_UNION:
1398                         /* TODO */
1399                         is_simple = FALSE;
1400                         break;
1401                     case GI_INFO_TYPE_ENUM:
1402                     case GI_INFO_TYPE_FLAGS:
1403                         if (g_type_info_is_pointer (field_type_info)) {
1404                             is_simple = FALSE;
1405                         }
1406                         break;
1407                     case GI_INFO_TYPE_BOXED:
1408                     case GI_INFO_TYPE_OBJECT:
1409                     case GI_INFO_TYPE_CALLBACK:
1410                     case GI_INFO_TYPE_INTERFACE:
1411                         is_simple = FALSE;
1412                         break;
1413                     case GI_INFO_TYPE_VFUNC:
1414                     case GI_INFO_TYPE_INVALID:
1415                     case GI_INFO_TYPE_FUNCTION:
1416                     case GI_INFO_TYPE_CONSTANT:
1417                     case GI_INFO_TYPE_VALUE:
1418                     case GI_INFO_TYPE_SIGNAL:
1419                     case GI_INFO_TYPE_PROPERTY:
1420                     case GI_INFO_TYPE_FIELD:
1421                     case GI_INFO_TYPE_ARG:
1422                     case GI_INFO_TYPE_TYPE:
1423                     case GI_INFO_TYPE_UNRESOLVED:
1424                     default:
1425                         g_assert_not_reached();
1426                         break;
1427                 }
1428
1429                 g_base_info_unref (info);
1430                 break;
1431             }
1432         }
1433
1434         g_base_info_unref ( (GIBaseInfo *) field_type_info);
1435         g_base_info_unref ( (GIBaseInfo *) field_info);
1436     }
1437
1438     return is_simple;
1439 }
1440
1441
1442 /* EnumInfo */
1443 PYGLIB_DEFINE_TYPE ("gi.EnumInfo", PyGIEnumInfo_Type, PyGIBaseInfo);
1444
1445 static PyObject *
1446 _wrap_g_enum_info_get_values (PyGIBaseInfo *self)
1447 {
1448     return _make_infos_tuple (self, g_enum_info_get_n_values, g_enum_info_get_value);
1449 }
1450
1451 static PyObject *
1452 _wrap_g_enum_info_is_flags (PyGIBaseInfo *self)
1453 {
1454     GIInfoType info_type = g_base_info_get_type ((GIBaseInfo *) self->info);
1455
1456     if (info_type == GI_INFO_TYPE_ENUM) {
1457         Py_RETURN_FALSE;
1458     } else if (info_type == GI_INFO_TYPE_FLAGS) {
1459         Py_RETURN_TRUE;
1460     } else {
1461         g_assert_not_reached();
1462     }
1463 }
1464
1465 static PyObject *
1466 _wrap_g_enum_info_get_methods (PyGIBaseInfo *self)
1467 {
1468     return _make_infos_tuple (self, g_enum_info_get_n_methods, g_enum_info_get_method);
1469 }
1470
1471 static PyObject *
1472 _wrap_g_enum_info_get_storage_type (PyGIBaseInfo *self)
1473 {
1474     return PYGLIB_PyLong_FromLong (g_enum_info_get_storage_type ((GIBaseInfo *) self->info));
1475 }
1476
1477 static PyMethodDef _PyGIEnumInfo_methods[] = {
1478     { "get_values", (PyCFunction) _wrap_g_enum_info_get_values, METH_NOARGS },
1479     { "is_flags", (PyCFunction) _wrap_g_enum_info_is_flags, METH_NOARGS },
1480     { "get_methods", (PyCFunction) _wrap_g_enum_info_get_methods, METH_NOARGS },
1481     { "get_storage_type", (PyCFunction) _wrap_g_enum_info_get_storage_type, METH_NOARGS },
1482     { NULL, NULL, 0 }
1483 };
1484
1485
1486 /* ObjectInfo */
1487 PYGLIB_DEFINE_TYPE ("ObjectInfo", PyGIObjectInfo_Type, PyGIBaseInfo);
1488
1489 static PyObject *
1490 _wrap_g_object_info_get_parent (PyGIBaseInfo *self)
1491 {
1492     return _get_child_info (self, g_object_info_get_parent);
1493 }
1494
1495 static PyObject *
1496 _wrap_g_object_info_get_methods (PyGIBaseInfo *self)
1497 {
1498     return _make_infos_tuple (self, g_object_info_get_n_methods, g_object_info_get_method);
1499 }
1500
1501 static PyObject *
1502 _wrap_g_object_info_find_method (PyGIBaseInfo *self, PyObject *py_name)
1503 {
1504     return _get_child_info_by_name (self, py_name, g_object_info_find_method);
1505 }
1506
1507 static PyObject *
1508 _wrap_g_object_info_get_fields (PyGIBaseInfo *self)
1509 {
1510     return _make_infos_tuple (self, g_object_info_get_n_fields, g_object_info_get_field);
1511 }
1512
1513 static PyObject *
1514 _wrap_g_object_info_get_properties (PyGIBaseInfo *self)
1515 {
1516     return _make_infos_tuple (self, g_object_info_get_n_properties, g_object_info_get_property);
1517 }
1518
1519 static PyObject *
1520 _wrap_g_object_info_get_signals (PyGIBaseInfo *self)
1521 {
1522     return _make_infos_tuple (self, g_object_info_get_n_signals, g_object_info_get_signal);
1523 }
1524
1525 static PyObject *
1526 _wrap_g_object_info_get_interfaces (PyGIBaseInfo *self)
1527 {
1528     return _make_infos_tuple (self, g_object_info_get_n_interfaces, g_object_info_get_interface);
1529 }
1530
1531 static PyObject *
1532 _wrap_g_object_info_get_constants (PyGIBaseInfo *self)
1533 {
1534     return _make_infos_tuple (self, g_object_info_get_n_constants, g_object_info_get_constant);
1535 }
1536
1537 static PyObject *
1538 _wrap_g_object_info_get_vfuncs (PyGIBaseInfo *self)
1539 {
1540     return _make_infos_tuple (self, g_object_info_get_n_vfuncs, g_object_info_get_vfunc);
1541 }
1542
1543 static PyObject *
1544 _wrap_g_object_info_get_abstract (PyGIBaseInfo *self)
1545 {
1546     gboolean is_abstract  = g_object_info_get_abstract ( (GIObjectInfo*) self->info);
1547     return PyBool_FromLong (is_abstract);
1548 }
1549
1550 static PyObject *
1551 _wrap_g_object_info_get_type_name (PyGIBaseInfo *self)
1552 {
1553     return _get_info_string (self, g_object_info_get_type_name);
1554 }
1555
1556 static PyObject *
1557 _wrap_g_object_info_get_type_init (PyGIBaseInfo *self)
1558 {
1559     return _get_info_string (self, g_object_info_get_type_init);
1560 }
1561
1562 static PyObject *
1563 _wrap_g_object_info_get_fundamental (PyGIBaseInfo *self)
1564 {
1565     return PyBool_FromLong (g_object_info_get_fundamental ( (GIObjectInfo*) self->info));
1566 }
1567
1568 static PyObject *
1569 _wrap_g_object_info_get_class_struct (PyGIBaseInfo *self)
1570 {
1571     return _get_child_info (self, g_object_info_get_class_struct);
1572 }
1573
1574 static PyObject *
1575 _wrap_g_object_info_find_vfunc (PyGIBaseInfo *self, PyObject *py_name)
1576 {
1577     return _get_child_info_by_name (self, py_name, g_object_info_find_vfunc);
1578 }
1579
1580 static PyObject *
1581 _wrap_g_object_info_get_unref_function (PyGIBaseInfo *self)
1582 {
1583     return _get_info_string (self, g_object_info_get_unref_function);
1584 }
1585
1586 static PyObject *
1587 _wrap_g_object_info_get_ref_function (PyGIBaseInfo *self)
1588 {
1589     return _get_info_string (self, g_object_info_get_ref_function);
1590 }
1591
1592 static PyObject *
1593 _wrap_g_object_info_get_set_value_function (PyGIBaseInfo *self)
1594 {
1595     return _get_info_string (self, g_object_info_get_set_value_function);
1596 }
1597
1598 static PyObject *
1599 _wrap_g_object_info_get_get_value_function (PyGIBaseInfo *self)
1600 {
1601     return _get_info_string (self, g_object_info_get_get_value_function);
1602 }
1603
1604 static PyMethodDef _PyGIObjectInfo_methods[] = {
1605     { "get_parent", (PyCFunction) _wrap_g_object_info_get_parent, METH_NOARGS },
1606     { "get_methods", (PyCFunction) _wrap_g_object_info_get_methods, METH_NOARGS },
1607     { "find_method", (PyCFunction) _wrap_g_object_info_find_method, METH_O },
1608     { "get_fields", (PyCFunction) _wrap_g_object_info_get_fields, METH_NOARGS },
1609     { "get_properties", (PyCFunction) _wrap_g_object_info_get_properties, METH_NOARGS },
1610     { "get_signals", (PyCFunction) _wrap_g_object_info_get_signals, METH_NOARGS },
1611     { "get_interfaces", (PyCFunction) _wrap_g_object_info_get_interfaces, METH_NOARGS },
1612     { "get_constants", (PyCFunction) _wrap_g_object_info_get_constants, METH_NOARGS },
1613     { "get_vfuncs", (PyCFunction) _wrap_g_object_info_get_vfuncs, METH_NOARGS },
1614     { "find_vfunc", (PyCFunction) _wrap_g_object_info_find_vfunc, METH_O },
1615     { "get_abstract", (PyCFunction) _wrap_g_object_info_get_abstract, METH_NOARGS },
1616     { "get_type_name", (PyCFunction) _wrap_g_object_info_get_type_name, METH_NOARGS },
1617     { "get_type_init", (PyCFunction) _wrap_g_object_info_get_type_init, METH_NOARGS },
1618     { "get_fundamental", (PyCFunction) _wrap_g_object_info_get_fundamental, METH_NOARGS },
1619     { "get_class_struct", (PyCFunction) _wrap_g_object_info_get_class_struct, METH_NOARGS },
1620     { "get_unref_function", (PyCFunction) _wrap_g_object_info_get_unref_function, METH_NOARGS },
1621     { "get_ref_function", (PyCFunction) _wrap_g_object_info_get_ref_function, METH_NOARGS },
1622     { "get_set_value_function", (PyCFunction) _wrap_g_object_info_get_set_value_function, METH_NOARGS },
1623     { "get_get_value_function", (PyCFunction) _wrap_g_object_info_get_get_value_function, METH_NOARGS },
1624     { NULL, NULL, 0 }
1625 };
1626
1627
1628 /* GIInterfaceInfo */
1629 PYGLIB_DEFINE_TYPE ("InterfaceInfo", PyGIInterfaceInfo_Type, PyGIBaseInfo);
1630
1631 static PyObject *
1632 _wrap_g_interface_info_get_methods (PyGIBaseInfo *self)
1633 {
1634     return _make_infos_tuple (self, g_interface_info_get_n_methods, g_interface_info_get_method);
1635 }
1636
1637 static PyObject *
1638 _wrap_g_interface_info_find_method (PyGIBaseInfo *self, PyObject *py_name)
1639 {
1640     return _get_child_info_by_name (self, py_name, g_interface_info_find_method);
1641 }
1642
1643 static PyObject *
1644 _wrap_g_interface_info_get_constants (PyGIBaseInfo *self)
1645 {
1646     return _make_infos_tuple (self, g_interface_info_get_n_constants, g_interface_info_get_constant);
1647 }
1648
1649 static PyObject *
1650 _wrap_g_interface_info_get_vfuncs (PyGIBaseInfo *self)
1651 {
1652     return _make_infos_tuple (self, g_interface_info_get_n_vfuncs, g_interface_info_get_vfunc);
1653 }
1654
1655 static PyObject *
1656 _wrap_g_interface_info_find_vfunc (PyGIBaseInfo *self, PyObject *py_name)
1657 {
1658     return _get_child_info_by_name (self, py_name, g_interface_info_find_vfunc);
1659 }
1660
1661 static PyObject *
1662 _wrap_g_interface_info_get_prerequisites (PyGIBaseInfo *self)
1663 {
1664     return _make_infos_tuple (self, g_interface_info_get_n_prerequisites, g_interface_info_get_prerequisite);
1665 }
1666
1667 static PyObject *
1668 _wrap_g_interface_info_get_properties (PyGIBaseInfo *self)
1669 {
1670     return _make_infos_tuple (self, g_interface_info_get_n_properties, g_interface_info_get_property);
1671 }
1672
1673 static PyObject *
1674 _wrap_g_interface_info_get_iface_struct (PyGIBaseInfo *self)
1675 {
1676     return _get_child_info (self, g_interface_info_get_iface_struct);
1677 }
1678
1679 static PyObject *
1680 _wrap_g_interface_info_get_signals (PyGIBaseInfo *self)
1681 {
1682     return _make_infos_tuple (self, g_interface_info_get_n_signals, g_interface_info_get_signal);
1683 }
1684
1685 static PyObject *
1686 _wrap_g_interface_info_find_signal (PyGIBaseInfo *self, PyObject *py_name)
1687 {
1688     return _get_child_info_by_name (self, py_name, g_interface_info_find_signal);
1689 }
1690
1691 static PyMethodDef _PyGIInterfaceInfo_methods[] = {
1692     { "get_prerequisites", (PyCFunction) _wrap_g_interface_info_get_prerequisites, METH_NOARGS },
1693     { "get_properties", (PyCFunction) _wrap_g_interface_info_get_properties, METH_NOARGS },
1694     { "get_methods", (PyCFunction) _wrap_g_interface_info_get_methods, METH_NOARGS },
1695     { "find_method", (PyCFunction) _wrap_g_interface_info_find_method, METH_O },
1696     { "get_signals", (PyCFunction) _wrap_g_interface_info_get_signals, METH_NOARGS },
1697     { "find_signal", (PyCFunction) _wrap_g_interface_info_find_signal, METH_O },
1698     { "get_vfuncs", (PyCFunction) _wrap_g_interface_info_get_vfuncs, METH_NOARGS },
1699     { "get_constants", (PyCFunction) _wrap_g_interface_info_get_constants, METH_NOARGS },
1700     { "get_iface_struct", (PyCFunction) _wrap_g_interface_info_get_iface_struct, METH_NOARGS },
1701     { "find_vfunc", (PyCFunction) _wrap_g_interface_info_find_vfunc, METH_O },
1702     { NULL, NULL, 0 }
1703 };
1704
1705 /* GIConstantInfo */
1706 PYGLIB_DEFINE_TYPE ("gi.ConstantInfo", PyGIConstantInfo_Type, PyGIBaseInfo);
1707
1708 static PyObject *
1709 _wrap_g_constant_info_get_value (PyGIBaseInfo *self)
1710 {
1711     GITypeInfo *type_info;
1712     GIArgument value;
1713     PyObject *py_value;
1714     gboolean free_array = FALSE;
1715
1716     if (g_constant_info_get_value ( (GIConstantInfo *) self->info, &value) < 0) {
1717         PyErr_SetString (PyExc_RuntimeError, "unable to get value");
1718         return NULL;
1719     }
1720
1721     type_info = g_constant_info_get_type ( (GIConstantInfo *) self->info);
1722
1723     if (g_type_info_get_tag (type_info) == GI_TYPE_TAG_ARRAY) {
1724         value.v_pointer = _pygi_argument_to_array (&value, NULL, NULL, NULL,
1725                                                    type_info, &free_array);
1726     }
1727
1728     py_value = _pygi_argument_to_object (&value, type_info, GI_TRANSFER_NOTHING);
1729     
1730     if (free_array) {
1731         g_array_free (value.v_pointer, FALSE);
1732     }
1733
1734     g_constant_info_free_value (self->info, &value);
1735     g_base_info_unref ( (GIBaseInfo *) type_info);
1736
1737     return py_value;
1738 }
1739
1740 static PyMethodDef _PyGIConstantInfo_methods[] = {
1741     { "get_value", (PyCFunction) _wrap_g_constant_info_get_value, METH_NOARGS },
1742     { NULL, NULL, 0 }
1743 };
1744
1745 /* GIValueInfo */
1746 PYGLIB_DEFINE_TYPE ("gi.ValueInfo", PyGIValueInfo_Type, PyGIBaseInfo);
1747
1748 static PyObject *
1749 _wrap_g_value_info_get_value (PyGIBaseInfo *self)
1750 {
1751     glong value;
1752
1753     value = g_value_info_get_value ( (GIValueInfo *) self->info);
1754
1755     return PYGLIB_PyLong_FromLong (value);
1756 }
1757
1758
1759 static PyMethodDef _PyGIValueInfo_methods[] = {
1760     { "get_value", (PyCFunction) _wrap_g_value_info_get_value, METH_NOARGS },
1761     { NULL, NULL, 0 }
1762 };
1763
1764
1765 /* GIFieldInfo */
1766 PYGLIB_DEFINE_TYPE ("gi.FieldInfo", PyGIFieldInfo_Type, PyGIBaseInfo);
1767
1768 static gssize
1769 _struct_field_array_length_marshal (gsize length_index,
1770                                     void *container_ptr,
1771                                     void *struct_data_ptr)
1772 {
1773     gssize array_len = -1;
1774     GIFieldInfo *array_len_field = NULL;
1775     GIArgument arg = {0};
1776     GIBaseInfo *container_info = (GIBaseInfo *)container_ptr;
1777
1778     switch (g_base_info_get_type (container_info)) {
1779         case GI_INFO_TYPE_UNION:
1780             array_len_field = g_union_info_get_field ((GIUnionInfo *)container_info, length_index);
1781             break;
1782         case GI_INFO_TYPE_STRUCT:
1783             array_len_field = g_struct_info_get_field ((GIStructInfo *)container_info, length_index);
1784             break;
1785         case GI_INFO_TYPE_OBJECT:
1786             array_len_field = g_object_info_get_field ((GIObjectInfo *)container_info, length_index);
1787             break;
1788         default:
1789             /* Other types don't have fields. */
1790             g_assert_not_reached();
1791     }
1792
1793     if (array_len_field == NULL) {
1794         return -1;
1795     }
1796
1797     if (g_field_info_get_field (array_len_field, struct_data_ptr, &arg)) {
1798         GITypeInfo *array_len_type_info;
1799
1800         array_len_type_info = g_field_info_get_type (array_len_field);
1801         if (array_len_type_info == NULL) {
1802             goto out;
1803         }
1804
1805         if (!pygi_argument_to_gssize (&arg,
1806                                       g_type_info_get_tag (array_len_type_info),
1807                                       &array_len)) {
1808             array_len = -1;
1809         }
1810
1811         g_base_info_unref (array_len_type_info);
1812     }
1813
1814 out:
1815     g_base_info_unref (array_len_field);
1816     return array_len;
1817 }
1818
1819 static gint
1820 _pygi_g_registered_type_info_check_object (GIRegisteredTypeInfo *info,
1821                                            gboolean              is_instance,
1822                                            PyObject             *object)
1823 {
1824     gint retval;
1825
1826     GType g_type;
1827     PyObject *py_type;
1828     gchar *type_name_expected = NULL;
1829     GIInfoType interface_type;
1830
1831     interface_type = g_base_info_get_type (info);
1832     if ( (interface_type == GI_INFO_TYPE_STRUCT) &&
1833             (g_struct_info_is_foreign ( (GIStructInfo*) info))) {
1834         /* TODO: Could we check is the correct foreign type? */
1835         return 1;
1836     }
1837
1838     g_type = g_registered_type_info_get_g_type (info);
1839     if (g_type != G_TYPE_NONE) {
1840         py_type = _pygi_type_get_from_g_type (g_type);
1841     } else {
1842         py_type = _pygi_type_import_by_gi_info ( (GIBaseInfo *) info);
1843     }
1844
1845     if (py_type == NULL) {
1846         return 0;
1847     }
1848
1849     g_assert (PyType_Check (py_type));
1850
1851     if (is_instance) {
1852         retval = PyObject_IsInstance (object, py_type);
1853         if (!retval) {
1854             type_name_expected = _pygi_g_base_info_get_fullname (
1855                                      (GIBaseInfo *) info);
1856         }
1857     } else {
1858         if (!PyObject_Type (py_type)) {
1859             type_name_expected = "type";
1860             retval = 0;
1861         } else if (!PyType_IsSubtype ( (PyTypeObject *) object,
1862                                        (PyTypeObject *) py_type)) {
1863             type_name_expected = _pygi_g_base_info_get_fullname (
1864                                      (GIBaseInfo *) info);
1865             retval = 0;
1866         } else {
1867             retval = 1;
1868         }
1869     }
1870
1871     Py_DECREF (py_type);
1872
1873     if (!retval) {
1874         PyTypeObject *object_type;
1875
1876         if (type_name_expected == NULL) {
1877             return -1;
1878         }
1879
1880         object_type = (PyTypeObject *) PyObject_Type (object);
1881         if (object_type == NULL) {
1882             return -1;
1883         }
1884
1885         PyErr_Format (PyExc_TypeError, "Must be %s, not %s",
1886                       type_name_expected, object_type->tp_name);
1887
1888         g_free (type_name_expected);
1889     }
1890
1891     return retval;
1892 }
1893
1894 static PyObject *
1895 _wrap_g_field_info_get_value (PyGIBaseInfo *self,
1896                               PyObject     *args)
1897 {
1898     PyObject *instance;
1899     GIBaseInfo *container_info;
1900     GIInfoType container_info_type;
1901     gpointer pointer;
1902     GITypeInfo *field_type_info;
1903     GIArgument value;
1904     PyObject *py_value = NULL;
1905     gboolean free_array = FALSE;
1906
1907     memset(&value, 0, sizeof(GIArgument));
1908
1909     if (!PyArg_ParseTuple (args, "O:FieldInfo.get_value", &instance)) {
1910         return NULL;
1911     }
1912
1913     container_info = g_base_info_get_container (self->info);
1914     g_assert (container_info != NULL);
1915
1916     /* Check the instance. */
1917     if (!_pygi_g_registered_type_info_check_object ( (GIRegisteredTypeInfo *) container_info, TRUE, instance)) {
1918         _PyGI_ERROR_PREFIX ("argument 1: ");
1919         return NULL;
1920     }
1921
1922     /* Get the pointer to the container. */
1923     container_info_type = g_base_info_get_type (container_info);
1924     switch (container_info_type) {
1925         case GI_INFO_TYPE_UNION:
1926         case GI_INFO_TYPE_STRUCT:
1927             pointer = pyg_boxed_get (instance, void);
1928             break;
1929         case GI_INFO_TYPE_OBJECT:
1930             pointer = pygobject_get (instance);
1931             break;
1932         default:
1933             /* Other types don't have fields. */
1934             g_assert_not_reached();
1935     }
1936
1937     /* Get the field's value. */
1938     field_type_info = g_field_info_get_type ( (GIFieldInfo *) self->info);
1939
1940     /* A few types are not handled by g_field_info_get_field, so do it here. */
1941     if (!g_type_info_is_pointer (field_type_info)
1942             && g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_INTERFACE) {
1943         GIBaseInfo *info;
1944         GIInfoType info_type;
1945
1946         if (! (g_field_info_get_flags ( (GIFieldInfo *) self->info) & GI_FIELD_IS_READABLE)) {
1947             PyErr_SetString (PyExc_RuntimeError, "field is not readable");
1948             goto out;
1949         }
1950
1951         info = g_type_info_get_interface (field_type_info);
1952
1953         info_type = g_base_info_get_type (info);
1954
1955         g_base_info_unref (info);
1956
1957         switch (info_type) {
1958             case GI_INFO_TYPE_UNION:
1959                 PyErr_SetString (PyExc_NotImplementedError, "getting an union is not supported yet");
1960                 goto out;
1961             case GI_INFO_TYPE_STRUCT:
1962             {
1963                 gsize offset;
1964
1965                 offset = g_field_info_get_offset ( (GIFieldInfo *) self->info);
1966
1967                 value.v_pointer = (char*) pointer + offset;
1968
1969                 goto argument_to_object;
1970             }
1971             default:
1972                 /* Fallback. */
1973                 break;
1974         }
1975     }
1976
1977     if (!g_field_info_get_field ( (GIFieldInfo *) self->info, pointer, &value)) {
1978         PyErr_SetString (PyExc_RuntimeError, "unable to get the value");
1979         goto out;
1980     }
1981
1982     if (g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_ARRAY) {
1983         value.v_pointer = _pygi_argument_to_array (&value,
1984                                                    _struct_field_array_length_marshal,
1985                                                    container_info,
1986                                                    pointer,
1987                                                    field_type_info,
1988                                                    &free_array);
1989     }
1990
1991 argument_to_object:
1992     py_value = _pygi_argument_to_object (&value, field_type_info, GI_TRANSFER_NOTHING);
1993
1994     if (free_array) {
1995         g_array_free (value.v_pointer, FALSE);
1996     }
1997
1998 out:
1999     g_base_info_unref ( (GIBaseInfo *) field_type_info);
2000
2001     return py_value;
2002 }
2003
2004 static PyObject *
2005 _wrap_g_field_info_set_value (PyGIBaseInfo *self,
2006                               PyObject     *args)
2007 {
2008     PyObject *instance;
2009     PyObject *py_value;
2010     GIBaseInfo *container_info;
2011     GIInfoType container_info_type;
2012     gpointer pointer;
2013     GITypeInfo *field_type_info;
2014     GIArgument value;
2015     PyObject *retval = NULL;
2016
2017     if (!PyArg_ParseTuple (args, "OO:FieldInfo.set_value", &instance, &py_value)) {
2018         return NULL;
2019     }
2020
2021     container_info = g_base_info_get_container (self->info);
2022     g_assert (container_info != NULL);
2023
2024     /* Check the instance. */
2025     if (!_pygi_g_registered_type_info_check_object ( (GIRegisteredTypeInfo *) container_info, TRUE, instance)) {
2026         _PyGI_ERROR_PREFIX ("argument 1: ");
2027         return NULL;
2028     }
2029
2030     /* Get the pointer to the container. */
2031     container_info_type = g_base_info_get_type (container_info);
2032     switch (container_info_type) {
2033         case GI_INFO_TYPE_UNION:
2034         case GI_INFO_TYPE_STRUCT:
2035             pointer = pyg_boxed_get (instance, void);
2036             break;
2037         case GI_INFO_TYPE_OBJECT:
2038             pointer = pygobject_get (instance);
2039             break;
2040         default:
2041             /* Other types don't have fields. */
2042             g_assert_not_reached();
2043     }
2044
2045     field_type_info = g_field_info_get_type ( (GIFieldInfo *) self->info);
2046
2047     /* Set the field's value. */
2048     /* A few types are not handled by g_field_info_set_field, so do it here. */
2049     if (!g_type_info_is_pointer (field_type_info)
2050             && g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_INTERFACE) {
2051         GIBaseInfo *info;
2052         GIInfoType info_type;
2053
2054         if (! (g_field_info_get_flags ( (GIFieldInfo *) self->info) & GI_FIELD_IS_WRITABLE)) {
2055             PyErr_SetString (PyExc_RuntimeError, "field is not writable");
2056             goto out;
2057         }
2058
2059         info = g_type_info_get_interface (field_type_info);
2060
2061         info_type = g_base_info_get_type (info);
2062
2063         switch (info_type) {
2064             case GI_INFO_TYPE_UNION:
2065                 PyErr_SetString (PyExc_NotImplementedError, "setting an union is not supported yet");
2066                 goto out;
2067             case GI_INFO_TYPE_STRUCT:
2068             {
2069                 gboolean is_simple;
2070                 gsize offset;
2071                 gssize size;
2072
2073                 is_simple = pygi_g_struct_info_is_simple ( (GIStructInfo *) info);
2074
2075                 if (!is_simple) {
2076                     PyErr_SetString (PyExc_TypeError,
2077                                      "cannot set a structure which has no well-defined ownership transfer rules");
2078                     g_base_info_unref (info);
2079                     goto out;
2080                 }
2081
2082                 value = _pygi_argument_from_object (py_value, field_type_info, GI_TRANSFER_NOTHING);
2083                 if (PyErr_Occurred()) {
2084                     g_base_info_unref (info);
2085                     goto out;
2086                 }
2087
2088                 offset = g_field_info_get_offset ( (GIFieldInfo *) self->info);
2089                 size = g_struct_info_get_size ( (GIStructInfo *) info);
2090                 g_assert (size > 0);
2091
2092                 g_memmove ((char*) pointer + offset, value.v_pointer, size);
2093
2094                 g_base_info_unref (info);
2095
2096                 retval = Py_None;
2097                 goto out;
2098             }
2099             default:
2100                 /* Fallback. */
2101                 break;
2102         }
2103
2104         g_base_info_unref (info);
2105     } else if (g_type_info_is_pointer (field_type_info)
2106             && (g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_VOID
2107                 || g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_UTF8)) {
2108         int offset;
2109         value = _pygi_argument_from_object (py_value, field_type_info, GI_TRANSFER_NOTHING);
2110         if (PyErr_Occurred()) {
2111             goto out;
2112         }
2113
2114         offset = g_field_info_get_offset ((GIFieldInfo *) self->info);
2115         G_STRUCT_MEMBER (gpointer, pointer, offset) = (gpointer)value.v_pointer;
2116
2117         retval = Py_None;
2118         goto out;
2119     }
2120
2121     value = _pygi_argument_from_object (py_value, field_type_info, GI_TRANSFER_EVERYTHING);
2122     if (PyErr_Occurred()) {
2123         goto out;
2124     }
2125
2126     if (!g_field_info_set_field ( (GIFieldInfo *) self->info, pointer, &value)) {
2127         _pygi_argument_release (&value, field_type_info, GI_TRANSFER_NOTHING, GI_DIRECTION_IN);
2128         PyErr_SetString (PyExc_RuntimeError, "unable to set value for field");
2129         goto out;
2130     }
2131
2132     retval = Py_None;
2133
2134 out:
2135     g_base_info_unref ( (GIBaseInfo *) field_type_info);
2136
2137     Py_XINCREF (retval);
2138     return retval;
2139 }
2140
2141 static PyObject *
2142 _wrap_g_field_info_get_flags (PyGIBaseInfo *self)
2143 {
2144     return PYGLIB_PyLong_FromLong (g_field_info_get_flags (self->info));
2145 }
2146
2147 static PyObject *
2148 _wrap_g_field_info_get_size (PyGIBaseInfo *self)
2149 {
2150     return PYGLIB_PyLong_FromLong (g_field_info_get_size (self->info));
2151 }
2152
2153 static PyObject *
2154 _wrap_g_field_info_get_offset (PyGIBaseInfo *self)
2155 {
2156     return PYGLIB_PyLong_FromLong (g_field_info_get_offset (self->info));
2157 }
2158
2159 static PyObject *
2160 _wrap_g_field_info_get_type (PyGIBaseInfo *self)
2161 {
2162     return _get_child_info (self, g_field_info_get_type);
2163 }
2164
2165 static PyMethodDef _PyGIFieldInfo_methods[] = {
2166     { "get_value", (PyCFunction) _wrap_g_field_info_get_value, METH_VARARGS },
2167     { "set_value", (PyCFunction) _wrap_g_field_info_set_value, METH_VARARGS },
2168     { "get_flags", (PyCFunction) _wrap_g_field_info_get_flags, METH_VARARGS },
2169     { "get_size", (PyCFunction) _wrap_g_field_info_get_size, METH_VARARGS },
2170     { "get_offset", (PyCFunction) _wrap_g_field_info_get_offset, METH_VARARGS },
2171     { "get_type", (PyCFunction) _wrap_g_field_info_get_type, METH_VARARGS },
2172     { NULL, NULL, 0 }
2173 };
2174
2175
2176 /* GIUnresolvedInfo */
2177 PYGLIB_DEFINE_TYPE ("gi.UnresolvedInfo", PyGIUnresolvedInfo_Type, PyGIBaseInfo);
2178
2179 static PyMethodDef _PyGIUnresolvedInfo_methods[] = {
2180     { NULL, NULL, 0 }
2181 };
2182
2183 /* GIVFuncInfo */
2184 PYGLIB_DEFINE_TYPE ("gi.VFuncInfo", PyGIVFuncInfo_Type, PyGICallableInfo);
2185
2186 static PyObject *
2187 _wrap_g_vfunc_info_get_flags (PyGIBaseInfo *self)
2188 {
2189     return PYGLIB_PyLong_FromLong (g_vfunc_info_get_flags ((GIVFuncInfo *) self->info));
2190 }
2191
2192 static PyObject *
2193 _wrap_g_vfunc_info_get_offset (PyGIBaseInfo *self)
2194 {
2195     return PYGLIB_PyLong_FromLong (g_vfunc_info_get_offset ((GIVFuncInfo *) self->info));
2196 }
2197
2198 static PyObject *
2199 _wrap_g_vfunc_info_get_signal (PyGIBaseInfo *self)
2200 {
2201     return _get_child_info (self, g_vfunc_info_get_signal);
2202 }
2203
2204 static PyObject *
2205 _wrap_g_vfunc_info_get_invoker (PyGIBaseInfo *self)
2206 {
2207     return _get_child_info (self, g_vfunc_info_get_invoker);
2208 }
2209
2210 static PyMethodDef _PyGIVFuncInfo_methods[] = {
2211     { "get_flags", (PyCFunction) _wrap_g_vfunc_info_get_flags, METH_NOARGS },
2212     { "get_offset", (PyCFunction) _wrap_g_vfunc_info_get_offset, METH_NOARGS },
2213     { "get_signal", (PyCFunction) _wrap_g_vfunc_info_get_signal, METH_NOARGS },
2214     { "get_invoker", (PyCFunction) _wrap_g_vfunc_info_get_invoker, METH_NOARGS },
2215     { NULL, NULL, 0 }
2216 };
2217
2218
2219 /* GIUnionInfo */
2220 PYGLIB_DEFINE_TYPE ("gi.UnionInfo", PyGIUnionInfo_Type, PyGIBaseInfo);
2221
2222 static PyObject *
2223 _wrap_g_union_info_get_fields (PyGIBaseInfo *self)
2224 {
2225     return _make_infos_tuple (self, g_union_info_get_n_fields, g_union_info_get_field);
2226 }
2227
2228 static PyObject *
2229 _wrap_g_union_info_get_methods (PyGIBaseInfo *self)
2230 {
2231     return _make_infos_tuple (self, g_union_info_get_n_methods, g_union_info_get_method);
2232 }
2233
2234 static PyObject *
2235 _wrap_g_union_info_get_size (PyGIBaseInfo *self)
2236 {
2237     return PYGLIB_PyLong_FromSize_t (g_union_info_get_size (self->info));
2238 }
2239
2240 static PyMethodDef _PyGIUnionInfo_methods[] = {
2241     { "get_fields", (PyCFunction) _wrap_g_union_info_get_fields, METH_NOARGS },
2242     { "get_methods", (PyCFunction) _wrap_g_union_info_get_methods, METH_NOARGS },
2243     { "get_size", (PyCFunction) _wrap_g_union_info_get_size, METH_NOARGS },
2244     { NULL, NULL, 0 }
2245 };
2246
2247 /* Private */
2248
2249 gchar *
2250 _pygi_g_base_info_get_fullname (GIBaseInfo *info)
2251 {
2252     GIBaseInfo *container_info;
2253     gchar *fullname;
2254
2255     container_info = g_base_info_get_container (info);
2256     if (container_info != NULL) {
2257         fullname = g_strdup_printf ("%s.%s.%s",
2258                                     g_base_info_get_namespace (container_info),
2259                                     _safe_base_info_get_name (container_info),
2260                                     _safe_base_info_get_name (info));
2261     } else {
2262         fullname = g_strdup_printf ("%s.%s",
2263                                     g_base_info_get_namespace (info),
2264                                     _safe_base_info_get_name (info));
2265     }
2266
2267     if (fullname == NULL) {
2268         PyErr_NoMemory();
2269     }
2270
2271     return fullname;
2272 }
2273
2274
2275 void
2276 _pygi_info_register_types (PyObject *m)
2277 {
2278 #define _PyGI_REGISTER_TYPE(m, type, cname, base) \
2279     Py_TYPE(&type) = &PyType_Type; \
2280     type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE); \
2281     type.tp_weaklistoffset = offsetof(PyGIBaseInfo, inst_weakreflist); \
2282     type.tp_methods = _PyGI##cname##_methods; \
2283     type.tp_base = &base; \
2284     if (PyType_Ready(&type)) \
2285         return; \
2286     if (PyModule_AddObject(m, #cname, (PyObject *)&type)) \
2287         return
2288
2289     Py_TYPE(&PyGIBaseInfo_Type) = &PyType_Type;
2290
2291     PyGIBaseInfo_Type.tp_dealloc = (destructor) _base_info_dealloc;
2292     PyGIBaseInfo_Type.tp_repr = (reprfunc) _base_info_repr;
2293     PyGIBaseInfo_Type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
2294     PyGIBaseInfo_Type.tp_weaklistoffset = offsetof(PyGIBaseInfo, inst_weakreflist);
2295     PyGIBaseInfo_Type.tp_methods = _PyGIBaseInfo_methods;
2296     PyGIBaseInfo_Type.tp_richcompare = (richcmpfunc)_base_info_richcompare;
2297     PyGIBaseInfo_Type.tp_getset = _base_info_getsets;
2298     PyGIBaseInfo_Type.tp_getattro = (getattrofunc) _base_info_getattro;
2299
2300     if (PyType_Ready(&PyGIBaseInfo_Type))
2301         return;
2302     if (PyModule_AddObject(m, "BaseInfo", (PyObject *)&PyGIBaseInfo_Type))
2303         return;
2304
2305     _PyGI_REGISTER_TYPE (m, PyGICallableInfo_Type, CallableInfo,
2306                          PyGIBaseInfo_Type);
2307     PyGICallableInfo_Type.tp_call = (ternaryfunc) _callable_info_call;
2308     PyGICallableInfo_Type.tp_dealloc = (destructor) _callable_info_dealloc;
2309
2310     _PyGI_REGISTER_TYPE (m, PyGIFunctionInfo_Type, FunctionInfo,
2311                          PyGICallableInfo_Type);
2312     PyGIFunctionInfo_Type.tp_call = (ternaryfunc) _function_info_call;
2313     PyGIFunctionInfo_Type.tp_descr_get = (descrgetfunc) _function_info_descr_get;
2314
2315     _PyGI_REGISTER_TYPE (m, PyGIVFuncInfo_Type, VFuncInfo,
2316                          PyGICallableInfo_Type);
2317     PyGIVFuncInfo_Type.tp_descr_get = (descrgetfunc) _vfunc_info_descr_get;
2318
2319     _PyGI_REGISTER_TYPE (m, PyGISignalInfo_Type, SignalInfo,
2320                          PyGICallableInfo_Type);
2321
2322     _PyGI_REGISTER_TYPE (m, PyGIUnresolvedInfo_Type, UnresolvedInfo,
2323                          PyGIBaseInfo_Type);
2324     _PyGI_REGISTER_TYPE (m, PyGICallbackInfo_Type, CallbackInfo,
2325                          PyGICallableInfo_Type);
2326     _PyGI_REGISTER_TYPE (m, PyGIRegisteredTypeInfo_Type, RegisteredTypeInfo,
2327                          PyGIBaseInfo_Type);
2328     _PyGI_REGISTER_TYPE (m, PyGIStructInfo_Type, StructInfo,
2329                          PyGIRegisteredTypeInfo_Type);
2330     _PyGI_REGISTER_TYPE (m, PyGIEnumInfo_Type, EnumInfo,
2331                          PyGIRegisteredTypeInfo_Type);
2332     _PyGI_REGISTER_TYPE (m, PyGIObjectInfo_Type, ObjectInfo,
2333                          PyGIRegisteredTypeInfo_Type);
2334     _PyGI_REGISTER_TYPE (m, PyGIInterfaceInfo_Type, InterfaceInfo,
2335                          PyGIRegisteredTypeInfo_Type);
2336     _PyGI_REGISTER_TYPE (m, PyGIConstantInfo_Type, ConstantInfo,
2337                          PyGIBaseInfo_Type);
2338     _PyGI_REGISTER_TYPE (m, PyGIValueInfo_Type, ValueInfo,
2339                          PyGIBaseInfo_Type);
2340     _PyGI_REGISTER_TYPE (m, PyGIFieldInfo_Type, FieldInfo,
2341                          PyGIBaseInfo_Type);
2342     _PyGI_REGISTER_TYPE (m, PyGIUnionInfo_Type, UnionInfo,
2343                          PyGIRegisteredTypeInfo_Type);
2344     _PyGI_REGISTER_TYPE (m, PyGIErrorDomainInfo_Type, ErrorDomainInfo,
2345                          PyGIBaseInfo_Type);
2346     _PyGI_REGISTER_TYPE (m, PyGIPropertyInfo_Type, PropertyInfo,
2347                          PyGIBaseInfo_Type);
2348     _PyGI_REGISTER_TYPE (m, PyGIArgInfo_Type, ArgInfo,
2349                          PyGIBaseInfo_Type);
2350     _PyGI_REGISTER_TYPE (m, PyGITypeInfo_Type, TypeInfo,
2351                          PyGIBaseInfo_Type);
2352
2353 #undef _PyGI_REGISTER_TYPE
2354
2355 #define _PyGI_ENUM_BEGIN(name) \
2356         { \
2357             const char *__enum_name = #name; \
2358             PyObject *__enum_value = NULL; \
2359             PyObject *__new_enum_cls = NULL; \
2360             PyObject *__enum_instance_dict = PyDict_New(); \
2361             PyObject *__module_name = PyObject_GetAttrString (m, "__name__"); \
2362             PyDict_SetItemString (__enum_instance_dict, "__module__", __module_name); \
2363             Py_DECREF (__module_name);
2364
2365 #define _PyGI_ENUM_ADD_VALUE(prefix, name) \
2366             __enum_value = PYGLIB_PyLong_FromLong (prefix##_##name); \
2367             if (PyDict_SetItemString(__enum_instance_dict, #name, __enum_value)) { \
2368                 Py_DECREF (__enum_instance_dict); \
2369                 Py_DECREF (__enum_value); \
2370                 return; \
2371             } \
2372             Py_DECREF (__enum_value);
2373
2374 #define _PyGI_ENUM_END \
2375             __new_enum_cls = PyObject_CallFunction ((PyObject *)&PyType_Type, "s(O)O", \
2376                                                     __enum_name, (PyObject *)&PyType_Type, \
2377                                                     __enum_instance_dict); \
2378             Py_DECREF (__enum_instance_dict); \
2379             PyModule_AddObject (m, __enum_name, __new_enum_cls); /* steals ref */ \
2380         }
2381
2382
2383     /* GIDirection */
2384     _PyGI_ENUM_BEGIN (Direction)
2385         _PyGI_ENUM_ADD_VALUE (GI_DIRECTION, IN)
2386         _PyGI_ENUM_ADD_VALUE (GI_DIRECTION, OUT)
2387         _PyGI_ENUM_ADD_VALUE (GI_DIRECTION, INOUT)
2388     _PyGI_ENUM_END
2389
2390
2391     /* GITransfer */
2392     _PyGI_ENUM_BEGIN (Transfer)
2393         _PyGI_ENUM_ADD_VALUE (GI_TRANSFER, NOTHING)
2394         _PyGI_ENUM_ADD_VALUE (GI_TRANSFER, CONTAINER)
2395         _PyGI_ENUM_ADD_VALUE (GI_TRANSFER, EVERYTHING)
2396     _PyGI_ENUM_END
2397
2398     /* GIArrayType */
2399     _PyGI_ENUM_BEGIN (ArrayType)
2400         _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE, C)
2401         _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE, ARRAY)
2402         _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE, PTR_ARRAY)
2403         _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE, BYTE_ARRAY)
2404     _PyGI_ENUM_END
2405
2406     /* GIScopeType */
2407     _PyGI_ENUM_BEGIN (ScopeType)
2408         _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE, INVALID)
2409         _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE, CALL)
2410         _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE, ASYNC)
2411         _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE, NOTIFIED)
2412     _PyGI_ENUM_END
2413
2414     /* GIVFuncInfoFlags */
2415     _PyGI_ENUM_BEGIN (VFuncInfoFlags)
2416         _PyGI_ENUM_ADD_VALUE (GI_VFUNC_MUST, CHAIN_UP)
2417         _PyGI_ENUM_ADD_VALUE (GI_VFUNC_MUST, OVERRIDE)
2418         _PyGI_ENUM_ADD_VALUE (GI_VFUNC_MUST, NOT_OVERRIDE)
2419     _PyGI_ENUM_END
2420
2421     /* GIFieldInfoFlags */
2422     _PyGI_ENUM_BEGIN (FieldInfoFlags)
2423         _PyGI_ENUM_ADD_VALUE (GI_FIELD, IS_READABLE)
2424         _PyGI_ENUM_ADD_VALUE (GI_FIELD, IS_WRITABLE)
2425     _PyGI_ENUM_END
2426
2427     /* GIFunctionInfoFlags */
2428     _PyGI_ENUM_BEGIN (FunctionInfoFlags)
2429         _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, IS_METHOD)
2430         _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, IS_CONSTRUCTOR)
2431         _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, IS_GETTER)
2432         _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, IS_SETTER)
2433         _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, WRAPS_VFUNC)
2434         _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, THROWS)
2435     _PyGI_ENUM_END
2436
2437     /* GITypeTag */
2438     _PyGI_ENUM_BEGIN (TypeTag)
2439         /* Basic types */
2440         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, VOID)
2441         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, BOOLEAN)
2442         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, INT8)
2443         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UINT8)
2444         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, INT16)
2445         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UINT16)
2446         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, INT32)
2447         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UINT32)
2448         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, INT64)
2449         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UINT64)
2450         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, FLOAT)
2451         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, DOUBLE)
2452         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, GTYPE)
2453         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UTF8)
2454         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, FILENAME)
2455
2456         /* Non-basic types; compare with G_TYPE_TAG_IS_BASIC */
2457         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, ARRAY)
2458         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, INTERFACE)
2459         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, GLIST)
2460         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, GSLIST)
2461         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, GHASH)
2462         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, ERROR)
2463
2464         /* Another basic type */
2465         _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UNICHAR)
2466     _PyGI_ENUM_END
2467
2468     /* GIInfoType */
2469     _PyGI_ENUM_BEGIN (InfoType)
2470         _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, INVALID)
2471         _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, FUNCTION)
2472         _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, CALLBACK)
2473         _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, STRUCT)
2474         _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, BOXED)
2475         _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, ENUM)
2476         _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, FLAGS)
2477         _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, OBJECT)
2478         _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, INTERFACE)
2479         _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, CONSTANT)
2480         _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, INVALID_0)
2481         _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, UNION)
2482         _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, VALUE)
2483         _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, SIGNAL)
2484         _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, VFUNC)
2485         _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, PROPERTY)
2486         _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, FIELD)
2487         _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, ARG)
2488         _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, TYPE)
2489         _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, UNRESOLVED)
2490     _PyGI_ENUM_END
2491
2492 #undef _PyGI_ENUM_BEGIN
2493 #undef _PyGI_ENUM_ADD_VALUE
2494 #undef _PyGI_ENUM_END
2495
2496 }