1 /* -*- Mode: C; c-basic-offset: 4 -*-
2 * vim: tabstop=4 shiftwidth=4 expandtab
4 * Copyright (C) 2005-2009 Johan Dahlin <johan@gnome.org>
5 * Copyright (C) 2013 Simon Feltman <sfeltman@gnome.org>
7 * pygi-info.c: GI.*Info wrappers.
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.
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.
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/>.
23 #include "pygi-private.h"
24 #include "pygi-cache.h"
25 #include "pygobject-private.h"
27 #include <pyglib-python-compat.h>
30 /* _generate_doc_string
32 * C wrapper to call Python implemented "gi.docstring.generate_doc_string"
35 _generate_doc_string(PyGIBaseInfo *self)
37 static PyObject *_py_generate_doc_string = NULL;
39 if (_py_generate_doc_string == NULL) {
40 PyObject *mod = PyImport_ImportModule ("gi.docstring");
44 _py_generate_doc_string = PyObject_GetAttrString (mod, "generate_doc_string");
45 if (_py_generate_doc_string == NULL) {
52 return PyObject_CallFunctionObjArgs (_py_generate_doc_string, self, NULL);
56 _get_info_string (PyGIBaseInfo *self,
57 const gchar* (*get_info_string)(GIBaseInfo*))
59 const gchar *value = get_info_string ((GIBaseInfo*)self->info);
63 return PYGLIB_PyUnicode_FromString (value);
67 _get_child_info (PyGIBaseInfo *self,
68 GIBaseInfo* (*get_child_info)(GIBaseInfo*))
73 info = get_child_info ((GIBaseInfo*)self->info);
78 py_info = _pygi_info_new (info);
79 g_base_info_unref (info);
85 _get_child_info_by_name (PyGIBaseInfo *self, PyObject *py_name,
86 GIBaseInfo* (*get_child_info_by_name)(GIBaseInfo*, const gchar*))
92 if (!PYGLIB_PyUnicode_Check (py_name)) {
93 PyErr_SetString (PyExc_TypeError, "expected string name");
97 name = PYGLIB_PyUnicode_AsString (py_name);
98 info = get_child_info_by_name ((GIObjectInfo*)self->info, name);
103 py_info = _pygi_info_new (info);
104 g_base_info_unref (info);
111 * Build a tuple from the common API pattern in GI of having a
112 * function which returns a count and an indexed GIBaseInfo
113 * in the range of 0 to count;
116 _make_infos_tuple (PyGIBaseInfo *self,
117 gint (*get_n_infos)(GIBaseInfo*),
118 GIBaseInfo* (*get_info)(GIBaseInfo*, gint))
124 n_infos = get_n_infos ( (GIBaseInfo *) self->info);
126 infos = PyTuple_New (n_infos);
131 for (i = 0; i < n_infos; i++) {
135 info = (GIBaseInfo *) get_info (self->info, i);
136 g_assert (info != NULL);
138 py_info = _pygi_info_new (info);
140 g_base_info_unref (info);
142 if (py_info == NULL) {
147 PyTuple_SET_ITEM (infos, i, py_info);
156 /* We need to be careful about calling g_base_info_get_name because
157 * calling it with a GI_INFO_TYPE_TYPE will crash.
158 * See: https://bugzilla.gnome.org/show_bug.cgi?id=709456
161 _safe_base_info_get_name (GIBaseInfo *info)
163 if (g_base_info_get_type (info) == GI_INFO_TYPE_TYPE) {
164 return "type_type_instance";
166 return g_base_info_get_name (info);
171 _base_info_dealloc (PyGIBaseInfo *self)
173 if (self->inst_weakreflist != NULL)
174 PyObject_ClearWeakRefs ( (PyObject *) self);
176 g_base_info_unref (self->info);
178 if (self->cache != NULL)
179 pygi_callable_cache_free ( (PyGICallableCache *) self->cache);
181 Py_TYPE (self)->tp_free ((PyObject *)self);
185 _base_info_repr (PyGIBaseInfo *self)
188 return PYGLIB_PyUnicode_FromFormat ("%s(%s)",
189 Py_TYPE( (PyObject *) self)->tp_name,
190 _safe_base_info_get_name (self->info));
194 _wrap_g_base_info_equal (PyGIBaseInfo *self, PyObject *other)
196 GIBaseInfo *other_info;
198 if (!PyObject_TypeCheck (other, &PyGIBaseInfo_Type)) {
199 Py_INCREF (Py_NotImplemented);
200 return Py_NotImplemented;
203 other_info = ((PyGIBaseInfo *)other)->info;
204 if (g_base_info_equal (self->info, other_info)) {
212 _base_info_richcompare (PyGIBaseInfo *self, PyObject *other, int op)
218 return _wrap_g_base_info_equal (self, other);
220 res = _wrap_g_base_info_equal (self, other);
221 if (res == Py_True) {
229 res = Py_NotImplemented;
236 PYGLIB_DEFINE_TYPE("gi.BaseInfo", PyGIBaseInfo_Type, PyGIBaseInfo);
239 _pygi_is_python_keyword (const gchar *name)
241 /* It may be better to use keyword.iskeyword(); keep in sync with
242 * python -c 'import keyword; print(keyword.kwlist)' */
243 #if PY_VERSION_HEX < 0x03000000
245 static const gchar* keywords[] = {"and", "as", "assert", "break", "class",
246 "continue", "def", "del", "elif", "else", "except", "exec", "finally",
247 "for", "from", "global", "if", "import", "in", "is", "lambda", "not",
248 "or", "pass", "print", "raise", "return", "try", "while", "with",
250 #elif PY_VERSION_HEX < 0x04000000
251 /* Python 3.x; note that we explicitly keep "print"; it is not a keyword
252 * any more, but we do not want to break API between Python versions */
253 static const gchar* keywords[] = {"False", "None", "True", "and", "as",
254 "assert", "break", "class", "continue", "def", "del", "elif", "else",
255 "except", "finally", "for", "from", "global", "if", "import", "in",
256 "is", "lambda", "nonlocal", "not", "or", "pass", "raise", "return",
257 "try", "while", "with", "yield",
260 #error Need keyword list for this major Python version
265 for (i = keywords; *i != NULL; ++i) {
266 if (strcmp (name, *i) == 0) {
275 _wrap_g_base_info_get_type (PyGIBaseInfo *self)
277 return PYGLIB_PyLong_FromLong (g_base_info_get_type (self->info));
281 _wrap_g_base_info_get_name (PyGIBaseInfo *self)
285 name = _safe_base_info_get_name (self->info);
287 /* escape keywords */
288 if (_pygi_is_python_keyword (name)) {
289 gchar *escaped = g_strconcat (name, "_", NULL);
290 PyObject *obj = PYGLIB_PyUnicode_FromString (escaped);
295 return PYGLIB_PyUnicode_FromString (name);
299 _wrap_g_base_info_get_name_unescaped (PyGIBaseInfo *self)
301 return _get_info_string (self, _safe_base_info_get_name);
305 _wrap_g_base_info_get_namespace (PyGIBaseInfo *self)
307 return _get_info_string (self, g_base_info_get_namespace);
311 _wrap_g_base_info_is_deprecated (PyGIBaseInfo *self)
313 if (g_base_info_is_deprecated (self->info))
320 _wrap_g_base_info_get_attribute (PyGIBaseInfo *self, PyObject *arg)
325 if (!PYGLIB_PyUnicode_Check (arg)) {
326 PyErr_SetString (PyExc_TypeError, "expected string name");
330 name = PYGLIB_PyUnicode_AsString (arg);
331 value = g_base_info_get_attribute (self->info, name);
335 return PYGLIB_PyUnicode_FromString (value);
339 _wrap_g_base_info_get_container (PyGIBaseInfo *self)
341 /* Note: don't use _get_child_info because g_base_info_get_container
342 * is marked as [transfer none] and therefore returns a borrowed ref.
346 info = g_base_info_get_container (self->info);
352 return _pygi_info_new (info);
356 static PyMethodDef _PyGIBaseInfo_methods[] = {
357 { "get_type", (PyCFunction) _wrap_g_base_info_get_type, METH_NOARGS },
358 { "get_name", (PyCFunction) _wrap_g_base_info_get_name, METH_NOARGS },
359 { "get_name_unescaped", (PyCFunction) _wrap_g_base_info_get_name_unescaped, METH_NOARGS },
360 { "get_namespace", (PyCFunction) _wrap_g_base_info_get_namespace, METH_NOARGS },
361 { "is_deprecated", (PyCFunction) _wrap_g_base_info_is_deprecated, METH_NOARGS },
362 { "get_attribute", (PyCFunction) _wrap_g_base_info_get_attribute, METH_O },
363 { "get_container", (PyCFunction) _wrap_g_base_info_get_container, METH_NOARGS },
364 { "equal", (PyCFunction) _wrap_g_base_info_equal, METH_O },
368 /* _base_info_getattro:
370 * The usage of __getattr__ is needed because the get/set method table
371 * does not work for __doc__.
374 _base_info_getattro(PyGIBaseInfo *self, PyObject *name)
378 static PyObject *docstr;
379 if (docstr == NULL) {
380 docstr= PYGLIB_PyUnicode_InternFromString("__doc__");
386 PYGLIB_PyUnicode_InternInPlace (&name);
388 if (name == docstr) {
389 result = _generate_doc_string (self);
391 result = PyObject_GenericGetAttr ((PyObject *)self, name);
399 _base_info_attr_name(PyGIBaseInfo *self, void *closure)
401 return _wrap_g_base_info_get_name (self);
405 _base_info_attr_module(PyGIBaseInfo *self, void *closure)
407 return PYGLIB_PyUnicode_FromFormat ("gi.repository.%s",
408 g_base_info_get_namespace (self->info));
411 static PyGetSetDef _base_info_getsets[] = {
412 { "__name__", (getter)_base_info_attr_name, (setter)0, "Name", NULL},
413 { "__module__", (getter)_base_info_attr_module, (setter)0, "Module name", NULL},
418 _pygi_info_new (GIBaseInfo *info)
420 GIInfoType info_type;
421 PyTypeObject *type = NULL;
424 info_type = g_base_info_get_type (info);
428 case GI_INFO_TYPE_INVALID:
429 PyErr_SetString (PyExc_RuntimeError, "Invalid info type");
431 case GI_INFO_TYPE_FUNCTION:
432 type = &PyGIFunctionInfo_Type;
434 case GI_INFO_TYPE_CALLBACK:
435 type = &PyGICallbackInfo_Type;
437 case GI_INFO_TYPE_STRUCT:
438 case GI_INFO_TYPE_BOXED:
439 type = &PyGIStructInfo_Type;
441 case GI_INFO_TYPE_ENUM:
442 case GI_INFO_TYPE_FLAGS:
443 type = &PyGIEnumInfo_Type;
445 case GI_INFO_TYPE_OBJECT:
446 type = &PyGIObjectInfo_Type;
448 case GI_INFO_TYPE_INTERFACE:
449 type = &PyGIInterfaceInfo_Type;
451 case GI_INFO_TYPE_CONSTANT:
452 type = &PyGIConstantInfo_Type;
454 case GI_INFO_TYPE_UNION:
455 type = &PyGIUnionInfo_Type;
457 case GI_INFO_TYPE_VALUE:
458 type = &PyGIValueInfo_Type;
460 case GI_INFO_TYPE_SIGNAL:
461 type = &PyGISignalInfo_Type;
463 case GI_INFO_TYPE_VFUNC:
464 type = &PyGIVFuncInfo_Type;
466 case GI_INFO_TYPE_PROPERTY:
467 type = &PyGIPropertyInfo_Type;
469 case GI_INFO_TYPE_FIELD:
470 type = &PyGIFieldInfo_Type;
472 case GI_INFO_TYPE_ARG:
473 type = &PyGIArgInfo_Type;
475 case GI_INFO_TYPE_TYPE:
476 type = &PyGITypeInfo_Type;
478 case GI_INFO_TYPE_UNRESOLVED:
479 type = &PyGIUnresolvedInfo_Type;
482 g_assert_not_reached();
486 self = (PyGIBaseInfo *) type->tp_alloc (type, 0);
491 self->info = g_base_info_ref (info);
492 self->inst_weakreflist = NULL;
495 return (PyObject *) self;
499 _pygi_object_get_gi_info (PyObject *object,
503 GIBaseInfo *info = NULL;
505 py_info = PyObject_GetAttrString (object, "__info__");
506 if (py_info == NULL) {
509 if (!PyObject_TypeCheck (py_info, type)) {
510 PyErr_Format (PyExc_TypeError, "attribute '__info__' must be %s, not %s",
511 type->tp_name, Py_TYPE(py_info)->tp_name);
515 info = ( (PyGIBaseInfo *) py_info)->info;
516 g_base_info_ref (info);
526 PYGLIB_DEFINE_TYPE ("gi.CallableInfo", PyGICallableInfo_Type, PyGICallableInfo);
528 /* _callable_info_call:
530 * Shared wrapper for invoke which can be bound (instance method or class constructor)
531 * or unbound (function or static method).
534 _callable_info_call (PyGICallableInfo *self, PyObject *args, PyObject *kwargs)
536 /* Insert the bound arg at the beginning of the invoke method args. */
537 if (self->py_bound_arg) {
540 Py_ssize_t argcount = PyTuple_Size (args);
541 PyObject *newargs = PyTuple_New (argcount + 1);
545 Py_INCREF (self->py_bound_arg);
546 PyTuple_SET_ITEM (newargs, 0, self->py_bound_arg);
548 for (i = 0; i < argcount; i++) {
549 PyObject *v = PyTuple_GET_ITEM (args, i);
551 PyTuple_SET_ITEM (newargs, i+1, v);
554 /* Invoke with the original GI info struct this wrapper was based upon.
555 * This is necessary to maintain the same cache for all bound versions.
557 result = _wrap_g_callable_info_invoke ((PyGIBaseInfo *)self->py_unbound_info,
563 /* We should never have an unbound info when calling when calling invoke
564 * at this point because the descriptor implementation on sub-classes
565 * should return "self" not a copy when there is no bound arg.
567 g_assert (self->py_unbound_info == NULL);
568 return _wrap_g_callable_info_invoke ((PyGIBaseInfo *)self, args, kwargs);
573 /* _function_info_call:
575 * Specialization of _callable_info_call for GIFunctionInfo which
576 * handles constructor error conditions.
579 _function_info_call (PyGICallableInfo *self, PyObject *args, PyObject *kwargs)
581 if (self->py_bound_arg) {
582 GIFunctionInfoFlags flags;
584 /* Ensure constructors are only called as class methods on the class
585 * implementing the constructor and not on sub-classes.
587 flags = g_function_info_get_flags ( (GIFunctionInfo*) self->base.info);
588 if (flags & GI_FUNCTION_IS_CONSTRUCTOR) {
589 PyObject *py_str_name;
590 const gchar *str_name;
591 GIBaseInfo *container_info = g_base_info_get_container (self->base.info);
592 g_assert (container_info != NULL);
594 py_str_name = PyObject_GetAttrString (self->py_bound_arg, "__name__");
595 if (py_str_name == NULL)
598 if (PyUnicode_Check (py_str_name) ) {
599 PyObject *tmp = PyUnicode_AsUTF8String (py_str_name);
600 Py_DECREF (py_str_name);
604 #if PY_VERSION_HEX < 0x03000000
605 str_name = PyString_AsString (py_str_name);
607 str_name = PyBytes_AsString (py_str_name);
610 if (strcmp (str_name, _safe_base_info_get_name (container_info))) {
611 PyErr_Format (PyExc_TypeError,
612 "%s constructor cannot be used to create instances of "
614 _safe_base_info_get_name (container_info),
616 Py_DECREF (py_str_name);
619 Py_DECREF (py_str_name);
623 return _callable_info_call (self, args, kwargs);
626 /* _new_bound_callable_info
628 * Utility function for sub-classes to create a bound version of themself.
630 static PyGICallableInfo *
631 _new_bound_callable_info (PyGICallableInfo *self, PyObject *bound_arg)
633 PyGICallableInfo *new_self;
635 /* Return self if this is already bound or there is nothing passed to bind. */
636 if (self->py_bound_arg != NULL || bound_arg == NULL || bound_arg == Py_None) {
637 Py_INCREF ((PyObject *)self);
641 new_self = (PyGICallableInfo *)_pygi_info_new (self->base.info);
642 if (new_self == NULL)
645 Py_INCREF ((PyObject *)self);
646 new_self->py_unbound_info = (struct PyGICallableInfo *)self;
648 Py_INCREF (bound_arg);
649 new_self->py_bound_arg = bound_arg;
654 /* _function_info_descr_get
656 * Descriptor protocol implementation for functions, methods, and constructors.
659 _function_info_descr_get (PyGICallableInfo *self, PyObject *obj, PyObject *type) {
660 GIFunctionInfoFlags flags;
661 PyObject *bound_arg = NULL;
663 flags = g_function_info_get_flags ( (GIFunctionInfo*) self->base.info);
664 if (flags & GI_FUNCTION_IS_CONSTRUCTOR) {
666 bound_arg = (PyObject *)(Py_TYPE(obj));
669 } else if (flags & GI_FUNCTION_IS_METHOD) {
673 return (PyObject *)_new_bound_callable_info (self, bound_arg);
676 /* _vfunc_info_descr_get
678 * Descriptor protocol implementation for virtual functions.
681 _vfunc_info_descr_get (PyGICallableInfo *self, PyObject *obj, PyObject *type) {
683 PyObject *bound_arg = NULL;
685 bound_arg = PyObject_GetAttrString (type, "__gtype__");
686 if (bound_arg == NULL)
689 /* _new_bound_callable_info adds its own ref so free the one from GetAttrString */
690 result = (PyObject *)_new_bound_callable_info (self, bound_arg);
691 Py_DECREF (bound_arg);
696 _callable_info_dealloc (PyGICallableInfo *self)
698 Py_CLEAR (self->py_unbound_info);
699 Py_CLEAR (self->py_bound_arg);
701 PyGIBaseInfo_Type.tp_dealloc ((PyObject *) self);
705 _wrap_g_callable_info_get_arguments (PyGIBaseInfo *self)
707 return _make_infos_tuple (self, g_callable_info_get_n_args, g_callable_info_get_arg);
711 _wrap_g_callable_info_get_return_type (PyGIBaseInfo *self)
713 return _get_child_info (self, g_callable_info_get_return_type);
717 _wrap_g_callable_info_get_caller_owns (PyGIBaseInfo *self)
719 return PYGLIB_PyLong_FromLong (
720 g_callable_info_get_caller_owns (self->info) );
724 _wrap_g_callable_info_may_return_null (PyGIBaseInfo *self)
726 return PyBool_FromLong (
727 g_callable_info_may_return_null (self->info) );
731 _wrap_g_callable_info_skip_return (PyGIBaseInfo *self)
733 return PyBool_FromLong (g_callable_info_skip_return (self->info));
737 _wrap_g_callable_info_get_return_attribute (PyGIBaseInfo *self, PyObject *py_name)
742 if (!PYGLIB_PyUnicode_Check (py_name)) {
743 PyErr_SetString (PyExc_TypeError, "expected string name");
747 name = PYGLIB_PyUnicode_AsString (py_name);
748 attr = g_callable_info_get_return_attribute (self->info, name);
750 return PYGLIB_PyUnicode_FromString (
751 g_callable_info_get_return_attribute (self->info, name));
753 PyErr_Format(PyExc_AttributeError, "return attribute %s not found", name);
759 _wrap_g_callable_info_can_throw_gerror (PyGIBaseInfo *self)
761 if (g_callable_info_can_throw_gerror (self->info))
767 static PyMethodDef _PyGICallableInfo_methods[] = {
768 { "invoke", (PyCFunction) _wrap_g_callable_info_invoke, METH_VARARGS | METH_KEYWORDS },
769 { "get_arguments", (PyCFunction) _wrap_g_callable_info_get_arguments, METH_NOARGS },
770 { "get_return_type", (PyCFunction) _wrap_g_callable_info_get_return_type, METH_NOARGS },
771 { "get_caller_owns", (PyCFunction) _wrap_g_callable_info_get_caller_owns, METH_NOARGS },
772 { "may_return_null", (PyCFunction) _wrap_g_callable_info_may_return_null, METH_NOARGS },
773 { "skip_return", (PyCFunction) _wrap_g_callable_info_skip_return, METH_NOARGS },
774 { "get_return_attribute", (PyCFunction) _wrap_g_callable_info_get_return_attribute, METH_O },
775 { "can_throw_gerror", (PyCFunction) _wrap_g_callable_info_can_throw_gerror, METH_NOARGS },
780 PYGLIB_DEFINE_TYPE ("gi.CallbackInfo", PyGICallbackInfo_Type, PyGICallableInfo);
782 static PyMethodDef _PyGICallbackInfo_methods[] = {
786 /* ErrorDomainInfo */
787 PYGLIB_DEFINE_TYPE ("gi.ErrorDomainInfo", PyGIErrorDomainInfo_Type, PyGIBaseInfo);
789 static PyMethodDef _PyGIErrorDomainInfo_methods[] = {
794 PYGLIB_DEFINE_TYPE ("gi.SignalInfo", PyGISignalInfo_Type, PyGICallableInfo);
797 _wrap_g_signal_info_get_flags (PyGIBaseInfo *self)
799 return PYGLIB_PyLong_FromLong (
800 g_signal_info_get_flags ((GISignalInfo *)self->info) );
804 _wrap_g_signal_info_get_class_closure (PyGIBaseInfo *self)
806 return _get_child_info (self, g_signal_info_get_class_closure);
810 _wrap_g_signal_info_true_stops_emit (PyGIBaseInfo *self)
812 return PyBool_FromLong (
813 g_signal_info_true_stops_emit ((GISignalInfo *)self->info) );
816 static PyMethodDef _PyGISignalInfo_methods[] = {
817 { "get_flags", (PyCFunction) _wrap_g_signal_info_get_flags, METH_NOARGS },
818 { "get_class_closure", (PyCFunction) _wrap_g_signal_info_get_class_closure, METH_NOARGS },
819 { "true_stops_emit", (PyCFunction) _wrap_g_signal_info_true_stops_emit, METH_NOARGS },
824 PYGLIB_DEFINE_TYPE ("gi.PropertyInfo", PyGIPropertyInfo_Type, PyGIBaseInfo);
827 _wrap_g_property_info_get_flags (PyGIBaseInfo *self)
829 return PYGLIB_PyLong_FromLong (
830 g_property_info_get_flags ((GIPropertyInfo *)self->info) );
834 _wrap_g_property_info_get_type (PyGIBaseInfo *self)
836 return _get_child_info (self, g_property_info_get_type);
840 _wrap_g_property_info_get_ownership_transfer (PyGIBaseInfo *self)
842 return PYGLIB_PyLong_FromLong (
843 g_property_info_get_ownership_transfer ((GIPropertyInfo *)self->info) );
846 static PyMethodDef _PyGIPropertyInfo_methods[] = {
847 { "get_flags", (PyCFunction) _wrap_g_property_info_get_flags, METH_NOARGS },
848 { "get_type", (PyCFunction) _wrap_g_property_info_get_type, METH_NOARGS },
849 { "get_ownership_transfer", (PyCFunction) _wrap_g_property_info_get_ownership_transfer, METH_NOARGS },
855 PYGLIB_DEFINE_TYPE ("gi.ArgInfo", PyGIArgInfo_Type, PyGIBaseInfo);
858 _wrap_g_arg_info_get_direction (PyGIBaseInfo *self)
860 return PYGLIB_PyLong_FromLong (
861 g_arg_info_get_direction ((GIArgInfo*)self->info) );
865 _wrap_g_arg_info_is_caller_allocates (PyGIBaseInfo *self)
867 return PyBool_FromLong (
868 g_arg_info_is_caller_allocates ((GIArgInfo*)self->info) );
872 _wrap_g_arg_info_is_return_value (PyGIBaseInfo *self)
874 return PyBool_FromLong (
875 g_arg_info_is_return_value ((GIArgInfo*)self->info) );
879 _wrap_g_arg_info_is_optional (PyGIBaseInfo *self)
881 return PyBool_FromLong (
882 g_arg_info_is_optional ((GIArgInfo*)self->info) );
886 _wrap_g_arg_info_may_be_null (PyGIBaseInfo *self)
888 return PyBool_FromLong (
889 g_arg_info_may_be_null ((GIArgInfo*)self->info) );
893 _wrap_g_arg_info_get_ownership_transfer (PyGIBaseInfo *self)
895 return PYGLIB_PyLong_FromLong (
896 g_arg_info_get_ownership_transfer ((GIArgInfo *)self->info) );
900 _wrap_g_arg_info_get_scope (PyGIBaseInfo *self)
902 return PYGLIB_PyLong_FromLong (
903 g_arg_info_get_scope ((GIArgInfo *)self->info) );
907 _wrap_g_arg_info_get_closure (PyGIBaseInfo *self)
909 return PYGLIB_PyLong_FromLong (
910 g_arg_info_get_closure ((GIArgInfo *)self->info) );
914 _wrap_g_arg_info_get_destroy (PyGIBaseInfo *self)
916 return PYGLIB_PyLong_FromLong (
917 g_arg_info_get_destroy ((GIArgInfo *)self->info) );
921 _wrap_g_arg_info_get_type (PyGIBaseInfo *self)
923 return _get_child_info (self, g_arg_info_get_type);
926 static PyMethodDef _PyGIArgInfo_methods[] = {
927 { "get_direction", (PyCFunction) _wrap_g_arg_info_get_direction, METH_NOARGS },
928 { "is_caller_allocates", (PyCFunction) _wrap_g_arg_info_is_caller_allocates, METH_NOARGS },
929 { "is_return_value", (PyCFunction) _wrap_g_arg_info_is_return_value, METH_NOARGS },
930 { "is_optional", (PyCFunction) _wrap_g_arg_info_is_optional, METH_NOARGS },
931 { "may_be_null", (PyCFunction) _wrap_g_arg_info_may_be_null, METH_NOARGS },
932 { "get_ownership_transfer", (PyCFunction) _wrap_g_arg_info_get_ownership_transfer, METH_NOARGS },
933 { "get_scope", (PyCFunction) _wrap_g_arg_info_get_scope, METH_NOARGS },
934 { "get_closure", (PyCFunction) _wrap_g_arg_info_get_closure, METH_NOARGS },
935 { "get_destroy", (PyCFunction) _wrap_g_arg_info_get_destroy, METH_NOARGS },
936 { "get_type", (PyCFunction) _wrap_g_arg_info_get_type, METH_NOARGS },
942 PYGLIB_DEFINE_TYPE ("gi.TypeInfo", PyGITypeInfo_Type, PyGIBaseInfo);
945 _wrap_g_type_info_is_pointer (PyGIBaseInfo *self)
947 return PyBool_FromLong (g_type_info_is_pointer (self->info));
951 _wrap_g_type_info_get_tag (PyGIBaseInfo *self)
953 return PYGLIB_PyLong_FromLong (g_type_info_get_tag (self->info));
957 _wrap_g_type_info_get_tag_as_string (PyGIBaseInfo *self)
959 GITypeTag tag = g_type_info_get_tag (self->info);
960 return PYGLIB_PyUnicode_FromString (g_type_tag_to_string(tag));
964 _wrap_g_type_info_get_param_type (PyGIBaseInfo *self, PyObject *py_n)
970 if (!PYGLIB_PyLong_Check (py_n)) {
971 PyErr_SetString(PyExc_TypeError, "expected integer value");
975 n = PYGLIB_PyLong_AsLong (py_n);
976 info = (GIBaseInfo *) g_type_info_get_param_type ( (GITypeInfo *) self->info, n);
981 py_info = _pygi_info_new (info);
982 g_base_info_unref (info);
987 _wrap_g_type_info_get_interface (PyGIBaseInfo *self)
989 return _get_child_info (self, g_type_info_get_interface);
993 _wrap_g_type_info_get_array_length (PyGIBaseInfo *self)
995 return PYGLIB_PyLong_FromLong (g_type_info_get_array_length (self->info));
999 _wrap_g_type_info_get_array_fixed_size (PyGIBaseInfo *self)
1001 return PYGLIB_PyLong_FromLong (g_type_info_get_array_fixed_size (self->info));
1005 _wrap_g_type_info_is_zero_terminated (PyGIBaseInfo *self)
1007 return PyBool_FromLong (g_type_info_is_zero_terminated (self->info));
1011 _wrap_g_type_info_get_array_type (PyGIBaseInfo *self)
1013 return PYGLIB_PyLong_FromLong (g_type_info_get_array_type (self->info));
1016 static PyMethodDef _PyGITypeInfo_methods[] = {
1017 { "is_pointer", (PyCFunction) _wrap_g_type_info_is_pointer, METH_NOARGS },
1018 { "get_tag", (PyCFunction) _wrap_g_type_info_get_tag, METH_NOARGS },
1019 { "get_tag_as_string", (PyCFunction) _wrap_g_type_info_get_tag_as_string, METH_NOARGS },
1020 { "get_param_type", (PyCFunction) _wrap_g_type_info_get_param_type, METH_O },
1021 { "get_interface", (PyCFunction) _wrap_g_type_info_get_interface, METH_NOARGS },
1022 { "get_array_length", (PyCFunction) _wrap_g_type_info_get_array_length, METH_NOARGS },
1023 { "get_array_fixed_size", (PyCFunction) _wrap_g_type_info_get_array_fixed_size, METH_NOARGS },
1024 { "is_zero_terminated", (PyCFunction) _wrap_g_type_info_is_zero_terminated, METH_NOARGS },
1025 { "get_array_type", (PyCFunction) _wrap_g_type_info_get_array_type, METH_NOARGS },
1031 PYGLIB_DEFINE_TYPE ("gi.FunctionInfo", PyGIFunctionInfo_Type, PyGICallableInfo);
1034 _wrap_g_function_info_is_constructor (PyGIBaseInfo *self)
1036 GIFunctionInfoFlags flags;
1037 gboolean is_constructor;
1039 flags = g_function_info_get_flags ( (GIFunctionInfo*) self->info);
1040 is_constructor = flags & GI_FUNCTION_IS_CONSTRUCTOR;
1042 return PyBool_FromLong (is_constructor);
1046 _wrap_g_function_info_is_method (PyGIBaseInfo *self)
1048 GIFunctionInfoFlags flags;
1051 flags = g_function_info_get_flags ( (GIFunctionInfo*) self->info);
1052 is_method = flags & GI_FUNCTION_IS_METHOD;
1054 return PyBool_FromLong (is_method);
1058 _pygi_g_type_tag_size (GITypeTag type_tag)
1063 case GI_TYPE_TAG_BOOLEAN:
1064 size = sizeof (gboolean);
1066 case GI_TYPE_TAG_INT8:
1067 case GI_TYPE_TAG_UINT8:
1068 size = sizeof (gint8);
1070 case GI_TYPE_TAG_INT16:
1071 case GI_TYPE_TAG_UINT16:
1072 size = sizeof (gint16);
1074 case GI_TYPE_TAG_INT32:
1075 case GI_TYPE_TAG_UINT32:
1076 size = sizeof (gint32);
1078 case GI_TYPE_TAG_INT64:
1079 case GI_TYPE_TAG_UINT64:
1080 size = sizeof (gint64);
1082 case GI_TYPE_TAG_FLOAT:
1083 size = sizeof (gfloat);
1085 case GI_TYPE_TAG_DOUBLE:
1086 size = sizeof (gdouble);
1088 case GI_TYPE_TAG_GTYPE:
1089 size = sizeof (GType);
1091 case GI_TYPE_TAG_UNICHAR:
1092 size = sizeof (gunichar);
1094 case GI_TYPE_TAG_VOID:
1095 case GI_TYPE_TAG_UTF8:
1096 case GI_TYPE_TAG_FILENAME:
1097 case GI_TYPE_TAG_ARRAY:
1098 case GI_TYPE_TAG_INTERFACE:
1099 case GI_TYPE_TAG_GLIST:
1100 case GI_TYPE_TAG_GSLIST:
1101 case GI_TYPE_TAG_GHASH:
1102 case GI_TYPE_TAG_ERROR:
1103 PyErr_Format (PyExc_TypeError,
1104 "Unable to know the size (assuming %s is not a pointer)",
1105 g_type_tag_to_string (type_tag));
1113 _pygi_g_type_info_size (GITypeInfo *type_info)
1119 type_tag = g_type_info_get_tag (type_info);
1121 case GI_TYPE_TAG_BOOLEAN:
1122 case GI_TYPE_TAG_INT8:
1123 case GI_TYPE_TAG_UINT8:
1124 case GI_TYPE_TAG_INT16:
1125 case GI_TYPE_TAG_UINT16:
1126 case GI_TYPE_TAG_INT32:
1127 case GI_TYPE_TAG_UINT32:
1128 case GI_TYPE_TAG_INT64:
1129 case GI_TYPE_TAG_UINT64:
1130 case GI_TYPE_TAG_FLOAT:
1131 case GI_TYPE_TAG_DOUBLE:
1132 case GI_TYPE_TAG_GTYPE:
1133 case GI_TYPE_TAG_UNICHAR:
1134 size = _pygi_g_type_tag_size (type_tag);
1135 g_assert (size > 0);
1137 case GI_TYPE_TAG_INTERFACE:
1140 GIInfoType info_type;
1142 info = g_type_info_get_interface (type_info);
1143 info_type = g_base_info_get_type (info);
1145 switch (info_type) {
1146 case GI_INFO_TYPE_STRUCT:
1147 if (g_type_info_is_pointer (type_info)) {
1148 size = sizeof (gpointer);
1150 size = g_struct_info_get_size ( (GIStructInfo *) info);
1153 case GI_INFO_TYPE_UNION:
1154 if (g_type_info_is_pointer (type_info)) {
1155 size = sizeof (gpointer);
1157 size = g_union_info_get_size ( (GIUnionInfo *) info);
1160 case GI_INFO_TYPE_ENUM:
1161 case GI_INFO_TYPE_FLAGS:
1162 if (g_type_info_is_pointer (type_info)) {
1163 size = sizeof (gpointer);
1167 type_tag = g_enum_info_get_storage_type ( (GIEnumInfo *) info);
1168 size = _pygi_g_type_tag_size (type_tag);
1171 case GI_INFO_TYPE_BOXED:
1172 case GI_INFO_TYPE_OBJECT:
1173 case GI_INFO_TYPE_INTERFACE:
1174 case GI_INFO_TYPE_CALLBACK:
1175 size = sizeof (gpointer);
1177 case GI_INFO_TYPE_VFUNC:
1178 case GI_INFO_TYPE_INVALID:
1179 case GI_INFO_TYPE_FUNCTION:
1180 case GI_INFO_TYPE_CONSTANT:
1181 case GI_INFO_TYPE_VALUE:
1182 case GI_INFO_TYPE_SIGNAL:
1183 case GI_INFO_TYPE_PROPERTY:
1184 case GI_INFO_TYPE_FIELD:
1185 case GI_INFO_TYPE_ARG:
1186 case GI_INFO_TYPE_TYPE:
1187 case GI_INFO_TYPE_UNRESOLVED:
1189 g_assert_not_reached();
1193 g_base_info_unref (info);
1196 case GI_TYPE_TAG_ARRAY:
1197 case GI_TYPE_TAG_VOID:
1198 case GI_TYPE_TAG_UTF8:
1199 case GI_TYPE_TAG_FILENAME:
1200 case GI_TYPE_TAG_GLIST:
1201 case GI_TYPE_TAG_GSLIST:
1202 case GI_TYPE_TAG_GHASH:
1203 case GI_TYPE_TAG_ERROR:
1204 size = sizeof (gpointer);
1212 _wrap_g_function_info_get_symbol (PyGIBaseInfo *self)
1214 return _get_info_string (self, g_function_info_get_symbol);
1218 _wrap_g_function_info_get_flags (PyGIBaseInfo *self)
1220 return PYGLIB_PyLong_FromLong (g_function_info_get_flags (self->info));
1224 _wrap_g_function_info_get_property (PyGIBaseInfo *self)
1226 return _get_child_info (self, g_function_info_get_property);
1230 _wrap_g_function_info_get_vfunc (PyGIBaseInfo *self)
1232 return _get_child_info (self, g_function_info_get_vfunc);
1235 static PyMethodDef _PyGIFunctionInfo_methods[] = {
1236 { "is_constructor", (PyCFunction) _wrap_g_function_info_is_constructor, METH_NOARGS },
1237 { "is_method", (PyCFunction) _wrap_g_function_info_is_method, METH_NOARGS },
1238 { "get_symbol", (PyCFunction) _wrap_g_function_info_get_symbol, METH_NOARGS },
1239 { "get_flags", (PyCFunction) _wrap_g_function_info_get_flags, METH_NOARGS },
1240 { "get_property", (PyCFunction) _wrap_g_function_info_get_property, METH_NOARGS },
1241 { "get_vfunc", (PyCFunction) _wrap_g_function_info_get_vfunc, METH_NOARGS },
1245 /* RegisteredTypeInfo */
1246 PYGLIB_DEFINE_TYPE ("gi.RegisteredTypeInfo", PyGIRegisteredTypeInfo_Type, PyGIBaseInfo);
1249 _wrap_g_registered_type_info_get_type_name (PyGIBaseInfo *self)
1251 return _get_info_string (self, g_registered_type_info_get_type_name);
1255 _wrap_g_registered_type_info_get_type_init (PyGIBaseInfo *self)
1257 return _get_info_string (self, g_registered_type_info_get_type_init);
1261 _wrap_g_registered_type_info_get_g_type (PyGIBaseInfo *self)
1265 type = g_registered_type_info_get_g_type ( (GIRegisteredTypeInfo *) self->info);
1267 return pyg_type_wrapper_new (type);
1270 static PyMethodDef _PyGIRegisteredTypeInfo_methods[] = {
1271 { "get_type_name", (PyCFunction) _wrap_g_registered_type_info_get_type_name, METH_NOARGS },
1272 { "get_type_init", (PyCFunction) _wrap_g_registered_type_info_get_type_init, METH_NOARGS },
1273 { "get_g_type", (PyCFunction) _wrap_g_registered_type_info_get_g_type, METH_NOARGS },
1279 PYGLIB_DEFINE_TYPE ("StructInfo", PyGIStructInfo_Type, PyGIBaseInfo);
1282 _wrap_g_struct_info_get_fields (PyGIBaseInfo *self)
1284 return _make_infos_tuple (self, g_struct_info_get_n_fields, g_struct_info_get_field);
1288 _wrap_g_struct_info_get_methods (PyGIBaseInfo *self)
1290 return _make_infos_tuple (self, g_struct_info_get_n_methods, g_struct_info_get_method);
1294 _wrap_g_struct_info_get_size (PyGIBaseInfo *self)
1296 return PYGLIB_PyLong_FromSize_t (g_struct_info_get_size (self->info));
1300 _wrap_g_struct_info_get_alignment (PyGIBaseInfo *self)
1302 return PYGLIB_PyLong_FromSize_t (g_struct_info_get_alignment (self->info));
1306 _wrap_g_struct_info_is_gtype_struct (PyGIBaseInfo *self)
1308 return PyBool_FromLong (g_struct_info_is_gtype_struct (self->info));
1312 _wrap_g_struct_info_is_foreign (PyGIBaseInfo *self)
1314 return PyBool_FromLong (g_struct_info_is_foreign (self->info));
1317 static PyMethodDef _PyGIStructInfo_methods[] = {
1318 { "get_fields", (PyCFunction) _wrap_g_struct_info_get_fields, METH_NOARGS },
1319 { "get_methods", (PyCFunction) _wrap_g_struct_info_get_methods, METH_NOARGS },
1320 { "get_size", (PyCFunction) _wrap_g_struct_info_get_size, METH_NOARGS },
1321 { "get_alignment", (PyCFunction) _wrap_g_struct_info_get_alignment, METH_NOARGS },
1322 { "is_gtype_struct", (PyCFunction) _wrap_g_struct_info_is_gtype_struct, METH_NOARGS },
1323 { "is_foreign", (PyCFunction) _wrap_g_struct_info_is_foreign, METH_NOARGS },
1328 pygi_g_struct_info_is_simple (GIStructInfo *struct_info)
1331 gsize n_field_infos;
1336 n_field_infos = g_struct_info_get_n_fields (struct_info);
1338 for (i = 0; i < n_field_infos && is_simple; i++) {
1339 GIFieldInfo *field_info;
1340 GITypeInfo *field_type_info;
1341 GITypeTag field_type_tag;
1343 field_info = g_struct_info_get_field (struct_info, i);
1344 field_type_info = g_field_info_get_type (field_info);
1347 field_type_tag = g_type_info_get_tag (field_type_info);
1349 switch (field_type_tag) {
1350 case GI_TYPE_TAG_BOOLEAN:
1351 case GI_TYPE_TAG_INT8:
1352 case GI_TYPE_TAG_UINT8:
1353 case GI_TYPE_TAG_INT16:
1354 case GI_TYPE_TAG_UINT16:
1355 case GI_TYPE_TAG_INT32:
1356 case GI_TYPE_TAG_UINT32:
1357 case GI_TYPE_TAG_INT64:
1358 case GI_TYPE_TAG_UINT64:
1359 case GI_TYPE_TAG_FLOAT:
1360 case GI_TYPE_TAG_DOUBLE:
1361 case GI_TYPE_TAG_UNICHAR:
1362 if (g_type_info_is_pointer (field_type_info)) {
1366 case GI_TYPE_TAG_VOID:
1367 case GI_TYPE_TAG_GTYPE:
1368 case GI_TYPE_TAG_ERROR:
1369 case GI_TYPE_TAG_UTF8:
1370 case GI_TYPE_TAG_FILENAME:
1371 case GI_TYPE_TAG_ARRAY:
1372 case GI_TYPE_TAG_GLIST:
1373 case GI_TYPE_TAG_GSLIST:
1374 case GI_TYPE_TAG_GHASH:
1377 case GI_TYPE_TAG_INTERFACE:
1380 GIInfoType info_type;
1382 info = g_type_info_get_interface (field_type_info);
1383 info_type = g_base_info_get_type (info);
1385 switch (info_type) {
1386 case GI_INFO_TYPE_STRUCT:
1387 if (g_type_info_is_pointer (field_type_info)) {
1390 is_simple = pygi_g_struct_info_is_simple ( (GIStructInfo *) info);
1393 case GI_INFO_TYPE_UNION:
1397 case GI_INFO_TYPE_ENUM:
1398 case GI_INFO_TYPE_FLAGS:
1399 if (g_type_info_is_pointer (field_type_info)) {
1403 case GI_INFO_TYPE_BOXED:
1404 case GI_INFO_TYPE_OBJECT:
1405 case GI_INFO_TYPE_CALLBACK:
1406 case GI_INFO_TYPE_INTERFACE:
1409 case GI_INFO_TYPE_VFUNC:
1410 case GI_INFO_TYPE_INVALID:
1411 case GI_INFO_TYPE_FUNCTION:
1412 case GI_INFO_TYPE_CONSTANT:
1413 case GI_INFO_TYPE_VALUE:
1414 case GI_INFO_TYPE_SIGNAL:
1415 case GI_INFO_TYPE_PROPERTY:
1416 case GI_INFO_TYPE_FIELD:
1417 case GI_INFO_TYPE_ARG:
1418 case GI_INFO_TYPE_TYPE:
1419 case GI_INFO_TYPE_UNRESOLVED:
1421 g_assert_not_reached();
1425 g_base_info_unref (info);
1430 g_base_info_unref ( (GIBaseInfo *) field_type_info);
1431 g_base_info_unref ( (GIBaseInfo *) field_info);
1439 PYGLIB_DEFINE_TYPE ("gi.EnumInfo", PyGIEnumInfo_Type, PyGIBaseInfo);
1442 _wrap_g_enum_info_get_values (PyGIBaseInfo *self)
1444 return _make_infos_tuple (self, g_enum_info_get_n_values, g_enum_info_get_value);
1448 _wrap_g_enum_info_is_flags (PyGIBaseInfo *self)
1450 GIInfoType info_type = g_base_info_get_type ((GIBaseInfo *) self->info);
1452 if (info_type == GI_INFO_TYPE_ENUM) {
1454 } else if (info_type == GI_INFO_TYPE_FLAGS) {
1457 g_assert_not_reached();
1462 _wrap_g_enum_info_get_methods (PyGIBaseInfo *self)
1464 return _make_infos_tuple (self, g_enum_info_get_n_methods, g_enum_info_get_method);
1468 _wrap_g_enum_info_get_storage_type (PyGIBaseInfo *self)
1470 return PYGLIB_PyLong_FromLong (g_enum_info_get_storage_type ((GIBaseInfo *) self->info));
1473 static PyMethodDef _PyGIEnumInfo_methods[] = {
1474 { "get_values", (PyCFunction) _wrap_g_enum_info_get_values, METH_NOARGS },
1475 { "is_flags", (PyCFunction) _wrap_g_enum_info_is_flags, METH_NOARGS },
1476 { "get_methods", (PyCFunction) _wrap_g_enum_info_get_methods, METH_NOARGS },
1477 { "get_storage_type", (PyCFunction) _wrap_g_enum_info_get_storage_type, METH_NOARGS },
1483 PYGLIB_DEFINE_TYPE ("ObjectInfo", PyGIObjectInfo_Type, PyGIBaseInfo);
1486 _wrap_g_object_info_get_parent (PyGIBaseInfo *self)
1488 return _get_child_info (self, g_object_info_get_parent);
1492 _wrap_g_object_info_get_methods (PyGIBaseInfo *self)
1494 return _make_infos_tuple (self, g_object_info_get_n_methods, g_object_info_get_method);
1498 _wrap_g_object_info_find_method (PyGIBaseInfo *self, PyObject *py_name)
1500 return _get_child_info_by_name (self, py_name, g_object_info_find_method);
1504 _wrap_g_object_info_get_fields (PyGIBaseInfo *self)
1506 return _make_infos_tuple (self, g_object_info_get_n_fields, g_object_info_get_field);
1510 _wrap_g_object_info_get_properties (PyGIBaseInfo *self)
1512 return _make_infos_tuple (self, g_object_info_get_n_properties, g_object_info_get_property);
1516 _wrap_g_object_info_get_signals (PyGIBaseInfo *self)
1518 return _make_infos_tuple (self, g_object_info_get_n_signals, g_object_info_get_signal);
1522 _wrap_g_object_info_get_interfaces (PyGIBaseInfo *self)
1524 return _make_infos_tuple (self, g_object_info_get_n_interfaces, g_object_info_get_interface);
1528 _wrap_g_object_info_get_constants (PyGIBaseInfo *self)
1530 return _make_infos_tuple (self, g_object_info_get_n_constants, g_object_info_get_constant);
1534 _wrap_g_object_info_get_vfuncs (PyGIBaseInfo *self)
1536 return _make_infos_tuple (self, g_object_info_get_n_vfuncs, g_object_info_get_vfunc);
1540 _wrap_g_object_info_get_abstract (PyGIBaseInfo *self)
1542 gboolean is_abstract = g_object_info_get_abstract ( (GIObjectInfo*) self->info);
1543 return PyBool_FromLong (is_abstract);
1547 _wrap_g_object_info_get_type_name (PyGIBaseInfo *self)
1549 return _get_info_string (self, g_object_info_get_type_name);
1553 _wrap_g_object_info_get_type_init (PyGIBaseInfo *self)
1555 return _get_info_string (self, g_object_info_get_type_init);
1559 _wrap_g_object_info_get_fundamental (PyGIBaseInfo *self)
1561 return PyBool_FromLong (g_object_info_get_fundamental ( (GIObjectInfo*) self->info));
1565 _wrap_g_object_info_get_class_struct (PyGIBaseInfo *self)
1567 return _get_child_info (self, g_object_info_get_class_struct);
1571 _wrap_g_object_info_find_vfunc (PyGIBaseInfo *self, PyObject *py_name)
1573 return _get_child_info_by_name (self, py_name, g_object_info_find_vfunc);
1577 _wrap_g_object_info_get_unref_function (PyGIBaseInfo *self)
1579 return _get_info_string (self, g_object_info_get_unref_function);
1583 _wrap_g_object_info_get_ref_function (PyGIBaseInfo *self)
1585 return _get_info_string (self, g_object_info_get_ref_function);
1589 _wrap_g_object_info_get_set_value_function (PyGIBaseInfo *self)
1591 return _get_info_string (self, g_object_info_get_set_value_function);
1595 _wrap_g_object_info_get_get_value_function (PyGIBaseInfo *self)
1597 return _get_info_string (self, g_object_info_get_get_value_function);
1600 static PyMethodDef _PyGIObjectInfo_methods[] = {
1601 { "get_parent", (PyCFunction) _wrap_g_object_info_get_parent, METH_NOARGS },
1602 { "get_methods", (PyCFunction) _wrap_g_object_info_get_methods, METH_NOARGS },
1603 { "find_method", (PyCFunction) _wrap_g_object_info_find_method, METH_O },
1604 { "get_fields", (PyCFunction) _wrap_g_object_info_get_fields, METH_NOARGS },
1605 { "get_properties", (PyCFunction) _wrap_g_object_info_get_properties, METH_NOARGS },
1606 { "get_signals", (PyCFunction) _wrap_g_object_info_get_signals, METH_NOARGS },
1607 { "get_interfaces", (PyCFunction) _wrap_g_object_info_get_interfaces, METH_NOARGS },
1608 { "get_constants", (PyCFunction) _wrap_g_object_info_get_constants, METH_NOARGS },
1609 { "get_vfuncs", (PyCFunction) _wrap_g_object_info_get_vfuncs, METH_NOARGS },
1610 { "find_vfunc", (PyCFunction) _wrap_g_object_info_find_vfunc, METH_O },
1611 { "get_abstract", (PyCFunction) _wrap_g_object_info_get_abstract, METH_NOARGS },
1612 { "get_type_name", (PyCFunction) _wrap_g_object_info_get_type_name, METH_NOARGS },
1613 { "get_type_init", (PyCFunction) _wrap_g_object_info_get_type_init, METH_NOARGS },
1614 { "get_fundamental", (PyCFunction) _wrap_g_object_info_get_fundamental, METH_NOARGS },
1615 { "get_class_struct", (PyCFunction) _wrap_g_object_info_get_class_struct, METH_NOARGS },
1616 { "get_unref_function", (PyCFunction) _wrap_g_object_info_get_unref_function, METH_NOARGS },
1617 { "get_ref_function", (PyCFunction) _wrap_g_object_info_get_ref_function, METH_NOARGS },
1618 { "get_set_value_function", (PyCFunction) _wrap_g_object_info_get_set_value_function, METH_NOARGS },
1619 { "get_get_value_function", (PyCFunction) _wrap_g_object_info_get_get_value_function, METH_NOARGS },
1624 /* GIInterfaceInfo */
1625 PYGLIB_DEFINE_TYPE ("InterfaceInfo", PyGIInterfaceInfo_Type, PyGIBaseInfo);
1628 _wrap_g_interface_info_get_methods (PyGIBaseInfo *self)
1630 return _make_infos_tuple (self, g_interface_info_get_n_methods, g_interface_info_get_method);
1634 _wrap_g_interface_info_find_method (PyGIBaseInfo *self, PyObject *py_name)
1636 return _get_child_info_by_name (self, py_name, g_interface_info_find_method);
1640 _wrap_g_interface_info_get_constants (PyGIBaseInfo *self)
1642 return _make_infos_tuple (self, g_interface_info_get_n_constants, g_interface_info_get_constant);
1646 _wrap_g_interface_info_get_vfuncs (PyGIBaseInfo *self)
1648 return _make_infos_tuple (self, g_interface_info_get_n_vfuncs, g_interface_info_get_vfunc);
1652 _wrap_g_interface_info_find_vfunc (PyGIBaseInfo *self, PyObject *py_name)
1654 return _get_child_info_by_name (self, py_name, g_interface_info_find_vfunc);
1658 _wrap_g_interface_info_get_prerequisites (PyGIBaseInfo *self)
1660 return _make_infos_tuple (self, g_interface_info_get_n_prerequisites, g_interface_info_get_prerequisite);
1664 _wrap_g_interface_info_get_properties (PyGIBaseInfo *self)
1666 return _make_infos_tuple (self, g_interface_info_get_n_properties, g_interface_info_get_property);
1670 _wrap_g_interface_info_get_iface_struct (PyGIBaseInfo *self)
1672 return _get_child_info (self, g_interface_info_get_iface_struct);
1676 _wrap_g_interface_info_get_signals (PyGIBaseInfo *self)
1678 return _make_infos_tuple (self, g_interface_info_get_n_signals, g_interface_info_get_signal);
1682 _wrap_g_interface_info_find_signal (PyGIBaseInfo *self, PyObject *py_name)
1684 return _get_child_info_by_name (self, py_name, g_interface_info_find_signal);
1687 static PyMethodDef _PyGIInterfaceInfo_methods[] = {
1688 { "get_prerequisites", (PyCFunction) _wrap_g_interface_info_get_prerequisites, METH_NOARGS },
1689 { "get_properties", (PyCFunction) _wrap_g_interface_info_get_properties, METH_NOARGS },
1690 { "get_methods", (PyCFunction) _wrap_g_interface_info_get_methods, METH_NOARGS },
1691 { "find_method", (PyCFunction) _wrap_g_interface_info_find_method, METH_O },
1692 { "get_signals", (PyCFunction) _wrap_g_interface_info_get_signals, METH_NOARGS },
1693 { "find_signal", (PyCFunction) _wrap_g_interface_info_find_signal, METH_O },
1694 { "get_vfuncs", (PyCFunction) _wrap_g_interface_info_get_vfuncs, METH_NOARGS },
1695 { "get_constants", (PyCFunction) _wrap_g_interface_info_get_constants, METH_NOARGS },
1696 { "get_iface_struct", (PyCFunction) _wrap_g_interface_info_get_iface_struct, METH_NOARGS },
1697 { "find_vfunc", (PyCFunction) _wrap_g_interface_info_find_vfunc, METH_O },
1701 /* GIConstantInfo */
1702 PYGLIB_DEFINE_TYPE ("gi.ConstantInfo", PyGIConstantInfo_Type, PyGIBaseInfo);
1705 _wrap_g_constant_info_get_value (PyGIBaseInfo *self)
1707 GITypeInfo *type_info;
1710 gboolean free_array = FALSE;
1712 if (g_constant_info_get_value ( (GIConstantInfo *) self->info, &value) < 0) {
1713 PyErr_SetString (PyExc_RuntimeError, "unable to get value");
1717 type_info = g_constant_info_get_type ( (GIConstantInfo *) self->info);
1719 if (g_type_info_get_tag (type_info) == GI_TYPE_TAG_ARRAY) {
1720 value.v_pointer = _pygi_argument_to_array (&value, NULL, NULL, NULL,
1721 type_info, &free_array);
1724 py_value = _pygi_argument_to_object (&value, type_info, GI_TRANSFER_NOTHING);
1727 g_array_free (value.v_pointer, FALSE);
1730 g_constant_info_free_value (self->info, &value);
1731 g_base_info_unref ( (GIBaseInfo *) type_info);
1736 static PyMethodDef _PyGIConstantInfo_methods[] = {
1737 { "get_value", (PyCFunction) _wrap_g_constant_info_get_value, METH_NOARGS },
1742 PYGLIB_DEFINE_TYPE ("gi.ValueInfo", PyGIValueInfo_Type, PyGIBaseInfo);
1745 _wrap_g_value_info_get_value (PyGIBaseInfo *self)
1749 value = g_value_info_get_value ( (GIValueInfo *) self->info);
1751 return PYGLIB_PyLong_FromLong (value);
1755 static PyMethodDef _PyGIValueInfo_methods[] = {
1756 { "get_value", (PyCFunction) _wrap_g_value_info_get_value, METH_NOARGS },
1762 PYGLIB_DEFINE_TYPE ("gi.FieldInfo", PyGIFieldInfo_Type, PyGIBaseInfo);
1765 _struct_field_array_length_marshal (gsize length_index,
1766 void *container_ptr,
1767 void *struct_data_ptr)
1769 gssize array_len = -1;
1770 GIFieldInfo *array_len_field = NULL;
1771 GIArgument arg = {0};
1772 GIBaseInfo *container_info = (GIBaseInfo *)container_ptr;
1774 switch (g_base_info_get_type (container_info)) {
1775 case GI_INFO_TYPE_UNION:
1776 array_len_field = g_union_info_get_field ((GIUnionInfo *)container_info, length_index);
1778 case GI_INFO_TYPE_STRUCT:
1779 array_len_field = g_struct_info_get_field ((GIStructInfo *)container_info, length_index);
1781 case GI_INFO_TYPE_OBJECT:
1782 array_len_field = g_object_info_get_field ((GIObjectInfo *)container_info, length_index);
1785 /* Other types don't have fields. */
1786 g_assert_not_reached();
1789 if (array_len_field == NULL) {
1793 if (g_field_info_get_field (array_len_field, struct_data_ptr, &arg)) {
1794 GITypeInfo *array_len_type_info;
1796 array_len_type_info = g_field_info_get_type (array_len_field);
1797 if (array_len_type_info == NULL) {
1801 if (!pygi_argument_to_gssize (&arg,
1802 g_type_info_get_tag (array_len_type_info),
1807 g_base_info_unref (array_len_type_info);
1811 g_base_info_unref (array_len_field);
1816 _pygi_g_registered_type_info_check_object (GIRegisteredTypeInfo *info,
1817 gboolean is_instance,
1824 gchar *type_name_expected = NULL;
1825 GIInfoType interface_type;
1827 interface_type = g_base_info_get_type (info);
1828 if ( (interface_type == GI_INFO_TYPE_STRUCT) &&
1829 (g_struct_info_is_foreign ( (GIStructInfo*) info))) {
1830 /* TODO: Could we check is the correct foreign type? */
1834 g_type = g_registered_type_info_get_g_type (info);
1835 if (g_type != G_TYPE_NONE) {
1836 py_type = _pygi_type_get_from_g_type (g_type);
1838 py_type = _pygi_type_import_by_gi_info ( (GIBaseInfo *) info);
1841 if (py_type == NULL) {
1845 g_assert (PyType_Check (py_type));
1848 retval = PyObject_IsInstance (object, py_type);
1850 type_name_expected = _pygi_g_base_info_get_fullname (
1851 (GIBaseInfo *) info);
1854 if (!PyObject_Type (py_type)) {
1855 type_name_expected = "type";
1857 } else if (!PyType_IsSubtype ( (PyTypeObject *) object,
1858 (PyTypeObject *) py_type)) {
1859 type_name_expected = _pygi_g_base_info_get_fullname (
1860 (GIBaseInfo *) info);
1867 Py_DECREF (py_type);
1870 PyTypeObject *object_type;
1872 if (type_name_expected == NULL) {
1876 object_type = (PyTypeObject *) PyObject_Type (object);
1877 if (object_type == NULL) {
1881 PyErr_Format (PyExc_TypeError, "Must be %s, not %s",
1882 type_name_expected, object_type->tp_name);
1884 g_free (type_name_expected);
1891 _wrap_g_field_info_get_value (PyGIBaseInfo *self,
1895 GIBaseInfo *container_info;
1896 GIInfoType container_info_type;
1898 GITypeInfo *field_type_info;
1900 PyObject *py_value = NULL;
1901 gboolean free_array = FALSE;
1903 memset(&value, 0, sizeof(GIArgument));
1905 if (!PyArg_ParseTuple (args, "O:FieldInfo.get_value", &instance)) {
1909 container_info = g_base_info_get_container (self->info);
1910 g_assert (container_info != NULL);
1912 /* Check the instance. */
1913 if (!_pygi_g_registered_type_info_check_object ( (GIRegisteredTypeInfo *) container_info, TRUE, instance)) {
1914 _PyGI_ERROR_PREFIX ("argument 1: ");
1918 /* Get the pointer to the container. */
1919 container_info_type = g_base_info_get_type (container_info);
1920 switch (container_info_type) {
1921 case GI_INFO_TYPE_UNION:
1922 case GI_INFO_TYPE_STRUCT:
1923 pointer = pyg_boxed_get (instance, void);
1925 case GI_INFO_TYPE_OBJECT:
1926 pointer = pygobject_get (instance);
1929 /* Other types don't have fields. */
1930 g_assert_not_reached();
1933 /* Get the field's value. */
1934 field_type_info = g_field_info_get_type ( (GIFieldInfo *) self->info);
1936 /* A few types are not handled by g_field_info_get_field, so do it here. */
1937 if (!g_type_info_is_pointer (field_type_info)
1938 && g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_INTERFACE) {
1940 GIInfoType info_type;
1942 if (! (g_field_info_get_flags ( (GIFieldInfo *) self->info) & GI_FIELD_IS_READABLE)) {
1943 PyErr_SetString (PyExc_RuntimeError, "field is not readable");
1947 info = g_type_info_get_interface (field_type_info);
1949 info_type = g_base_info_get_type (info);
1951 g_base_info_unref (info);
1953 switch (info_type) {
1954 case GI_INFO_TYPE_UNION:
1955 PyErr_SetString (PyExc_NotImplementedError, "getting an union is not supported yet");
1957 case GI_INFO_TYPE_STRUCT:
1961 offset = g_field_info_get_offset ( (GIFieldInfo *) self->info);
1963 value.v_pointer = (char*) pointer + offset;
1965 goto argument_to_object;
1973 if (!g_field_info_get_field ( (GIFieldInfo *) self->info, pointer, &value)) {
1974 PyErr_SetString (PyExc_RuntimeError, "unable to get the value");
1978 if (g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_ARRAY) {
1979 value.v_pointer = _pygi_argument_to_array (&value,
1980 _struct_field_array_length_marshal,
1988 py_value = _pygi_argument_to_object (&value, field_type_info, GI_TRANSFER_NOTHING);
1991 g_array_free (value.v_pointer, FALSE);
1995 g_base_info_unref ( (GIBaseInfo *) field_type_info);
2001 _wrap_g_field_info_set_value (PyGIBaseInfo *self,
2006 GIBaseInfo *container_info;
2007 GIInfoType container_info_type;
2009 GITypeInfo *field_type_info;
2011 PyObject *retval = NULL;
2013 if (!PyArg_ParseTuple (args, "OO:FieldInfo.set_value", &instance, &py_value)) {
2017 container_info = g_base_info_get_container (self->info);
2018 g_assert (container_info != NULL);
2020 /* Check the instance. */
2021 if (!_pygi_g_registered_type_info_check_object ( (GIRegisteredTypeInfo *) container_info, TRUE, instance)) {
2022 _PyGI_ERROR_PREFIX ("argument 1: ");
2026 /* Get the pointer to the container. */
2027 container_info_type = g_base_info_get_type (container_info);
2028 switch (container_info_type) {
2029 case GI_INFO_TYPE_UNION:
2030 case GI_INFO_TYPE_STRUCT:
2031 pointer = pyg_boxed_get (instance, void);
2033 case GI_INFO_TYPE_OBJECT:
2034 pointer = pygobject_get (instance);
2037 /* Other types don't have fields. */
2038 g_assert_not_reached();
2041 field_type_info = g_field_info_get_type ( (GIFieldInfo *) self->info);
2043 /* Set the field's value. */
2044 /* A few types are not handled by g_field_info_set_field, so do it here. */
2045 if (!g_type_info_is_pointer (field_type_info)
2046 && g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_INTERFACE) {
2048 GIInfoType info_type;
2050 if (! (g_field_info_get_flags ( (GIFieldInfo *) self->info) & GI_FIELD_IS_WRITABLE)) {
2051 PyErr_SetString (PyExc_RuntimeError, "field is not writable");
2055 info = g_type_info_get_interface (field_type_info);
2057 info_type = g_base_info_get_type (info);
2059 switch (info_type) {
2060 case GI_INFO_TYPE_UNION:
2061 PyErr_SetString (PyExc_NotImplementedError, "setting an union is not supported yet");
2063 case GI_INFO_TYPE_STRUCT:
2069 is_simple = pygi_g_struct_info_is_simple ( (GIStructInfo *) info);
2072 PyErr_SetString (PyExc_TypeError,
2073 "cannot set a structure which has no well-defined ownership transfer rules");
2074 g_base_info_unref (info);
2078 value = _pygi_argument_from_object (py_value, field_type_info, GI_TRANSFER_NOTHING);
2079 if (PyErr_Occurred()) {
2080 g_base_info_unref (info);
2084 offset = g_field_info_get_offset ( (GIFieldInfo *) self->info);
2085 size = g_struct_info_get_size ( (GIStructInfo *) info);
2086 g_assert (size > 0);
2088 g_memmove ((char*) pointer + offset, value.v_pointer, size);
2090 g_base_info_unref (info);
2100 g_base_info_unref (info);
2101 } else if (g_type_info_is_pointer (field_type_info)
2102 && (g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_VOID
2103 || g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_UTF8)) {
2105 value = _pygi_argument_from_object (py_value, field_type_info, GI_TRANSFER_NOTHING);
2106 if (PyErr_Occurred()) {
2110 offset = g_field_info_get_offset ((GIFieldInfo *) self->info);
2111 G_STRUCT_MEMBER (gpointer, pointer, offset) = (gpointer)value.v_pointer;
2117 value = _pygi_argument_from_object (py_value, field_type_info, GI_TRANSFER_EVERYTHING);
2118 if (PyErr_Occurred()) {
2122 if (!g_field_info_set_field ( (GIFieldInfo *) self->info, pointer, &value)) {
2123 _pygi_argument_release (&value, field_type_info, GI_TRANSFER_NOTHING, GI_DIRECTION_IN);
2124 PyErr_SetString (PyExc_RuntimeError, "unable to set value for field");
2131 g_base_info_unref ( (GIBaseInfo *) field_type_info);
2133 Py_XINCREF (retval);
2138 _wrap_g_field_info_get_flags (PyGIBaseInfo *self)
2140 return PYGLIB_PyLong_FromLong (g_field_info_get_flags (self->info));
2144 _wrap_g_field_info_get_size (PyGIBaseInfo *self)
2146 return PYGLIB_PyLong_FromLong (g_field_info_get_size (self->info));
2150 _wrap_g_field_info_get_offset (PyGIBaseInfo *self)
2152 return PYGLIB_PyLong_FromLong (g_field_info_get_offset (self->info));
2156 _wrap_g_field_info_get_type (PyGIBaseInfo *self)
2158 return _get_child_info (self, g_field_info_get_type);
2161 static PyMethodDef _PyGIFieldInfo_methods[] = {
2162 { "get_value", (PyCFunction) _wrap_g_field_info_get_value, METH_VARARGS },
2163 { "set_value", (PyCFunction) _wrap_g_field_info_set_value, METH_VARARGS },
2164 { "get_flags", (PyCFunction) _wrap_g_field_info_get_flags, METH_VARARGS },
2165 { "get_size", (PyCFunction) _wrap_g_field_info_get_size, METH_VARARGS },
2166 { "get_offset", (PyCFunction) _wrap_g_field_info_get_offset, METH_VARARGS },
2167 { "get_type", (PyCFunction) _wrap_g_field_info_get_type, METH_VARARGS },
2172 /* GIUnresolvedInfo */
2173 PYGLIB_DEFINE_TYPE ("gi.UnresolvedInfo", PyGIUnresolvedInfo_Type, PyGIBaseInfo);
2175 static PyMethodDef _PyGIUnresolvedInfo_methods[] = {
2180 PYGLIB_DEFINE_TYPE ("gi.VFuncInfo", PyGIVFuncInfo_Type, PyGICallableInfo);
2183 _wrap_g_vfunc_info_get_flags (PyGIBaseInfo *self)
2185 return PYGLIB_PyLong_FromLong (g_vfunc_info_get_flags ((GIVFuncInfo *) self->info));
2189 _wrap_g_vfunc_info_get_offset (PyGIBaseInfo *self)
2191 return PYGLIB_PyLong_FromLong (g_vfunc_info_get_offset ((GIVFuncInfo *) self->info));
2195 _wrap_g_vfunc_info_get_signal (PyGIBaseInfo *self)
2197 return _get_child_info (self, g_vfunc_info_get_signal);
2201 _wrap_g_vfunc_info_get_invoker (PyGIBaseInfo *self)
2203 return _get_child_info (self, g_vfunc_info_get_invoker);
2206 static PyMethodDef _PyGIVFuncInfo_methods[] = {
2207 { "get_flags", (PyCFunction) _wrap_g_vfunc_info_get_flags, METH_NOARGS },
2208 { "get_offset", (PyCFunction) _wrap_g_vfunc_info_get_offset, METH_NOARGS },
2209 { "get_signal", (PyCFunction) _wrap_g_vfunc_info_get_signal, METH_NOARGS },
2210 { "get_invoker", (PyCFunction) _wrap_g_vfunc_info_get_invoker, METH_NOARGS },
2216 PYGLIB_DEFINE_TYPE ("gi.UnionInfo", PyGIUnionInfo_Type, PyGIBaseInfo);
2219 _wrap_g_union_info_get_fields (PyGIBaseInfo *self)
2221 return _make_infos_tuple (self, g_union_info_get_n_fields, g_union_info_get_field);
2225 _wrap_g_union_info_get_methods (PyGIBaseInfo *self)
2227 return _make_infos_tuple (self, g_union_info_get_n_methods, g_union_info_get_method);
2231 _wrap_g_union_info_get_size (PyGIBaseInfo *self)
2233 return PYGLIB_PyLong_FromSize_t (g_union_info_get_size (self->info));
2236 static PyMethodDef _PyGIUnionInfo_methods[] = {
2237 { "get_fields", (PyCFunction) _wrap_g_union_info_get_fields, METH_NOARGS },
2238 { "get_methods", (PyCFunction) _wrap_g_union_info_get_methods, METH_NOARGS },
2239 { "get_size", (PyCFunction) _wrap_g_union_info_get_size, METH_NOARGS },
2246 _pygi_g_base_info_get_fullname (GIBaseInfo *info)
2248 GIBaseInfo *container_info;
2251 container_info = g_base_info_get_container (info);
2252 if (container_info != NULL) {
2253 fullname = g_strdup_printf ("%s.%s.%s",
2254 g_base_info_get_namespace (container_info),
2255 _safe_base_info_get_name (container_info),
2256 _safe_base_info_get_name (info));
2258 fullname = g_strdup_printf ("%s.%s",
2259 g_base_info_get_namespace (info),
2260 _safe_base_info_get_name (info));
2263 if (fullname == NULL) {
2272 _pygi_info_register_types (PyObject *m)
2274 #define _PyGI_REGISTER_TYPE(m, type, cname, base) \
2275 Py_TYPE(&type) = &PyType_Type; \
2276 type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE); \
2277 type.tp_weaklistoffset = offsetof(PyGIBaseInfo, inst_weakreflist); \
2278 type.tp_methods = _PyGI##cname##_methods; \
2279 type.tp_base = &base; \
2280 if (PyType_Ready(&type)) \
2282 if (PyModule_AddObject(m, #cname, (PyObject *)&type)) \
2285 Py_TYPE(&PyGIBaseInfo_Type) = &PyType_Type;
2287 PyGIBaseInfo_Type.tp_dealloc = (destructor) _base_info_dealloc;
2288 PyGIBaseInfo_Type.tp_repr = (reprfunc) _base_info_repr;
2289 PyGIBaseInfo_Type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
2290 PyGIBaseInfo_Type.tp_weaklistoffset = offsetof(PyGIBaseInfo, inst_weakreflist);
2291 PyGIBaseInfo_Type.tp_methods = _PyGIBaseInfo_methods;
2292 PyGIBaseInfo_Type.tp_richcompare = (richcmpfunc)_base_info_richcompare;
2293 PyGIBaseInfo_Type.tp_getset = _base_info_getsets;
2294 PyGIBaseInfo_Type.tp_getattro = (getattrofunc) _base_info_getattro;
2296 if (PyType_Ready(&PyGIBaseInfo_Type))
2298 if (PyModule_AddObject(m, "BaseInfo", (PyObject *)&PyGIBaseInfo_Type))
2301 _PyGI_REGISTER_TYPE (m, PyGICallableInfo_Type, CallableInfo,
2303 PyGICallableInfo_Type.tp_call = (ternaryfunc) _callable_info_call;
2304 PyGICallableInfo_Type.tp_dealloc = (destructor) _callable_info_dealloc;
2306 _PyGI_REGISTER_TYPE (m, PyGIFunctionInfo_Type, FunctionInfo,
2307 PyGICallableInfo_Type);
2308 PyGIFunctionInfo_Type.tp_call = (ternaryfunc) _function_info_call;
2309 PyGIFunctionInfo_Type.tp_descr_get = (descrgetfunc) _function_info_descr_get;
2311 _PyGI_REGISTER_TYPE (m, PyGIVFuncInfo_Type, VFuncInfo,
2312 PyGICallableInfo_Type);
2313 PyGIVFuncInfo_Type.tp_descr_get = (descrgetfunc) _vfunc_info_descr_get;
2315 _PyGI_REGISTER_TYPE (m, PyGISignalInfo_Type, SignalInfo,
2316 PyGICallableInfo_Type);
2318 _PyGI_REGISTER_TYPE (m, PyGIUnresolvedInfo_Type, UnresolvedInfo,
2320 _PyGI_REGISTER_TYPE (m, PyGICallbackInfo_Type, CallbackInfo,
2321 PyGICallableInfo_Type);
2322 _PyGI_REGISTER_TYPE (m, PyGIRegisteredTypeInfo_Type, RegisteredTypeInfo,
2324 _PyGI_REGISTER_TYPE (m, PyGIStructInfo_Type, StructInfo,
2325 PyGIRegisteredTypeInfo_Type);
2326 _PyGI_REGISTER_TYPE (m, PyGIEnumInfo_Type, EnumInfo,
2327 PyGIRegisteredTypeInfo_Type);
2328 _PyGI_REGISTER_TYPE (m, PyGIObjectInfo_Type, ObjectInfo,
2329 PyGIRegisteredTypeInfo_Type);
2330 _PyGI_REGISTER_TYPE (m, PyGIInterfaceInfo_Type, InterfaceInfo,
2331 PyGIRegisteredTypeInfo_Type);
2332 _PyGI_REGISTER_TYPE (m, PyGIConstantInfo_Type, ConstantInfo,
2334 _PyGI_REGISTER_TYPE (m, PyGIValueInfo_Type, ValueInfo,
2336 _PyGI_REGISTER_TYPE (m, PyGIFieldInfo_Type, FieldInfo,
2338 _PyGI_REGISTER_TYPE (m, PyGIUnionInfo_Type, UnionInfo,
2339 PyGIRegisteredTypeInfo_Type);
2340 _PyGI_REGISTER_TYPE (m, PyGIErrorDomainInfo_Type, ErrorDomainInfo,
2342 _PyGI_REGISTER_TYPE (m, PyGIPropertyInfo_Type, PropertyInfo,
2344 _PyGI_REGISTER_TYPE (m, PyGIArgInfo_Type, ArgInfo,
2346 _PyGI_REGISTER_TYPE (m, PyGITypeInfo_Type, TypeInfo,
2349 #undef _PyGI_REGISTER_TYPE
2351 #define _PyGI_ENUM_BEGIN(name) \
2353 const char *__enum_name = #name; \
2354 PyObject *__enum_value = NULL; \
2355 PyObject *__new_enum_cls = NULL; \
2356 PyObject *__enum_instance_dict = PyDict_New(); \
2357 PyObject *__module_name = PyObject_GetAttrString (m, "__name__"); \
2358 PyDict_SetItemString (__enum_instance_dict, "__module__", __module_name); \
2359 Py_DECREF (__module_name);
2361 #define _PyGI_ENUM_ADD_VALUE(prefix, name) \
2362 __enum_value = PYGLIB_PyLong_FromLong (prefix##_##name); \
2363 if (PyDict_SetItemString(__enum_instance_dict, #name, __enum_value)) { \
2364 Py_DECREF (__enum_instance_dict); \
2365 Py_DECREF (__enum_value); \
2368 Py_DECREF (__enum_value);
2370 #define _PyGI_ENUM_END \
2371 __new_enum_cls = PyObject_CallFunction ((PyObject *)&PyType_Type, "s(O)O", \
2372 __enum_name, (PyObject *)&PyType_Type, \
2373 __enum_instance_dict); \
2374 Py_DECREF (__enum_instance_dict); \
2375 PyModule_AddObject (m, __enum_name, __new_enum_cls); /* steals ref */ \
2380 _PyGI_ENUM_BEGIN (Direction)
2381 _PyGI_ENUM_ADD_VALUE (GI_DIRECTION, IN)
2382 _PyGI_ENUM_ADD_VALUE (GI_DIRECTION, OUT)
2383 _PyGI_ENUM_ADD_VALUE (GI_DIRECTION, INOUT)
2388 _PyGI_ENUM_BEGIN (Transfer)
2389 _PyGI_ENUM_ADD_VALUE (GI_TRANSFER, NOTHING)
2390 _PyGI_ENUM_ADD_VALUE (GI_TRANSFER, CONTAINER)
2391 _PyGI_ENUM_ADD_VALUE (GI_TRANSFER, EVERYTHING)
2395 _PyGI_ENUM_BEGIN (ArrayType)
2396 _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE, C)
2397 _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE, ARRAY)
2398 _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE, PTR_ARRAY)
2399 _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE, BYTE_ARRAY)
2403 _PyGI_ENUM_BEGIN (ScopeType)
2404 _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE, INVALID)
2405 _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE, CALL)
2406 _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE, ASYNC)
2407 _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE, NOTIFIED)
2410 /* GIVFuncInfoFlags */
2411 _PyGI_ENUM_BEGIN (VFuncInfoFlags)
2412 _PyGI_ENUM_ADD_VALUE (GI_VFUNC_MUST, CHAIN_UP)
2413 _PyGI_ENUM_ADD_VALUE (GI_VFUNC_MUST, OVERRIDE)
2414 _PyGI_ENUM_ADD_VALUE (GI_VFUNC_MUST, NOT_OVERRIDE)
2417 /* GIFieldInfoFlags */
2418 _PyGI_ENUM_BEGIN (FieldInfoFlags)
2419 _PyGI_ENUM_ADD_VALUE (GI_FIELD, IS_READABLE)
2420 _PyGI_ENUM_ADD_VALUE (GI_FIELD, IS_WRITABLE)
2423 /* GIFunctionInfoFlags */
2424 _PyGI_ENUM_BEGIN (FunctionInfoFlags)
2425 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, IS_METHOD)
2426 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, IS_CONSTRUCTOR)
2427 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, IS_GETTER)
2428 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, IS_SETTER)
2429 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, WRAPS_VFUNC)
2430 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, THROWS)
2434 _PyGI_ENUM_BEGIN (TypeTag)
2436 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, VOID)
2437 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, BOOLEAN)
2438 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, INT8)
2439 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UINT8)
2440 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, INT16)
2441 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UINT16)
2442 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, INT32)
2443 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UINT32)
2444 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, INT64)
2445 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UINT64)
2446 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, FLOAT)
2447 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, DOUBLE)
2448 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, GTYPE)
2449 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UTF8)
2450 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, FILENAME)
2452 /* Non-basic types; compare with G_TYPE_TAG_IS_BASIC */
2453 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, ARRAY)
2454 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, INTERFACE)
2455 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, GLIST)
2456 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, GSLIST)
2457 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, GHASH)
2458 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, ERROR)
2460 /* Another basic type */
2461 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UNICHAR)
2465 _PyGI_ENUM_BEGIN (InfoType)
2466 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, INVALID)
2467 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, FUNCTION)
2468 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, CALLBACK)
2469 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, STRUCT)
2470 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, BOXED)
2471 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, ENUM)
2472 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, FLAGS)
2473 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, OBJECT)
2474 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, INTERFACE)
2475 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, CONSTANT)
2476 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, INVALID_0)
2477 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, UNION)
2478 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, VALUE)
2479 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, SIGNAL)
2480 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, VFUNC)
2481 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, PROPERTY)
2482 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, FIELD)
2483 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, ARG)
2484 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, TYPE)
2485 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, UNRESOLVED)
2488 #undef _PyGI_ENUM_BEGIN
2489 #undef _PyGI_ENUM_ADD_VALUE
2490 #undef _PyGI_ENUM_END