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-info.h"
24 #include "pygi-cache.h"
25 #include "pygi-invoke.h"
26 #include "pygi-type.h"
27 #include "pygi-argument.h"
28 #include "pygi-util.h"
31 #include <pyglib-python-compat.h>
34 /* _generate_doc_string
36 * C wrapper to call Python implemented "gi.docstring.generate_doc_string"
39 _generate_doc_string(PyGIBaseInfo *self)
41 static PyObject *_py_generate_doc_string = NULL;
43 if (_py_generate_doc_string == NULL) {
44 PyObject *mod = PyImport_ImportModule ("gi.docstring");
48 _py_generate_doc_string = PyObject_GetAttrString (mod, "generate_doc_string");
49 if (_py_generate_doc_string == NULL) {
56 return PyObject_CallFunctionObjArgs (_py_generate_doc_string, self, NULL);
60 _get_info_string (PyGIBaseInfo *self,
61 const gchar* (*get_info_string)(GIBaseInfo*))
63 const gchar *value = get_info_string ((GIBaseInfo*)self->info);
67 return PYGLIB_PyUnicode_FromString (value);
71 _get_child_info (PyGIBaseInfo *self,
72 GIBaseInfo* (*get_child_info)(GIBaseInfo*))
77 info = get_child_info ((GIBaseInfo*)self->info);
82 py_info = _pygi_info_new (info);
83 g_base_info_unref (info);
89 _get_child_info_by_name (PyGIBaseInfo *self, PyObject *py_name,
90 GIBaseInfo* (*get_child_info_by_name)(GIBaseInfo*, const gchar*))
96 if (!PYGLIB_PyUnicode_Check (py_name)) {
97 PyErr_SetString (PyExc_TypeError, "expected string name");
101 name = PYGLIB_PyUnicode_AsString (py_name);
102 info = get_child_info_by_name ((GIObjectInfo*)self->info, name);
107 py_info = _pygi_info_new (info);
108 g_base_info_unref (info);
115 * Build a tuple from the common API pattern in GI of having a
116 * function which returns a count and an indexed GIBaseInfo
117 * in the range of 0 to count;
120 _make_infos_tuple (PyGIBaseInfo *self,
121 gint (*get_n_infos)(GIBaseInfo*),
122 GIBaseInfo* (*get_info)(GIBaseInfo*, gint))
128 n_infos = get_n_infos ( (GIBaseInfo *) self->info);
130 infos = PyTuple_New (n_infos);
135 for (i = 0; i < n_infos; i++) {
139 info = (GIBaseInfo *) get_info (self->info, i);
140 g_assert (info != NULL);
142 py_info = _pygi_info_new (info);
144 g_base_info_unref (info);
146 if (py_info == NULL) {
151 PyTuple_SET_ITEM (infos, i, py_info);
160 /* We need to be careful about calling g_base_info_get_name because
161 * calling it with a GI_INFO_TYPE_TYPE will crash.
162 * See: https://bugzilla.gnome.org/show_bug.cgi?id=709456
165 _safe_base_info_get_name (GIBaseInfo *info)
167 if (g_base_info_get_type (info) == GI_INFO_TYPE_TYPE) {
168 return "type_type_instance";
170 return g_base_info_get_name (info);
175 _base_info_dealloc (PyGIBaseInfo *self)
177 if (self->inst_weakreflist != NULL)
178 PyObject_ClearWeakRefs ( (PyObject *) self);
180 g_base_info_unref (self->info);
182 if (self->cache != NULL)
183 pygi_callable_cache_free ( (PyGICallableCache *) self->cache);
185 Py_TYPE (self)->tp_free ((PyObject *)self);
189 _base_info_repr (PyGIBaseInfo *self)
192 return PYGLIB_PyUnicode_FromFormat ("%s(%s)",
193 Py_TYPE( (PyObject *) self)->tp_name,
194 _safe_base_info_get_name (self->info));
198 _wrap_g_base_info_equal (PyGIBaseInfo *self, PyObject *other)
200 GIBaseInfo *other_info;
202 if (!PyObject_TypeCheck (other, &PyGIBaseInfo_Type)) {
203 Py_INCREF (Py_NotImplemented);
204 return Py_NotImplemented;
207 other_info = ((PyGIBaseInfo *)other)->info;
208 if (g_base_info_equal (self->info, other_info)) {
216 _base_info_richcompare (PyGIBaseInfo *self, PyObject *other, int op)
222 return _wrap_g_base_info_equal (self, other);
224 res = _wrap_g_base_info_equal (self, other);
225 if (res == Py_True) {
233 res = Py_NotImplemented;
240 PYGLIB_DEFINE_TYPE("gi.BaseInfo", PyGIBaseInfo_Type, PyGIBaseInfo);
243 _pygi_is_python_keyword (const gchar *name)
245 /* It may be better to use keyword.iskeyword(); keep in sync with
246 * python -c 'import keyword; print(keyword.kwlist)' */
247 #if PY_VERSION_HEX < 0x03000000
249 static const gchar* keywords[] = {"and", "as", "assert", "break", "class",
250 "continue", "def", "del", "elif", "else", "except", "exec", "finally",
251 "for", "from", "global", "if", "import", "in", "is", "lambda", "not",
252 "or", "pass", "print", "raise", "return", "try", "while", "with",
254 #elif PY_VERSION_HEX < 0x04000000
255 /* Python 3.x; note that we explicitly keep "print"; it is not a keyword
256 * any more, but we do not want to break API between Python versions */
257 static const gchar* keywords[] = {"False", "None", "True", "and", "as",
258 "assert", "break", "class", "continue", "def", "del", "elif", "else",
259 "except", "finally", "for", "from", "global", "if", "import", "in",
260 "is", "lambda", "nonlocal", "not", "or", "pass", "raise", "return",
261 "try", "while", "with", "yield",
264 #error Need keyword list for this major Python version
269 for (i = keywords; *i != NULL; ++i) {
270 if (strcmp (name, *i) == 0) {
279 _wrap_g_base_info_get_type (PyGIBaseInfo *self)
281 return PYGLIB_PyLong_FromLong (g_base_info_get_type (self->info));
285 _wrap_g_base_info_get_name (PyGIBaseInfo *self)
289 name = _safe_base_info_get_name (self->info);
291 /* escape keywords */
292 if (_pygi_is_python_keyword (name)) {
293 gchar *escaped = g_strconcat (name, "_", NULL);
294 PyObject *obj = PYGLIB_PyUnicode_FromString (escaped);
299 return PYGLIB_PyUnicode_FromString (name);
303 _wrap_g_base_info_get_name_unescaped (PyGIBaseInfo *self)
305 return _get_info_string (self, _safe_base_info_get_name);
309 _wrap_g_base_info_get_namespace (PyGIBaseInfo *self)
311 return _get_info_string (self, g_base_info_get_namespace);
315 _wrap_g_base_info_is_deprecated (PyGIBaseInfo *self)
317 if (g_base_info_is_deprecated (self->info))
324 _wrap_g_base_info_get_attribute (PyGIBaseInfo *self, PyObject *arg)
329 if (!PYGLIB_PyUnicode_Check (arg)) {
330 PyErr_SetString (PyExc_TypeError, "expected string name");
334 name = PYGLIB_PyUnicode_AsString (arg);
335 value = g_base_info_get_attribute (self->info, name);
339 return PYGLIB_PyUnicode_FromString (value);
343 _wrap_g_base_info_get_container (PyGIBaseInfo *self)
345 /* Note: don't use _get_child_info because g_base_info_get_container
346 * is marked as [transfer none] and therefore returns a borrowed ref.
350 info = g_base_info_get_container (self->info);
356 return _pygi_info_new (info);
360 static PyMethodDef _PyGIBaseInfo_methods[] = {
361 { "get_type", (PyCFunction) _wrap_g_base_info_get_type, METH_NOARGS },
362 { "get_name", (PyCFunction) _wrap_g_base_info_get_name, METH_NOARGS },
363 { "get_name_unescaped", (PyCFunction) _wrap_g_base_info_get_name_unescaped, METH_NOARGS },
364 { "get_namespace", (PyCFunction) _wrap_g_base_info_get_namespace, METH_NOARGS },
365 { "is_deprecated", (PyCFunction) _wrap_g_base_info_is_deprecated, METH_NOARGS },
366 { "get_attribute", (PyCFunction) _wrap_g_base_info_get_attribute, METH_O },
367 { "get_container", (PyCFunction) _wrap_g_base_info_get_container, METH_NOARGS },
368 { "equal", (PyCFunction) _wrap_g_base_info_equal, METH_O },
372 /* _base_info_getattro:
374 * The usage of __getattr__ is needed because the get/set method table
375 * does not work for __doc__.
378 _base_info_getattro(PyGIBaseInfo *self, PyObject *name)
382 static PyObject *docstr;
383 if (docstr == NULL) {
384 docstr= PYGLIB_PyUnicode_InternFromString("__doc__");
390 PYGLIB_PyUnicode_InternInPlace (&name);
392 if (name == docstr) {
393 result = _generate_doc_string (self);
395 result = PyObject_GenericGetAttr ((PyObject *)self, name);
403 _base_info_attr_name(PyGIBaseInfo *self, void *closure)
405 return _wrap_g_base_info_get_name (self);
409 _base_info_attr_module(PyGIBaseInfo *self, void *closure)
411 return PYGLIB_PyUnicode_FromFormat ("gi.repository.%s",
412 g_base_info_get_namespace (self->info));
415 static PyGetSetDef _base_info_getsets[] = {
416 { "__name__", (getter)_base_info_attr_name, (setter)0, "Name", NULL},
417 { "__module__", (getter)_base_info_attr_module, (setter)0, "Module name", NULL},
422 _pygi_info_new (GIBaseInfo *info)
424 GIInfoType info_type;
425 PyTypeObject *type = NULL;
428 info_type = g_base_info_get_type (info);
432 case GI_INFO_TYPE_INVALID:
433 PyErr_SetString (PyExc_RuntimeError, "Invalid info type");
435 case GI_INFO_TYPE_FUNCTION:
436 type = &PyGIFunctionInfo_Type;
438 case GI_INFO_TYPE_CALLBACK:
439 type = &PyGICallbackInfo_Type;
441 case GI_INFO_TYPE_STRUCT:
442 case GI_INFO_TYPE_BOXED:
443 type = &PyGIStructInfo_Type;
445 case GI_INFO_TYPE_ENUM:
446 case GI_INFO_TYPE_FLAGS:
447 type = &PyGIEnumInfo_Type;
449 case GI_INFO_TYPE_OBJECT:
450 type = &PyGIObjectInfo_Type;
452 case GI_INFO_TYPE_INTERFACE:
453 type = &PyGIInterfaceInfo_Type;
455 case GI_INFO_TYPE_CONSTANT:
456 type = &PyGIConstantInfo_Type;
458 case GI_INFO_TYPE_UNION:
459 type = &PyGIUnionInfo_Type;
461 case GI_INFO_TYPE_VALUE:
462 type = &PyGIValueInfo_Type;
464 case GI_INFO_TYPE_SIGNAL:
465 type = &PyGISignalInfo_Type;
467 case GI_INFO_TYPE_VFUNC:
468 type = &PyGIVFuncInfo_Type;
470 case GI_INFO_TYPE_PROPERTY:
471 type = &PyGIPropertyInfo_Type;
473 case GI_INFO_TYPE_FIELD:
474 type = &PyGIFieldInfo_Type;
476 case GI_INFO_TYPE_ARG:
477 type = &PyGIArgInfo_Type;
479 case GI_INFO_TYPE_TYPE:
480 type = &PyGITypeInfo_Type;
482 case GI_INFO_TYPE_UNRESOLVED:
483 type = &PyGIUnresolvedInfo_Type;
486 g_assert_not_reached();
490 self = (PyGIBaseInfo *) type->tp_alloc (type, 0);
495 self->info = g_base_info_ref (info);
496 self->inst_weakreflist = NULL;
499 return (PyObject *) self;
503 _pygi_object_get_gi_info (PyObject *object,
507 GIBaseInfo *info = NULL;
509 py_info = PyObject_GetAttrString (object, "__info__");
510 if (py_info == NULL) {
513 if (!PyObject_TypeCheck (py_info, type)) {
514 PyErr_Format (PyExc_TypeError, "attribute '__info__' must be %s, not %s",
515 type->tp_name, Py_TYPE(py_info)->tp_name);
519 info = ( (PyGIBaseInfo *) py_info)->info;
520 g_base_info_ref (info);
530 PYGLIB_DEFINE_TYPE ("gi.CallableInfo", PyGICallableInfo_Type, PyGICallableInfo);
532 /* _callable_info_call:
534 * Shared wrapper for invoke which can be bound (instance method or class constructor)
535 * or unbound (function or static method).
538 _callable_info_call (PyGICallableInfo *self, PyObject *args, PyObject *kwargs)
540 /* Insert the bound arg at the beginning of the invoke method args. */
541 if (self->py_bound_arg) {
544 Py_ssize_t argcount = PyTuple_Size (args);
545 PyObject *newargs = PyTuple_New (argcount + 1);
549 Py_INCREF (self->py_bound_arg);
550 PyTuple_SET_ITEM (newargs, 0, self->py_bound_arg);
552 for (i = 0; i < argcount; i++) {
553 PyObject *v = PyTuple_GET_ITEM (args, i);
555 PyTuple_SET_ITEM (newargs, i+1, v);
558 /* Invoke with the original GI info struct this wrapper was based upon.
559 * This is necessary to maintain the same cache for all bound versions.
561 result = _wrap_g_callable_info_invoke ((PyGIBaseInfo *)self->py_unbound_info,
567 /* We should never have an unbound info when calling when calling invoke
568 * at this point because the descriptor implementation on sub-classes
569 * should return "self" not a copy when there is no bound arg.
571 g_assert (self->py_unbound_info == NULL);
572 return _wrap_g_callable_info_invoke ((PyGIBaseInfo *)self, args, kwargs);
577 /* _function_info_call:
579 * Specialization of _callable_info_call for GIFunctionInfo which
580 * handles constructor error conditions.
583 _function_info_call (PyGICallableInfo *self, PyObject *args, PyObject *kwargs)
585 if (self->py_bound_arg) {
586 GIFunctionInfoFlags flags;
588 /* Ensure constructors are only called as class methods on the class
589 * implementing the constructor and not on sub-classes.
591 flags = g_function_info_get_flags ( (GIFunctionInfo*) self->base.info);
592 if (flags & GI_FUNCTION_IS_CONSTRUCTOR) {
593 PyObject *py_str_name;
594 const gchar *str_name;
595 GIBaseInfo *container_info = g_base_info_get_container (self->base.info);
596 g_assert (container_info != NULL);
598 py_str_name = PyObject_GetAttrString (self->py_bound_arg, "__name__");
599 if (py_str_name == NULL)
602 if (PyUnicode_Check (py_str_name) ) {
603 PyObject *tmp = PyUnicode_AsUTF8String (py_str_name);
604 Py_DECREF (py_str_name);
608 #if PY_VERSION_HEX < 0x03000000
609 str_name = PyString_AsString (py_str_name);
611 str_name = PyBytes_AsString (py_str_name);
614 if (strcmp (str_name, _safe_base_info_get_name (container_info))) {
615 PyErr_Format (PyExc_TypeError,
616 "%s constructor cannot be used to create instances of "
618 _safe_base_info_get_name (container_info),
620 Py_DECREF (py_str_name);
623 Py_DECREF (py_str_name);
627 return _callable_info_call (self, args, kwargs);
630 /* _new_bound_callable_info
632 * Utility function for sub-classes to create a bound version of themself.
634 static PyGICallableInfo *
635 _new_bound_callable_info (PyGICallableInfo *self, PyObject *bound_arg)
637 PyGICallableInfo *new_self;
639 /* Return self if this is already bound or there is nothing passed to bind. */
640 if (self->py_bound_arg != NULL || bound_arg == NULL || bound_arg == Py_None) {
641 Py_INCREF ((PyObject *)self);
645 new_self = (PyGICallableInfo *)_pygi_info_new (self->base.info);
646 if (new_self == NULL)
649 Py_INCREF ((PyObject *)self);
650 new_self->py_unbound_info = (struct PyGICallableInfo *)self;
652 Py_INCREF (bound_arg);
653 new_self->py_bound_arg = bound_arg;
658 /* _function_info_descr_get
660 * Descriptor protocol implementation for functions, methods, and constructors.
663 _function_info_descr_get (PyGICallableInfo *self, PyObject *obj, PyObject *type) {
664 GIFunctionInfoFlags flags;
665 PyObject *bound_arg = NULL;
667 flags = g_function_info_get_flags ( (GIFunctionInfo*) self->base.info);
668 if (flags & GI_FUNCTION_IS_CONSTRUCTOR) {
670 bound_arg = (PyObject *)(Py_TYPE(obj));
673 } else if (flags & GI_FUNCTION_IS_METHOD) {
677 return (PyObject *)_new_bound_callable_info (self, bound_arg);
680 /* _vfunc_info_descr_get
682 * Descriptor protocol implementation for virtual functions.
685 _vfunc_info_descr_get (PyGICallableInfo *self, PyObject *obj, PyObject *type) {
687 PyObject *bound_arg = NULL;
689 bound_arg = PyObject_GetAttrString (type, "__gtype__");
690 if (bound_arg == NULL)
693 /* _new_bound_callable_info adds its own ref so free the one from GetAttrString */
694 result = (PyObject *)_new_bound_callable_info (self, bound_arg);
695 Py_DECREF (bound_arg);
700 _callable_info_dealloc (PyGICallableInfo *self)
702 Py_CLEAR (self->py_unbound_info);
703 Py_CLEAR (self->py_bound_arg);
705 PyGIBaseInfo_Type.tp_dealloc ((PyObject *) self);
709 _wrap_g_callable_info_get_arguments (PyGIBaseInfo *self)
711 return _make_infos_tuple (self, g_callable_info_get_n_args, g_callable_info_get_arg);
715 _wrap_g_callable_info_get_return_type (PyGIBaseInfo *self)
717 return _get_child_info (self, g_callable_info_get_return_type);
721 _wrap_g_callable_info_get_caller_owns (PyGIBaseInfo *self)
723 return PYGLIB_PyLong_FromLong (
724 g_callable_info_get_caller_owns (self->info) );
728 _wrap_g_callable_info_may_return_null (PyGIBaseInfo *self)
730 return PyBool_FromLong (
731 g_callable_info_may_return_null (self->info) );
735 _wrap_g_callable_info_skip_return (PyGIBaseInfo *self)
737 return PyBool_FromLong (g_callable_info_skip_return (self->info));
741 _wrap_g_callable_info_get_return_attribute (PyGIBaseInfo *self, PyObject *py_name)
746 if (!PYGLIB_PyUnicode_Check (py_name)) {
747 PyErr_SetString (PyExc_TypeError, "expected string name");
751 name = PYGLIB_PyUnicode_AsString (py_name);
752 attr = g_callable_info_get_return_attribute (self->info, name);
754 return PYGLIB_PyUnicode_FromString (
755 g_callable_info_get_return_attribute (self->info, name));
757 PyErr_Format(PyExc_AttributeError, "return attribute %s not found", name);
763 _wrap_g_callable_info_can_throw_gerror (PyGIBaseInfo *self)
765 if (g_callable_info_can_throw_gerror (self->info))
771 static PyMethodDef _PyGICallableInfo_methods[] = {
772 { "invoke", (PyCFunction) _wrap_g_callable_info_invoke, METH_VARARGS | METH_KEYWORDS },
773 { "get_arguments", (PyCFunction) _wrap_g_callable_info_get_arguments, METH_NOARGS },
774 { "get_return_type", (PyCFunction) _wrap_g_callable_info_get_return_type, METH_NOARGS },
775 { "get_caller_owns", (PyCFunction) _wrap_g_callable_info_get_caller_owns, METH_NOARGS },
776 { "may_return_null", (PyCFunction) _wrap_g_callable_info_may_return_null, METH_NOARGS },
777 { "skip_return", (PyCFunction) _wrap_g_callable_info_skip_return, METH_NOARGS },
778 { "get_return_attribute", (PyCFunction) _wrap_g_callable_info_get_return_attribute, METH_O },
779 { "can_throw_gerror", (PyCFunction) _wrap_g_callable_info_can_throw_gerror, METH_NOARGS },
784 PYGLIB_DEFINE_TYPE ("gi.CallbackInfo", PyGICallbackInfo_Type, PyGICallableInfo);
786 static PyMethodDef _PyGICallbackInfo_methods[] = {
790 /* ErrorDomainInfo */
791 PYGLIB_DEFINE_TYPE ("gi.ErrorDomainInfo", PyGIErrorDomainInfo_Type, PyGIBaseInfo);
793 static PyMethodDef _PyGIErrorDomainInfo_methods[] = {
798 PYGLIB_DEFINE_TYPE ("gi.SignalInfo", PyGISignalInfo_Type, PyGICallableInfo);
801 _wrap_g_signal_info_get_flags (PyGIBaseInfo *self)
803 return PYGLIB_PyLong_FromLong (
804 g_signal_info_get_flags ((GISignalInfo *)self->info) );
808 _wrap_g_signal_info_get_class_closure (PyGIBaseInfo *self)
810 return _get_child_info (self, g_signal_info_get_class_closure);
814 _wrap_g_signal_info_true_stops_emit (PyGIBaseInfo *self)
816 return PyBool_FromLong (
817 g_signal_info_true_stops_emit ((GISignalInfo *)self->info) );
820 static PyMethodDef _PyGISignalInfo_methods[] = {
821 { "get_flags", (PyCFunction) _wrap_g_signal_info_get_flags, METH_NOARGS },
822 { "get_class_closure", (PyCFunction) _wrap_g_signal_info_get_class_closure, METH_NOARGS },
823 { "true_stops_emit", (PyCFunction) _wrap_g_signal_info_true_stops_emit, METH_NOARGS },
828 PYGLIB_DEFINE_TYPE ("gi.PropertyInfo", PyGIPropertyInfo_Type, PyGIBaseInfo);
831 _wrap_g_property_info_get_flags (PyGIBaseInfo *self)
833 return PYGLIB_PyLong_FromLong (
834 g_property_info_get_flags ((GIPropertyInfo *)self->info) );
838 _wrap_g_property_info_get_type (PyGIBaseInfo *self)
840 return _get_child_info (self, g_property_info_get_type);
844 _wrap_g_property_info_get_ownership_transfer (PyGIBaseInfo *self)
846 return PYGLIB_PyLong_FromLong (
847 g_property_info_get_ownership_transfer ((GIPropertyInfo *)self->info) );
850 static PyMethodDef _PyGIPropertyInfo_methods[] = {
851 { "get_flags", (PyCFunction) _wrap_g_property_info_get_flags, METH_NOARGS },
852 { "get_type", (PyCFunction) _wrap_g_property_info_get_type, METH_NOARGS },
853 { "get_ownership_transfer", (PyCFunction) _wrap_g_property_info_get_ownership_transfer, METH_NOARGS },
859 PYGLIB_DEFINE_TYPE ("gi.ArgInfo", PyGIArgInfo_Type, PyGIBaseInfo);
862 _wrap_g_arg_info_get_direction (PyGIBaseInfo *self)
864 return PYGLIB_PyLong_FromLong (
865 g_arg_info_get_direction ((GIArgInfo*)self->info) );
869 _wrap_g_arg_info_is_caller_allocates (PyGIBaseInfo *self)
871 return PyBool_FromLong (
872 g_arg_info_is_caller_allocates ((GIArgInfo*)self->info) );
876 _wrap_g_arg_info_is_return_value (PyGIBaseInfo *self)
878 return PyBool_FromLong (
879 g_arg_info_is_return_value ((GIArgInfo*)self->info) );
883 _wrap_g_arg_info_is_optional (PyGIBaseInfo *self)
885 return PyBool_FromLong (
886 g_arg_info_is_optional ((GIArgInfo*)self->info) );
890 _wrap_g_arg_info_may_be_null (PyGIBaseInfo *self)
892 return PyBool_FromLong (
893 g_arg_info_may_be_null ((GIArgInfo*)self->info) );
897 _wrap_g_arg_info_get_ownership_transfer (PyGIBaseInfo *self)
899 return PYGLIB_PyLong_FromLong (
900 g_arg_info_get_ownership_transfer ((GIArgInfo *)self->info) );
904 _wrap_g_arg_info_get_scope (PyGIBaseInfo *self)
906 return PYGLIB_PyLong_FromLong (
907 g_arg_info_get_scope ((GIArgInfo *)self->info) );
911 _wrap_g_arg_info_get_closure (PyGIBaseInfo *self)
913 return PYGLIB_PyLong_FromLong (
914 g_arg_info_get_closure ((GIArgInfo *)self->info) );
918 _wrap_g_arg_info_get_destroy (PyGIBaseInfo *self)
920 return PYGLIB_PyLong_FromLong (
921 g_arg_info_get_destroy ((GIArgInfo *)self->info) );
925 _wrap_g_arg_info_get_type (PyGIBaseInfo *self)
927 return _get_child_info (self, g_arg_info_get_type);
930 static PyMethodDef _PyGIArgInfo_methods[] = {
931 { "get_direction", (PyCFunction) _wrap_g_arg_info_get_direction, METH_NOARGS },
932 { "is_caller_allocates", (PyCFunction) _wrap_g_arg_info_is_caller_allocates, METH_NOARGS },
933 { "is_return_value", (PyCFunction) _wrap_g_arg_info_is_return_value, METH_NOARGS },
934 { "is_optional", (PyCFunction) _wrap_g_arg_info_is_optional, METH_NOARGS },
935 { "may_be_null", (PyCFunction) _wrap_g_arg_info_may_be_null, METH_NOARGS },
936 { "get_ownership_transfer", (PyCFunction) _wrap_g_arg_info_get_ownership_transfer, METH_NOARGS },
937 { "get_scope", (PyCFunction) _wrap_g_arg_info_get_scope, METH_NOARGS },
938 { "get_closure", (PyCFunction) _wrap_g_arg_info_get_closure, METH_NOARGS },
939 { "get_destroy", (PyCFunction) _wrap_g_arg_info_get_destroy, METH_NOARGS },
940 { "get_type", (PyCFunction) _wrap_g_arg_info_get_type, METH_NOARGS },
946 PYGLIB_DEFINE_TYPE ("gi.TypeInfo", PyGITypeInfo_Type, PyGIBaseInfo);
949 _wrap_g_type_info_is_pointer (PyGIBaseInfo *self)
951 return PyBool_FromLong (g_type_info_is_pointer (self->info));
955 _wrap_g_type_info_get_tag (PyGIBaseInfo *self)
957 return PYGLIB_PyLong_FromLong (g_type_info_get_tag (self->info));
961 _wrap_g_type_info_get_tag_as_string (PyGIBaseInfo *self)
963 GITypeTag tag = g_type_info_get_tag (self->info);
964 return PYGLIB_PyUnicode_FromString (g_type_tag_to_string(tag));
968 _wrap_g_type_info_get_param_type (PyGIBaseInfo *self, PyObject *py_n)
974 if (!PYGLIB_PyLong_Check (py_n)) {
975 PyErr_SetString(PyExc_TypeError, "expected integer value");
979 n = PYGLIB_PyLong_AsLong (py_n);
980 info = (GIBaseInfo *) g_type_info_get_param_type ( (GITypeInfo *) self->info, n);
985 py_info = _pygi_info_new (info);
986 g_base_info_unref (info);
991 _wrap_g_type_info_get_interface (PyGIBaseInfo *self)
993 return _get_child_info (self, g_type_info_get_interface);
997 _wrap_g_type_info_get_array_length (PyGIBaseInfo *self)
999 return PYGLIB_PyLong_FromLong (g_type_info_get_array_length (self->info));
1003 _wrap_g_type_info_get_array_fixed_size (PyGIBaseInfo *self)
1005 return PYGLIB_PyLong_FromLong (g_type_info_get_array_fixed_size (self->info));
1009 _wrap_g_type_info_is_zero_terminated (PyGIBaseInfo *self)
1011 return PyBool_FromLong (g_type_info_is_zero_terminated (self->info));
1015 _wrap_g_type_info_get_array_type (PyGIBaseInfo *self)
1017 return PYGLIB_PyLong_FromLong (g_type_info_get_array_type (self->info));
1020 static PyMethodDef _PyGITypeInfo_methods[] = {
1021 { "is_pointer", (PyCFunction) _wrap_g_type_info_is_pointer, METH_NOARGS },
1022 { "get_tag", (PyCFunction) _wrap_g_type_info_get_tag, METH_NOARGS },
1023 { "get_tag_as_string", (PyCFunction) _wrap_g_type_info_get_tag_as_string, METH_NOARGS },
1024 { "get_param_type", (PyCFunction) _wrap_g_type_info_get_param_type, METH_O },
1025 { "get_interface", (PyCFunction) _wrap_g_type_info_get_interface, METH_NOARGS },
1026 { "get_array_length", (PyCFunction) _wrap_g_type_info_get_array_length, METH_NOARGS },
1027 { "get_array_fixed_size", (PyCFunction) _wrap_g_type_info_get_array_fixed_size, METH_NOARGS },
1028 { "is_zero_terminated", (PyCFunction) _wrap_g_type_info_is_zero_terminated, METH_NOARGS },
1029 { "get_array_type", (PyCFunction) _wrap_g_type_info_get_array_type, METH_NOARGS },
1035 PYGLIB_DEFINE_TYPE ("gi.FunctionInfo", PyGIFunctionInfo_Type, PyGICallableInfo);
1038 _wrap_g_function_info_is_constructor (PyGIBaseInfo *self)
1040 GIFunctionInfoFlags flags;
1041 gboolean is_constructor;
1043 flags = g_function_info_get_flags ( (GIFunctionInfo*) self->info);
1044 is_constructor = flags & GI_FUNCTION_IS_CONSTRUCTOR;
1046 return PyBool_FromLong (is_constructor);
1050 _wrap_g_function_info_is_method (PyGIBaseInfo *self)
1052 GIFunctionInfoFlags flags;
1055 flags = g_function_info_get_flags ( (GIFunctionInfo*) self->info);
1056 is_method = flags & GI_FUNCTION_IS_METHOD;
1058 return PyBool_FromLong (is_method);
1062 _pygi_g_type_tag_size (GITypeTag type_tag)
1067 case GI_TYPE_TAG_BOOLEAN:
1068 size = sizeof (gboolean);
1070 case GI_TYPE_TAG_INT8:
1071 case GI_TYPE_TAG_UINT8:
1072 size = sizeof (gint8);
1074 case GI_TYPE_TAG_INT16:
1075 case GI_TYPE_TAG_UINT16:
1076 size = sizeof (gint16);
1078 case GI_TYPE_TAG_INT32:
1079 case GI_TYPE_TAG_UINT32:
1080 size = sizeof (gint32);
1082 case GI_TYPE_TAG_INT64:
1083 case GI_TYPE_TAG_UINT64:
1084 size = sizeof (gint64);
1086 case GI_TYPE_TAG_FLOAT:
1087 size = sizeof (gfloat);
1089 case GI_TYPE_TAG_DOUBLE:
1090 size = sizeof (gdouble);
1092 case GI_TYPE_TAG_GTYPE:
1093 size = sizeof (GType);
1095 case GI_TYPE_TAG_UNICHAR:
1096 size = sizeof (gunichar);
1098 case GI_TYPE_TAG_VOID:
1099 case GI_TYPE_TAG_UTF8:
1100 case GI_TYPE_TAG_FILENAME:
1101 case GI_TYPE_TAG_ARRAY:
1102 case GI_TYPE_TAG_INTERFACE:
1103 case GI_TYPE_TAG_GLIST:
1104 case GI_TYPE_TAG_GSLIST:
1105 case GI_TYPE_TAG_GHASH:
1106 case GI_TYPE_TAG_ERROR:
1107 PyErr_Format (PyExc_TypeError,
1108 "Unable to know the size (assuming %s is not a pointer)",
1109 g_type_tag_to_string (type_tag));
1117 _pygi_g_type_info_size (GITypeInfo *type_info)
1123 type_tag = g_type_info_get_tag (type_info);
1125 case GI_TYPE_TAG_BOOLEAN:
1126 case GI_TYPE_TAG_INT8:
1127 case GI_TYPE_TAG_UINT8:
1128 case GI_TYPE_TAG_INT16:
1129 case GI_TYPE_TAG_UINT16:
1130 case GI_TYPE_TAG_INT32:
1131 case GI_TYPE_TAG_UINT32:
1132 case GI_TYPE_TAG_INT64:
1133 case GI_TYPE_TAG_UINT64:
1134 case GI_TYPE_TAG_FLOAT:
1135 case GI_TYPE_TAG_DOUBLE:
1136 case GI_TYPE_TAG_GTYPE:
1137 case GI_TYPE_TAG_UNICHAR:
1138 size = _pygi_g_type_tag_size (type_tag);
1139 g_assert (size > 0);
1141 case GI_TYPE_TAG_INTERFACE:
1144 GIInfoType info_type;
1146 info = g_type_info_get_interface (type_info);
1147 info_type = g_base_info_get_type (info);
1149 switch (info_type) {
1150 case GI_INFO_TYPE_STRUCT:
1151 if (g_type_info_is_pointer (type_info)) {
1152 size = sizeof (gpointer);
1154 size = g_struct_info_get_size ( (GIStructInfo *) info);
1157 case GI_INFO_TYPE_UNION:
1158 if (g_type_info_is_pointer (type_info)) {
1159 size = sizeof (gpointer);
1161 size = g_union_info_get_size ( (GIUnionInfo *) info);
1164 case GI_INFO_TYPE_ENUM:
1165 case GI_INFO_TYPE_FLAGS:
1166 if (g_type_info_is_pointer (type_info)) {
1167 size = sizeof (gpointer);
1171 type_tag = g_enum_info_get_storage_type ( (GIEnumInfo *) info);
1172 size = _pygi_g_type_tag_size (type_tag);
1175 case GI_INFO_TYPE_BOXED:
1176 case GI_INFO_TYPE_OBJECT:
1177 case GI_INFO_TYPE_INTERFACE:
1178 case GI_INFO_TYPE_CALLBACK:
1179 size = sizeof (gpointer);
1181 case GI_INFO_TYPE_VFUNC:
1182 case GI_INFO_TYPE_INVALID:
1183 case GI_INFO_TYPE_FUNCTION:
1184 case GI_INFO_TYPE_CONSTANT:
1185 case GI_INFO_TYPE_VALUE:
1186 case GI_INFO_TYPE_SIGNAL:
1187 case GI_INFO_TYPE_PROPERTY:
1188 case GI_INFO_TYPE_FIELD:
1189 case GI_INFO_TYPE_ARG:
1190 case GI_INFO_TYPE_TYPE:
1191 case GI_INFO_TYPE_UNRESOLVED:
1193 g_assert_not_reached();
1197 g_base_info_unref (info);
1200 case GI_TYPE_TAG_ARRAY:
1201 case GI_TYPE_TAG_VOID:
1202 case GI_TYPE_TAG_UTF8:
1203 case GI_TYPE_TAG_FILENAME:
1204 case GI_TYPE_TAG_GLIST:
1205 case GI_TYPE_TAG_GSLIST:
1206 case GI_TYPE_TAG_GHASH:
1207 case GI_TYPE_TAG_ERROR:
1208 size = sizeof (gpointer);
1216 _wrap_g_function_info_get_symbol (PyGIBaseInfo *self)
1218 return _get_info_string (self, g_function_info_get_symbol);
1222 _wrap_g_function_info_get_flags (PyGIBaseInfo *self)
1224 return PYGLIB_PyLong_FromLong (g_function_info_get_flags (self->info));
1228 _wrap_g_function_info_get_property (PyGIBaseInfo *self)
1230 return _get_child_info (self, g_function_info_get_property);
1234 _wrap_g_function_info_get_vfunc (PyGIBaseInfo *self)
1236 return _get_child_info (self, g_function_info_get_vfunc);
1239 static PyMethodDef _PyGIFunctionInfo_methods[] = {
1240 { "is_constructor", (PyCFunction) _wrap_g_function_info_is_constructor, METH_NOARGS },
1241 { "is_method", (PyCFunction) _wrap_g_function_info_is_method, METH_NOARGS },
1242 { "get_symbol", (PyCFunction) _wrap_g_function_info_get_symbol, METH_NOARGS },
1243 { "get_flags", (PyCFunction) _wrap_g_function_info_get_flags, METH_NOARGS },
1244 { "get_property", (PyCFunction) _wrap_g_function_info_get_property, METH_NOARGS },
1245 { "get_vfunc", (PyCFunction) _wrap_g_function_info_get_vfunc, METH_NOARGS },
1249 /* RegisteredTypeInfo */
1250 PYGLIB_DEFINE_TYPE ("gi.RegisteredTypeInfo", PyGIRegisteredTypeInfo_Type, PyGIBaseInfo);
1253 _wrap_g_registered_type_info_get_type_name (PyGIBaseInfo *self)
1255 return _get_info_string (self, g_registered_type_info_get_type_name);
1259 _wrap_g_registered_type_info_get_type_init (PyGIBaseInfo *self)
1261 return _get_info_string (self, g_registered_type_info_get_type_init);
1265 _wrap_g_registered_type_info_get_g_type (PyGIBaseInfo *self)
1269 type = g_registered_type_info_get_g_type ( (GIRegisteredTypeInfo *) self->info);
1271 return pyg_type_wrapper_new (type);
1274 static PyMethodDef _PyGIRegisteredTypeInfo_methods[] = {
1275 { "get_type_name", (PyCFunction) _wrap_g_registered_type_info_get_type_name, METH_NOARGS },
1276 { "get_type_init", (PyCFunction) _wrap_g_registered_type_info_get_type_init, METH_NOARGS },
1277 { "get_g_type", (PyCFunction) _wrap_g_registered_type_info_get_g_type, METH_NOARGS },
1283 PYGLIB_DEFINE_TYPE ("StructInfo", PyGIStructInfo_Type, PyGIBaseInfo);
1286 _wrap_g_struct_info_get_fields (PyGIBaseInfo *self)
1288 return _make_infos_tuple (self, g_struct_info_get_n_fields, g_struct_info_get_field);
1292 _wrap_g_struct_info_get_methods (PyGIBaseInfo *self)
1294 return _make_infos_tuple (self, g_struct_info_get_n_methods, g_struct_info_get_method);
1298 _wrap_g_struct_info_get_size (PyGIBaseInfo *self)
1300 return PYGLIB_PyLong_FromSize_t (g_struct_info_get_size (self->info));
1304 _wrap_g_struct_info_get_alignment (PyGIBaseInfo *self)
1306 return PYGLIB_PyLong_FromSize_t (g_struct_info_get_alignment (self->info));
1310 _wrap_g_struct_info_is_gtype_struct (PyGIBaseInfo *self)
1312 return PyBool_FromLong (g_struct_info_is_gtype_struct (self->info));
1316 _wrap_g_struct_info_is_foreign (PyGIBaseInfo *self)
1318 return PyBool_FromLong (g_struct_info_is_foreign (self->info));
1321 static PyMethodDef _PyGIStructInfo_methods[] = {
1322 { "get_fields", (PyCFunction) _wrap_g_struct_info_get_fields, METH_NOARGS },
1323 { "get_methods", (PyCFunction) _wrap_g_struct_info_get_methods, METH_NOARGS },
1324 { "get_size", (PyCFunction) _wrap_g_struct_info_get_size, METH_NOARGS },
1325 { "get_alignment", (PyCFunction) _wrap_g_struct_info_get_alignment, METH_NOARGS },
1326 { "is_gtype_struct", (PyCFunction) _wrap_g_struct_info_is_gtype_struct, METH_NOARGS },
1327 { "is_foreign", (PyCFunction) _wrap_g_struct_info_is_foreign, METH_NOARGS },
1332 pygi_g_struct_info_is_simple (GIStructInfo *struct_info)
1335 gsize n_field_infos;
1340 n_field_infos = g_struct_info_get_n_fields (struct_info);
1342 for (i = 0; i < n_field_infos && is_simple; i++) {
1343 GIFieldInfo *field_info;
1344 GITypeInfo *field_type_info;
1345 GITypeTag field_type_tag;
1347 field_info = g_struct_info_get_field (struct_info, i);
1348 field_type_info = g_field_info_get_type (field_info);
1351 field_type_tag = g_type_info_get_tag (field_type_info);
1353 switch (field_type_tag) {
1354 case GI_TYPE_TAG_BOOLEAN:
1355 case GI_TYPE_TAG_INT8:
1356 case GI_TYPE_TAG_UINT8:
1357 case GI_TYPE_TAG_INT16:
1358 case GI_TYPE_TAG_UINT16:
1359 case GI_TYPE_TAG_INT32:
1360 case GI_TYPE_TAG_UINT32:
1361 case GI_TYPE_TAG_INT64:
1362 case GI_TYPE_TAG_UINT64:
1363 case GI_TYPE_TAG_FLOAT:
1364 case GI_TYPE_TAG_DOUBLE:
1365 case GI_TYPE_TAG_UNICHAR:
1366 if (g_type_info_is_pointer (field_type_info)) {
1370 case GI_TYPE_TAG_VOID:
1371 case GI_TYPE_TAG_GTYPE:
1372 case GI_TYPE_TAG_ERROR:
1373 case GI_TYPE_TAG_UTF8:
1374 case GI_TYPE_TAG_FILENAME:
1375 case GI_TYPE_TAG_ARRAY:
1376 case GI_TYPE_TAG_GLIST:
1377 case GI_TYPE_TAG_GSLIST:
1378 case GI_TYPE_TAG_GHASH:
1381 case GI_TYPE_TAG_INTERFACE:
1384 GIInfoType info_type;
1386 info = g_type_info_get_interface (field_type_info);
1387 info_type = g_base_info_get_type (info);
1389 switch (info_type) {
1390 case GI_INFO_TYPE_STRUCT:
1391 if (g_type_info_is_pointer (field_type_info)) {
1394 is_simple = pygi_g_struct_info_is_simple ( (GIStructInfo *) info);
1397 case GI_INFO_TYPE_UNION:
1401 case GI_INFO_TYPE_ENUM:
1402 case GI_INFO_TYPE_FLAGS:
1403 if (g_type_info_is_pointer (field_type_info)) {
1407 case GI_INFO_TYPE_BOXED:
1408 case GI_INFO_TYPE_OBJECT:
1409 case GI_INFO_TYPE_CALLBACK:
1410 case GI_INFO_TYPE_INTERFACE:
1413 case GI_INFO_TYPE_VFUNC:
1414 case GI_INFO_TYPE_INVALID:
1415 case GI_INFO_TYPE_FUNCTION:
1416 case GI_INFO_TYPE_CONSTANT:
1417 case GI_INFO_TYPE_VALUE:
1418 case GI_INFO_TYPE_SIGNAL:
1419 case GI_INFO_TYPE_PROPERTY:
1420 case GI_INFO_TYPE_FIELD:
1421 case GI_INFO_TYPE_ARG:
1422 case GI_INFO_TYPE_TYPE:
1423 case GI_INFO_TYPE_UNRESOLVED:
1425 g_assert_not_reached();
1429 g_base_info_unref (info);
1434 g_base_info_unref ( (GIBaseInfo *) field_type_info);
1435 g_base_info_unref ( (GIBaseInfo *) field_info);
1443 PYGLIB_DEFINE_TYPE ("gi.EnumInfo", PyGIEnumInfo_Type, PyGIBaseInfo);
1446 _wrap_g_enum_info_get_values (PyGIBaseInfo *self)
1448 return _make_infos_tuple (self, g_enum_info_get_n_values, g_enum_info_get_value);
1452 _wrap_g_enum_info_is_flags (PyGIBaseInfo *self)
1454 GIInfoType info_type = g_base_info_get_type ((GIBaseInfo *) self->info);
1456 if (info_type == GI_INFO_TYPE_ENUM) {
1458 } else if (info_type == GI_INFO_TYPE_FLAGS) {
1461 g_assert_not_reached();
1466 _wrap_g_enum_info_get_methods (PyGIBaseInfo *self)
1468 return _make_infos_tuple (self, g_enum_info_get_n_methods, g_enum_info_get_method);
1472 _wrap_g_enum_info_get_storage_type (PyGIBaseInfo *self)
1474 return PYGLIB_PyLong_FromLong (g_enum_info_get_storage_type ((GIBaseInfo *) self->info));
1477 static PyMethodDef _PyGIEnumInfo_methods[] = {
1478 { "get_values", (PyCFunction) _wrap_g_enum_info_get_values, METH_NOARGS },
1479 { "is_flags", (PyCFunction) _wrap_g_enum_info_is_flags, METH_NOARGS },
1480 { "get_methods", (PyCFunction) _wrap_g_enum_info_get_methods, METH_NOARGS },
1481 { "get_storage_type", (PyCFunction) _wrap_g_enum_info_get_storage_type, METH_NOARGS },
1487 PYGLIB_DEFINE_TYPE ("ObjectInfo", PyGIObjectInfo_Type, PyGIBaseInfo);
1490 _wrap_g_object_info_get_parent (PyGIBaseInfo *self)
1492 return _get_child_info (self, g_object_info_get_parent);
1496 _wrap_g_object_info_get_methods (PyGIBaseInfo *self)
1498 return _make_infos_tuple (self, g_object_info_get_n_methods, g_object_info_get_method);
1502 _wrap_g_object_info_find_method (PyGIBaseInfo *self, PyObject *py_name)
1504 return _get_child_info_by_name (self, py_name, g_object_info_find_method);
1508 _wrap_g_object_info_get_fields (PyGIBaseInfo *self)
1510 return _make_infos_tuple (self, g_object_info_get_n_fields, g_object_info_get_field);
1514 _wrap_g_object_info_get_properties (PyGIBaseInfo *self)
1516 return _make_infos_tuple (self, g_object_info_get_n_properties, g_object_info_get_property);
1520 _wrap_g_object_info_get_signals (PyGIBaseInfo *self)
1522 return _make_infos_tuple (self, g_object_info_get_n_signals, g_object_info_get_signal);
1526 _wrap_g_object_info_get_interfaces (PyGIBaseInfo *self)
1528 return _make_infos_tuple (self, g_object_info_get_n_interfaces, g_object_info_get_interface);
1532 _wrap_g_object_info_get_constants (PyGIBaseInfo *self)
1534 return _make_infos_tuple (self, g_object_info_get_n_constants, g_object_info_get_constant);
1538 _wrap_g_object_info_get_vfuncs (PyGIBaseInfo *self)
1540 return _make_infos_tuple (self, g_object_info_get_n_vfuncs, g_object_info_get_vfunc);
1544 _wrap_g_object_info_get_abstract (PyGIBaseInfo *self)
1546 gboolean is_abstract = g_object_info_get_abstract ( (GIObjectInfo*) self->info);
1547 return PyBool_FromLong (is_abstract);
1551 _wrap_g_object_info_get_type_name (PyGIBaseInfo *self)
1553 return _get_info_string (self, g_object_info_get_type_name);
1557 _wrap_g_object_info_get_type_init (PyGIBaseInfo *self)
1559 return _get_info_string (self, g_object_info_get_type_init);
1563 _wrap_g_object_info_get_fundamental (PyGIBaseInfo *self)
1565 return PyBool_FromLong (g_object_info_get_fundamental ( (GIObjectInfo*) self->info));
1569 _wrap_g_object_info_get_class_struct (PyGIBaseInfo *self)
1571 return _get_child_info (self, g_object_info_get_class_struct);
1575 _wrap_g_object_info_find_vfunc (PyGIBaseInfo *self, PyObject *py_name)
1577 return _get_child_info_by_name (self, py_name, g_object_info_find_vfunc);
1581 _wrap_g_object_info_get_unref_function (PyGIBaseInfo *self)
1583 return _get_info_string (self, g_object_info_get_unref_function);
1587 _wrap_g_object_info_get_ref_function (PyGIBaseInfo *self)
1589 return _get_info_string (self, g_object_info_get_ref_function);
1593 _wrap_g_object_info_get_set_value_function (PyGIBaseInfo *self)
1595 return _get_info_string (self, g_object_info_get_set_value_function);
1599 _wrap_g_object_info_get_get_value_function (PyGIBaseInfo *self)
1601 return _get_info_string (self, g_object_info_get_get_value_function);
1604 static PyMethodDef _PyGIObjectInfo_methods[] = {
1605 { "get_parent", (PyCFunction) _wrap_g_object_info_get_parent, METH_NOARGS },
1606 { "get_methods", (PyCFunction) _wrap_g_object_info_get_methods, METH_NOARGS },
1607 { "find_method", (PyCFunction) _wrap_g_object_info_find_method, METH_O },
1608 { "get_fields", (PyCFunction) _wrap_g_object_info_get_fields, METH_NOARGS },
1609 { "get_properties", (PyCFunction) _wrap_g_object_info_get_properties, METH_NOARGS },
1610 { "get_signals", (PyCFunction) _wrap_g_object_info_get_signals, METH_NOARGS },
1611 { "get_interfaces", (PyCFunction) _wrap_g_object_info_get_interfaces, METH_NOARGS },
1612 { "get_constants", (PyCFunction) _wrap_g_object_info_get_constants, METH_NOARGS },
1613 { "get_vfuncs", (PyCFunction) _wrap_g_object_info_get_vfuncs, METH_NOARGS },
1614 { "find_vfunc", (PyCFunction) _wrap_g_object_info_find_vfunc, METH_O },
1615 { "get_abstract", (PyCFunction) _wrap_g_object_info_get_abstract, METH_NOARGS },
1616 { "get_type_name", (PyCFunction) _wrap_g_object_info_get_type_name, METH_NOARGS },
1617 { "get_type_init", (PyCFunction) _wrap_g_object_info_get_type_init, METH_NOARGS },
1618 { "get_fundamental", (PyCFunction) _wrap_g_object_info_get_fundamental, METH_NOARGS },
1619 { "get_class_struct", (PyCFunction) _wrap_g_object_info_get_class_struct, METH_NOARGS },
1620 { "get_unref_function", (PyCFunction) _wrap_g_object_info_get_unref_function, METH_NOARGS },
1621 { "get_ref_function", (PyCFunction) _wrap_g_object_info_get_ref_function, METH_NOARGS },
1622 { "get_set_value_function", (PyCFunction) _wrap_g_object_info_get_set_value_function, METH_NOARGS },
1623 { "get_get_value_function", (PyCFunction) _wrap_g_object_info_get_get_value_function, METH_NOARGS },
1628 /* GIInterfaceInfo */
1629 PYGLIB_DEFINE_TYPE ("InterfaceInfo", PyGIInterfaceInfo_Type, PyGIBaseInfo);
1632 _wrap_g_interface_info_get_methods (PyGIBaseInfo *self)
1634 return _make_infos_tuple (self, g_interface_info_get_n_methods, g_interface_info_get_method);
1638 _wrap_g_interface_info_find_method (PyGIBaseInfo *self, PyObject *py_name)
1640 return _get_child_info_by_name (self, py_name, g_interface_info_find_method);
1644 _wrap_g_interface_info_get_constants (PyGIBaseInfo *self)
1646 return _make_infos_tuple (self, g_interface_info_get_n_constants, g_interface_info_get_constant);
1650 _wrap_g_interface_info_get_vfuncs (PyGIBaseInfo *self)
1652 return _make_infos_tuple (self, g_interface_info_get_n_vfuncs, g_interface_info_get_vfunc);
1656 _wrap_g_interface_info_find_vfunc (PyGIBaseInfo *self, PyObject *py_name)
1658 return _get_child_info_by_name (self, py_name, g_interface_info_find_vfunc);
1662 _wrap_g_interface_info_get_prerequisites (PyGIBaseInfo *self)
1664 return _make_infos_tuple (self, g_interface_info_get_n_prerequisites, g_interface_info_get_prerequisite);
1668 _wrap_g_interface_info_get_properties (PyGIBaseInfo *self)
1670 return _make_infos_tuple (self, g_interface_info_get_n_properties, g_interface_info_get_property);
1674 _wrap_g_interface_info_get_iface_struct (PyGIBaseInfo *self)
1676 return _get_child_info (self, g_interface_info_get_iface_struct);
1680 _wrap_g_interface_info_get_signals (PyGIBaseInfo *self)
1682 return _make_infos_tuple (self, g_interface_info_get_n_signals, g_interface_info_get_signal);
1686 _wrap_g_interface_info_find_signal (PyGIBaseInfo *self, PyObject *py_name)
1688 return _get_child_info_by_name (self, py_name, g_interface_info_find_signal);
1691 static PyMethodDef _PyGIInterfaceInfo_methods[] = {
1692 { "get_prerequisites", (PyCFunction) _wrap_g_interface_info_get_prerequisites, METH_NOARGS },
1693 { "get_properties", (PyCFunction) _wrap_g_interface_info_get_properties, METH_NOARGS },
1694 { "get_methods", (PyCFunction) _wrap_g_interface_info_get_methods, METH_NOARGS },
1695 { "find_method", (PyCFunction) _wrap_g_interface_info_find_method, METH_O },
1696 { "get_signals", (PyCFunction) _wrap_g_interface_info_get_signals, METH_NOARGS },
1697 { "find_signal", (PyCFunction) _wrap_g_interface_info_find_signal, METH_O },
1698 { "get_vfuncs", (PyCFunction) _wrap_g_interface_info_get_vfuncs, METH_NOARGS },
1699 { "get_constants", (PyCFunction) _wrap_g_interface_info_get_constants, METH_NOARGS },
1700 { "get_iface_struct", (PyCFunction) _wrap_g_interface_info_get_iface_struct, METH_NOARGS },
1701 { "find_vfunc", (PyCFunction) _wrap_g_interface_info_find_vfunc, METH_O },
1705 /* GIConstantInfo */
1706 PYGLIB_DEFINE_TYPE ("gi.ConstantInfo", PyGIConstantInfo_Type, PyGIBaseInfo);
1709 _wrap_g_constant_info_get_value (PyGIBaseInfo *self)
1711 GITypeInfo *type_info;
1712 GIArgument value = {0};
1714 gboolean free_array = FALSE;
1716 if (g_constant_info_get_value ( (GIConstantInfo *) self->info, &value) < 0) {
1717 PyErr_SetString (PyExc_RuntimeError, "unable to get value");
1721 type_info = g_constant_info_get_type ( (GIConstantInfo *) self->info);
1723 if (g_type_info_get_tag (type_info) == GI_TYPE_TAG_ARRAY) {
1724 value.v_pointer = _pygi_argument_to_array (&value, NULL, NULL, NULL,
1725 type_info, &free_array);
1728 py_value = _pygi_argument_to_object (&value, type_info, GI_TRANSFER_NOTHING);
1731 g_array_free (value.v_pointer, FALSE);
1734 g_constant_info_free_value (self->info, &value);
1735 g_base_info_unref ( (GIBaseInfo *) type_info);
1740 static PyMethodDef _PyGIConstantInfo_methods[] = {
1741 { "get_value", (PyCFunction) _wrap_g_constant_info_get_value, METH_NOARGS },
1746 PYGLIB_DEFINE_TYPE ("gi.ValueInfo", PyGIValueInfo_Type, PyGIBaseInfo);
1749 _wrap_g_value_info_get_value (PyGIBaseInfo *self)
1753 value = g_value_info_get_value ( (GIValueInfo *) self->info);
1755 return PYGLIB_PyLong_FromLong (value);
1759 static PyMethodDef _PyGIValueInfo_methods[] = {
1760 { "get_value", (PyCFunction) _wrap_g_value_info_get_value, METH_NOARGS },
1766 PYGLIB_DEFINE_TYPE ("gi.FieldInfo", PyGIFieldInfo_Type, PyGIBaseInfo);
1769 _struct_field_array_length_marshal (gsize length_index,
1770 void *container_ptr,
1771 void *struct_data_ptr)
1773 gssize array_len = -1;
1774 GIFieldInfo *array_len_field = NULL;
1775 GIArgument arg = {0};
1776 GIBaseInfo *container_info = (GIBaseInfo *)container_ptr;
1778 switch (g_base_info_get_type (container_info)) {
1779 case GI_INFO_TYPE_UNION:
1780 array_len_field = g_union_info_get_field ((GIUnionInfo *)container_info, length_index);
1782 case GI_INFO_TYPE_STRUCT:
1783 array_len_field = g_struct_info_get_field ((GIStructInfo *)container_info, length_index);
1785 case GI_INFO_TYPE_OBJECT:
1786 array_len_field = g_object_info_get_field ((GIObjectInfo *)container_info, length_index);
1789 /* Other types don't have fields. */
1790 g_assert_not_reached();
1793 if (array_len_field == NULL) {
1797 if (g_field_info_get_field (array_len_field, struct_data_ptr, &arg)) {
1798 GITypeInfo *array_len_type_info;
1800 array_len_type_info = g_field_info_get_type (array_len_field);
1801 if (array_len_type_info == NULL) {
1805 if (!pygi_argument_to_gssize (&arg,
1806 g_type_info_get_tag (array_len_type_info),
1811 g_base_info_unref (array_len_type_info);
1815 g_base_info_unref (array_len_field);
1820 _pygi_g_registered_type_info_check_object (GIRegisteredTypeInfo *info,
1821 gboolean is_instance,
1828 gchar *type_name_expected = NULL;
1829 GIInfoType interface_type;
1831 interface_type = g_base_info_get_type (info);
1832 if ( (interface_type == GI_INFO_TYPE_STRUCT) &&
1833 (g_struct_info_is_foreign ( (GIStructInfo*) info))) {
1834 /* TODO: Could we check is the correct foreign type? */
1838 g_type = g_registered_type_info_get_g_type (info);
1839 if (g_type != G_TYPE_NONE) {
1840 py_type = _pygi_type_get_from_g_type (g_type);
1842 py_type = _pygi_type_import_by_gi_info ( (GIBaseInfo *) info);
1845 if (py_type == NULL) {
1849 g_assert (PyType_Check (py_type));
1852 retval = PyObject_IsInstance (object, py_type);
1854 type_name_expected = _pygi_g_base_info_get_fullname (
1855 (GIBaseInfo *) info);
1858 if (!PyObject_Type (py_type)) {
1859 type_name_expected = "type";
1861 } else if (!PyType_IsSubtype ( (PyTypeObject *) object,
1862 (PyTypeObject *) py_type)) {
1863 type_name_expected = _pygi_g_base_info_get_fullname (
1864 (GIBaseInfo *) info);
1871 Py_DECREF (py_type);
1874 PyTypeObject *object_type;
1876 if (type_name_expected == NULL) {
1880 object_type = (PyTypeObject *) PyObject_Type (object);
1881 if (object_type == NULL) {
1885 PyErr_Format (PyExc_TypeError, "Must be %s, not %s",
1886 type_name_expected, object_type->tp_name);
1888 g_free (type_name_expected);
1895 _wrap_g_field_info_get_value (PyGIBaseInfo *self,
1899 GIBaseInfo *container_info;
1900 GIInfoType container_info_type;
1902 GITypeInfo *field_type_info;
1904 PyObject *py_value = NULL;
1905 gboolean free_array = FALSE;
1907 memset(&value, 0, sizeof(GIArgument));
1909 if (!PyArg_ParseTuple (args, "O:FieldInfo.get_value", &instance)) {
1913 container_info = g_base_info_get_container (self->info);
1914 g_assert (container_info != NULL);
1916 /* Check the instance. */
1917 if (!_pygi_g_registered_type_info_check_object ( (GIRegisteredTypeInfo *) container_info, TRUE, instance)) {
1918 _PyGI_ERROR_PREFIX ("argument 1: ");
1922 /* Get the pointer to the container. */
1923 container_info_type = g_base_info_get_type (container_info);
1924 switch (container_info_type) {
1925 case GI_INFO_TYPE_UNION:
1926 case GI_INFO_TYPE_STRUCT:
1927 pointer = pyg_boxed_get (instance, void);
1929 case GI_INFO_TYPE_OBJECT:
1930 pointer = pygobject_get (instance);
1933 /* Other types don't have fields. */
1934 g_assert_not_reached();
1937 /* Get the field's value. */
1938 field_type_info = g_field_info_get_type ( (GIFieldInfo *) self->info);
1940 /* A few types are not handled by g_field_info_get_field, so do it here. */
1941 if (!g_type_info_is_pointer (field_type_info)
1942 && g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_INTERFACE) {
1944 GIInfoType info_type;
1946 if (! (g_field_info_get_flags ( (GIFieldInfo *) self->info) & GI_FIELD_IS_READABLE)) {
1947 PyErr_SetString (PyExc_RuntimeError, "field is not readable");
1951 info = g_type_info_get_interface (field_type_info);
1953 info_type = g_base_info_get_type (info);
1955 g_base_info_unref (info);
1957 switch (info_type) {
1958 case GI_INFO_TYPE_UNION:
1959 PyErr_SetString (PyExc_NotImplementedError, "getting an union is not supported yet");
1961 case GI_INFO_TYPE_STRUCT:
1965 offset = g_field_info_get_offset ( (GIFieldInfo *) self->info);
1967 value.v_pointer = (char*) pointer + offset;
1969 goto argument_to_object;
1977 if (!g_field_info_get_field ( (GIFieldInfo *) self->info, pointer, &value)) {
1978 PyErr_SetString (PyExc_RuntimeError, "unable to get the value");
1982 if (g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_ARRAY) {
1983 value.v_pointer = _pygi_argument_to_array (&value,
1984 _struct_field_array_length_marshal,
1992 py_value = _pygi_argument_to_object (&value, field_type_info, GI_TRANSFER_NOTHING);
1995 g_array_free (value.v_pointer, FALSE);
1999 g_base_info_unref ( (GIBaseInfo *) field_type_info);
2005 _wrap_g_field_info_set_value (PyGIBaseInfo *self,
2010 GIBaseInfo *container_info;
2011 GIInfoType container_info_type;
2013 GITypeInfo *field_type_info;
2015 PyObject *retval = NULL;
2017 if (!PyArg_ParseTuple (args, "OO:FieldInfo.set_value", &instance, &py_value)) {
2021 container_info = g_base_info_get_container (self->info);
2022 g_assert (container_info != NULL);
2024 /* Check the instance. */
2025 if (!_pygi_g_registered_type_info_check_object ( (GIRegisteredTypeInfo *) container_info, TRUE, instance)) {
2026 _PyGI_ERROR_PREFIX ("argument 1: ");
2030 /* Get the pointer to the container. */
2031 container_info_type = g_base_info_get_type (container_info);
2032 switch (container_info_type) {
2033 case GI_INFO_TYPE_UNION:
2034 case GI_INFO_TYPE_STRUCT:
2035 pointer = pyg_boxed_get (instance, void);
2037 case GI_INFO_TYPE_OBJECT:
2038 pointer = pygobject_get (instance);
2041 /* Other types don't have fields. */
2042 g_assert_not_reached();
2045 field_type_info = g_field_info_get_type ( (GIFieldInfo *) self->info);
2047 /* Set the field's value. */
2048 /* A few types are not handled by g_field_info_set_field, so do it here. */
2049 if (!g_type_info_is_pointer (field_type_info)
2050 && g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_INTERFACE) {
2052 GIInfoType info_type;
2054 if (! (g_field_info_get_flags ( (GIFieldInfo *) self->info) & GI_FIELD_IS_WRITABLE)) {
2055 PyErr_SetString (PyExc_RuntimeError, "field is not writable");
2059 info = g_type_info_get_interface (field_type_info);
2061 info_type = g_base_info_get_type (info);
2063 switch (info_type) {
2064 case GI_INFO_TYPE_UNION:
2065 PyErr_SetString (PyExc_NotImplementedError, "setting an union is not supported yet");
2067 case GI_INFO_TYPE_STRUCT:
2073 is_simple = pygi_g_struct_info_is_simple ( (GIStructInfo *) info);
2076 PyErr_SetString (PyExc_TypeError,
2077 "cannot set a structure which has no well-defined ownership transfer rules");
2078 g_base_info_unref (info);
2082 value = _pygi_argument_from_object (py_value, field_type_info, GI_TRANSFER_NOTHING);
2083 if (PyErr_Occurred()) {
2084 g_base_info_unref (info);
2088 offset = g_field_info_get_offset ( (GIFieldInfo *) self->info);
2089 size = g_struct_info_get_size ( (GIStructInfo *) info);
2090 g_assert (size > 0);
2092 g_memmove ((char*) pointer + offset, value.v_pointer, size);
2094 g_base_info_unref (info);
2104 g_base_info_unref (info);
2105 } else if (g_type_info_is_pointer (field_type_info)
2106 && (g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_VOID
2107 || g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_UTF8)) {
2109 value = _pygi_argument_from_object (py_value, field_type_info, GI_TRANSFER_NOTHING);
2110 if (PyErr_Occurred()) {
2114 offset = g_field_info_get_offset ((GIFieldInfo *) self->info);
2115 G_STRUCT_MEMBER (gpointer, pointer, offset) = (gpointer)value.v_pointer;
2121 value = _pygi_argument_from_object (py_value, field_type_info, GI_TRANSFER_EVERYTHING);
2122 if (PyErr_Occurred()) {
2126 if (!g_field_info_set_field ( (GIFieldInfo *) self->info, pointer, &value)) {
2127 _pygi_argument_release (&value, field_type_info, GI_TRANSFER_NOTHING, GI_DIRECTION_IN);
2128 PyErr_SetString (PyExc_RuntimeError, "unable to set value for field");
2135 g_base_info_unref ( (GIBaseInfo *) field_type_info);
2137 Py_XINCREF (retval);
2142 _wrap_g_field_info_get_flags (PyGIBaseInfo *self)
2144 return PYGLIB_PyLong_FromLong (g_field_info_get_flags (self->info));
2148 _wrap_g_field_info_get_size (PyGIBaseInfo *self)
2150 return PYGLIB_PyLong_FromLong (g_field_info_get_size (self->info));
2154 _wrap_g_field_info_get_offset (PyGIBaseInfo *self)
2156 return PYGLIB_PyLong_FromLong (g_field_info_get_offset (self->info));
2160 _wrap_g_field_info_get_type (PyGIBaseInfo *self)
2162 return _get_child_info (self, g_field_info_get_type);
2165 static PyMethodDef _PyGIFieldInfo_methods[] = {
2166 { "get_value", (PyCFunction) _wrap_g_field_info_get_value, METH_VARARGS },
2167 { "set_value", (PyCFunction) _wrap_g_field_info_set_value, METH_VARARGS },
2168 { "get_flags", (PyCFunction) _wrap_g_field_info_get_flags, METH_VARARGS },
2169 { "get_size", (PyCFunction) _wrap_g_field_info_get_size, METH_VARARGS },
2170 { "get_offset", (PyCFunction) _wrap_g_field_info_get_offset, METH_VARARGS },
2171 { "get_type", (PyCFunction) _wrap_g_field_info_get_type, METH_VARARGS },
2176 /* GIUnresolvedInfo */
2177 PYGLIB_DEFINE_TYPE ("gi.UnresolvedInfo", PyGIUnresolvedInfo_Type, PyGIBaseInfo);
2179 static PyMethodDef _PyGIUnresolvedInfo_methods[] = {
2184 PYGLIB_DEFINE_TYPE ("gi.VFuncInfo", PyGIVFuncInfo_Type, PyGICallableInfo);
2187 _wrap_g_vfunc_info_get_flags (PyGIBaseInfo *self)
2189 return PYGLIB_PyLong_FromLong (g_vfunc_info_get_flags ((GIVFuncInfo *) self->info));
2193 _wrap_g_vfunc_info_get_offset (PyGIBaseInfo *self)
2195 return PYGLIB_PyLong_FromLong (g_vfunc_info_get_offset ((GIVFuncInfo *) self->info));
2199 _wrap_g_vfunc_info_get_signal (PyGIBaseInfo *self)
2201 return _get_child_info (self, g_vfunc_info_get_signal);
2205 _wrap_g_vfunc_info_get_invoker (PyGIBaseInfo *self)
2207 return _get_child_info (self, g_vfunc_info_get_invoker);
2210 static PyMethodDef _PyGIVFuncInfo_methods[] = {
2211 { "get_flags", (PyCFunction) _wrap_g_vfunc_info_get_flags, METH_NOARGS },
2212 { "get_offset", (PyCFunction) _wrap_g_vfunc_info_get_offset, METH_NOARGS },
2213 { "get_signal", (PyCFunction) _wrap_g_vfunc_info_get_signal, METH_NOARGS },
2214 { "get_invoker", (PyCFunction) _wrap_g_vfunc_info_get_invoker, METH_NOARGS },
2220 PYGLIB_DEFINE_TYPE ("gi.UnionInfo", PyGIUnionInfo_Type, PyGIBaseInfo);
2223 _wrap_g_union_info_get_fields (PyGIBaseInfo *self)
2225 return _make_infos_tuple (self, g_union_info_get_n_fields, g_union_info_get_field);
2229 _wrap_g_union_info_get_methods (PyGIBaseInfo *self)
2231 return _make_infos_tuple (self, g_union_info_get_n_methods, g_union_info_get_method);
2235 _wrap_g_union_info_get_size (PyGIBaseInfo *self)
2237 return PYGLIB_PyLong_FromSize_t (g_union_info_get_size (self->info));
2240 static PyMethodDef _PyGIUnionInfo_methods[] = {
2241 { "get_fields", (PyCFunction) _wrap_g_union_info_get_fields, METH_NOARGS },
2242 { "get_methods", (PyCFunction) _wrap_g_union_info_get_methods, METH_NOARGS },
2243 { "get_size", (PyCFunction) _wrap_g_union_info_get_size, METH_NOARGS },
2250 _pygi_g_base_info_get_fullname (GIBaseInfo *info)
2252 GIBaseInfo *container_info;
2255 container_info = g_base_info_get_container (info);
2256 if (container_info != NULL) {
2257 fullname = g_strdup_printf ("%s.%s.%s",
2258 g_base_info_get_namespace (container_info),
2259 _safe_base_info_get_name (container_info),
2260 _safe_base_info_get_name (info));
2262 fullname = g_strdup_printf ("%s.%s",
2263 g_base_info_get_namespace (info),
2264 _safe_base_info_get_name (info));
2267 if (fullname == NULL) {
2276 _pygi_info_register_types (PyObject *m)
2278 #define _PyGI_REGISTER_TYPE(m, type, cname, base) \
2279 Py_TYPE(&type) = &PyType_Type; \
2280 type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE); \
2281 type.tp_weaklistoffset = offsetof(PyGIBaseInfo, inst_weakreflist); \
2282 type.tp_methods = _PyGI##cname##_methods; \
2283 type.tp_base = &base; \
2284 if (PyType_Ready(&type)) \
2286 if (PyModule_AddObject(m, #cname, (PyObject *)&type)) \
2289 Py_TYPE(&PyGIBaseInfo_Type) = &PyType_Type;
2291 PyGIBaseInfo_Type.tp_dealloc = (destructor) _base_info_dealloc;
2292 PyGIBaseInfo_Type.tp_repr = (reprfunc) _base_info_repr;
2293 PyGIBaseInfo_Type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
2294 PyGIBaseInfo_Type.tp_weaklistoffset = offsetof(PyGIBaseInfo, inst_weakreflist);
2295 PyGIBaseInfo_Type.tp_methods = _PyGIBaseInfo_methods;
2296 PyGIBaseInfo_Type.tp_richcompare = (richcmpfunc)_base_info_richcompare;
2297 PyGIBaseInfo_Type.tp_getset = _base_info_getsets;
2298 PyGIBaseInfo_Type.tp_getattro = (getattrofunc) _base_info_getattro;
2300 if (PyType_Ready(&PyGIBaseInfo_Type))
2302 if (PyModule_AddObject(m, "BaseInfo", (PyObject *)&PyGIBaseInfo_Type))
2305 _PyGI_REGISTER_TYPE (m, PyGICallableInfo_Type, CallableInfo,
2307 PyGICallableInfo_Type.tp_call = (ternaryfunc) _callable_info_call;
2308 PyGICallableInfo_Type.tp_dealloc = (destructor) _callable_info_dealloc;
2310 _PyGI_REGISTER_TYPE (m, PyGIFunctionInfo_Type, FunctionInfo,
2311 PyGICallableInfo_Type);
2312 PyGIFunctionInfo_Type.tp_call = (ternaryfunc) _function_info_call;
2313 PyGIFunctionInfo_Type.tp_descr_get = (descrgetfunc) _function_info_descr_get;
2315 _PyGI_REGISTER_TYPE (m, PyGIVFuncInfo_Type, VFuncInfo,
2316 PyGICallableInfo_Type);
2317 PyGIVFuncInfo_Type.tp_descr_get = (descrgetfunc) _vfunc_info_descr_get;
2319 _PyGI_REGISTER_TYPE (m, PyGISignalInfo_Type, SignalInfo,
2320 PyGICallableInfo_Type);
2322 _PyGI_REGISTER_TYPE (m, PyGIUnresolvedInfo_Type, UnresolvedInfo,
2324 _PyGI_REGISTER_TYPE (m, PyGICallbackInfo_Type, CallbackInfo,
2325 PyGICallableInfo_Type);
2326 _PyGI_REGISTER_TYPE (m, PyGIRegisteredTypeInfo_Type, RegisteredTypeInfo,
2328 _PyGI_REGISTER_TYPE (m, PyGIStructInfo_Type, StructInfo,
2329 PyGIRegisteredTypeInfo_Type);
2330 _PyGI_REGISTER_TYPE (m, PyGIEnumInfo_Type, EnumInfo,
2331 PyGIRegisteredTypeInfo_Type);
2332 _PyGI_REGISTER_TYPE (m, PyGIObjectInfo_Type, ObjectInfo,
2333 PyGIRegisteredTypeInfo_Type);
2334 _PyGI_REGISTER_TYPE (m, PyGIInterfaceInfo_Type, InterfaceInfo,
2335 PyGIRegisteredTypeInfo_Type);
2336 _PyGI_REGISTER_TYPE (m, PyGIConstantInfo_Type, ConstantInfo,
2338 _PyGI_REGISTER_TYPE (m, PyGIValueInfo_Type, ValueInfo,
2340 _PyGI_REGISTER_TYPE (m, PyGIFieldInfo_Type, FieldInfo,
2342 _PyGI_REGISTER_TYPE (m, PyGIUnionInfo_Type, UnionInfo,
2343 PyGIRegisteredTypeInfo_Type);
2344 _PyGI_REGISTER_TYPE (m, PyGIErrorDomainInfo_Type, ErrorDomainInfo,
2346 _PyGI_REGISTER_TYPE (m, PyGIPropertyInfo_Type, PropertyInfo,
2348 _PyGI_REGISTER_TYPE (m, PyGIArgInfo_Type, ArgInfo,
2350 _PyGI_REGISTER_TYPE (m, PyGITypeInfo_Type, TypeInfo,
2353 #undef _PyGI_REGISTER_TYPE
2355 #define _PyGI_ENUM_BEGIN(name) \
2357 const char *__enum_name = #name; \
2358 PyObject *__enum_value = NULL; \
2359 PyObject *__new_enum_cls = NULL; \
2360 PyObject *__enum_instance_dict = PyDict_New(); \
2361 PyObject *__module_name = PyObject_GetAttrString (m, "__name__"); \
2362 PyDict_SetItemString (__enum_instance_dict, "__module__", __module_name); \
2363 Py_DECREF (__module_name);
2365 #define _PyGI_ENUM_ADD_VALUE(prefix, name) \
2366 __enum_value = PYGLIB_PyLong_FromLong (prefix##_##name); \
2367 if (PyDict_SetItemString(__enum_instance_dict, #name, __enum_value)) { \
2368 Py_DECREF (__enum_instance_dict); \
2369 Py_DECREF (__enum_value); \
2372 Py_DECREF (__enum_value);
2374 #define _PyGI_ENUM_END \
2375 __new_enum_cls = PyObject_CallFunction ((PyObject *)&PyType_Type, "s(O)O", \
2376 __enum_name, (PyObject *)&PyType_Type, \
2377 __enum_instance_dict); \
2378 Py_DECREF (__enum_instance_dict); \
2379 PyModule_AddObject (m, __enum_name, __new_enum_cls); /* steals ref */ \
2384 _PyGI_ENUM_BEGIN (Direction)
2385 _PyGI_ENUM_ADD_VALUE (GI_DIRECTION, IN)
2386 _PyGI_ENUM_ADD_VALUE (GI_DIRECTION, OUT)
2387 _PyGI_ENUM_ADD_VALUE (GI_DIRECTION, INOUT)
2392 _PyGI_ENUM_BEGIN (Transfer)
2393 _PyGI_ENUM_ADD_VALUE (GI_TRANSFER, NOTHING)
2394 _PyGI_ENUM_ADD_VALUE (GI_TRANSFER, CONTAINER)
2395 _PyGI_ENUM_ADD_VALUE (GI_TRANSFER, EVERYTHING)
2399 _PyGI_ENUM_BEGIN (ArrayType)
2400 _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE, C)
2401 _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE, ARRAY)
2402 _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE, PTR_ARRAY)
2403 _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE, BYTE_ARRAY)
2407 _PyGI_ENUM_BEGIN (ScopeType)
2408 _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE, INVALID)
2409 _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE, CALL)
2410 _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE, ASYNC)
2411 _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE, NOTIFIED)
2414 /* GIVFuncInfoFlags */
2415 _PyGI_ENUM_BEGIN (VFuncInfoFlags)
2416 _PyGI_ENUM_ADD_VALUE (GI_VFUNC_MUST, CHAIN_UP)
2417 _PyGI_ENUM_ADD_VALUE (GI_VFUNC_MUST, OVERRIDE)
2418 _PyGI_ENUM_ADD_VALUE (GI_VFUNC_MUST, NOT_OVERRIDE)
2421 /* GIFieldInfoFlags */
2422 _PyGI_ENUM_BEGIN (FieldInfoFlags)
2423 _PyGI_ENUM_ADD_VALUE (GI_FIELD, IS_READABLE)
2424 _PyGI_ENUM_ADD_VALUE (GI_FIELD, IS_WRITABLE)
2427 /* GIFunctionInfoFlags */
2428 _PyGI_ENUM_BEGIN (FunctionInfoFlags)
2429 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, IS_METHOD)
2430 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, IS_CONSTRUCTOR)
2431 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, IS_GETTER)
2432 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, IS_SETTER)
2433 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, WRAPS_VFUNC)
2434 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, THROWS)
2438 _PyGI_ENUM_BEGIN (TypeTag)
2440 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, VOID)
2441 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, BOOLEAN)
2442 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, INT8)
2443 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UINT8)
2444 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, INT16)
2445 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UINT16)
2446 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, INT32)
2447 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UINT32)
2448 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, INT64)
2449 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UINT64)
2450 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, FLOAT)
2451 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, DOUBLE)
2452 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, GTYPE)
2453 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UTF8)
2454 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, FILENAME)
2456 /* Non-basic types; compare with G_TYPE_TAG_IS_BASIC */
2457 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, ARRAY)
2458 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, INTERFACE)
2459 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, GLIST)
2460 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, GSLIST)
2461 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, GHASH)
2462 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, ERROR)
2464 /* Another basic type */
2465 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UNICHAR)
2469 _PyGI_ENUM_BEGIN (InfoType)
2470 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, INVALID)
2471 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, FUNCTION)
2472 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, CALLBACK)
2473 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, STRUCT)
2474 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, BOXED)
2475 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, ENUM)
2476 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, FLAGS)
2477 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, OBJECT)
2478 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, INTERFACE)
2479 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, CONSTANT)
2480 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, INVALID_0)
2481 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, UNION)
2482 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, VALUE)
2483 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, SIGNAL)
2484 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, VFUNC)
2485 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, PROPERTY)
2486 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, FIELD)
2487 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, ARG)
2488 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, TYPE)
2489 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, UNRESOLVED)
2492 #undef _PyGI_ENUM_BEGIN
2493 #undef _PyGI_ENUM_ADD_VALUE
2494 #undef _PyGI_ENUM_END