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