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, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
25 #include "pygi-private.h"
26 #include "pygi-cache.h"
28 #include <pygobject.h>
29 #include <pyglib-python-compat.h>
32 /* _generate_doc_string
34 * C wrapper to call Python implemented "gi.docstring.generate_doc_string"
37 _generate_doc_string(PyGIBaseInfo *self)
39 static PyObject *_py_generate_doc_string = NULL;
41 if (_py_generate_doc_string == NULL) {
42 PyObject *mod = PyImport_ImportModule ("gi.docstring");
46 _py_generate_doc_string = PyObject_GetAttrString (mod, "generate_doc_string");
47 if (_py_generate_doc_string == NULL) {
54 return PyObject_CallFunctionObjArgs (_py_generate_doc_string, self, NULL);
58 _get_info_string (PyGIBaseInfo *self,
59 const gchar* (*get_info_string)(GIBaseInfo*))
61 const gchar *value = get_info_string ((GIBaseInfo*)self->info);
65 return PYGLIB_PyUnicode_FromString (value);
69 _get_child_info (PyGIBaseInfo *self,
70 GIBaseInfo* (*get_child_info)(GIBaseInfo*))
75 info = get_child_info ((GIBaseInfo*)self->info);
80 py_info = _pygi_info_new (info);
81 g_base_info_unref (info);
87 _get_child_info_by_name (PyGIBaseInfo *self, PyObject *py_name,
88 GIBaseInfo* (*get_child_info_by_name)(GIBaseInfo*, const gchar*))
94 if (!PYGLIB_PyUnicode_Check (py_name)) {
95 PyErr_SetString (PyExc_TypeError, "expected string name");
99 name = PYGLIB_PyUnicode_AsString (py_name);
100 info = get_child_info_by_name ((GIObjectInfo*)self->info, name);
105 py_info = _pygi_info_new (info);
106 g_base_info_unref (info);
113 * Build a tuple from the common API pattern in GI of having a
114 * function which returns a count and an indexed GIBaseInfo
115 * in the range of 0 to count;
118 _make_infos_tuple (PyGIBaseInfo *self,
119 gint (*get_n_infos)(GIBaseInfo*),
120 GIBaseInfo* (*get_info)(GIBaseInfo*, gint))
126 n_infos = get_n_infos ( (GIBaseInfo *) self->info);
128 infos = PyTuple_New (n_infos);
133 for (i = 0; i < n_infos; i++) {
137 info = (GIBaseInfo *) get_info (self->info, i);
138 g_assert (info != NULL);
140 py_info = _pygi_info_new (info);
142 g_base_info_unref (info);
144 if (py_info == NULL) {
149 PyTuple_SET_ITEM (infos, i, py_info);
158 /* We need to be careful about calling g_base_info_get_name because
159 * calling it with a GI_INFO_TYPE_TYPE will crash.
160 * See: https://bugzilla.gnome.org/show_bug.cgi?id=709456
163 _safe_base_info_get_name (GIBaseInfo *info)
165 if (g_base_info_get_type (info) == GI_INFO_TYPE_TYPE) {
166 return "type_type_instance";
168 return g_base_info_get_name (info);
173 _base_info_dealloc (PyGIBaseInfo *self)
175 if (self->inst_weakreflist != NULL)
176 PyObject_ClearWeakRefs ( (PyObject *) self);
178 g_base_info_unref (self->info);
180 _pygi_callable_cache_free(self->cache);
182 Py_TYPE( (PyObject *) self)->tp_free ( (PyObject *) self);
186 _base_info_repr (PyGIBaseInfo *self)
189 return PYGLIB_PyUnicode_FromFormat ("<%s object (%s) at 0x%p>",
190 Py_TYPE( (PyObject *) self)->tp_name,
191 _safe_base_info_get_name (self->info),
196 _wrap_g_base_info_equal (PyGIBaseInfo *self, PyObject *other)
198 GIBaseInfo *other_info;
200 if (!PyObject_TypeCheck (other, &PyGIBaseInfo_Type)) {
201 Py_INCREF (Py_NotImplemented);
202 return Py_NotImplemented;
205 other_info = ((PyGIBaseInfo *)other)->info;
206 if (g_base_info_equal (self->info, other_info)) {
214 _base_info_richcompare (PyGIBaseInfo *self, PyObject *other, int op)
220 return _wrap_g_base_info_equal (self, other);
222 res = _wrap_g_base_info_equal (self, other);
223 if (res == Py_True) {
231 res = Py_NotImplemented;
238 PYGLIB_DEFINE_TYPE("gi.BaseInfo", PyGIBaseInfo_Type, PyGIBaseInfo);
241 _pygi_is_python_keyword (const gchar *name)
243 /* It may be better to use keyword.iskeyword(); keep in sync with
244 * python -c 'import keyword; print(keyword.kwlist)' */
245 #if PY_VERSION_HEX < 0x03000000
247 static const gchar* keywords[] = {"and", "as", "assert", "break", "class",
248 "continue", "def", "del", "elif", "else", "except", "exec", "finally",
249 "for", "from", "global", "if", "import", "in", "is", "lambda", "not",
250 "or", "pass", "print", "raise", "return", "try", "while", "with",
252 #elif PY_VERSION_HEX < 0x04000000
253 /* Python 3.x; note that we explicitly keep "print"; it is not a keyword
254 * any more, but we do not want to break API between Python versions */
255 static const gchar* keywords[] = {"False", "None", "True", "and", "as",
256 "assert", "break", "class", "continue", "def", "del", "elif", "else",
257 "except", "finally", "for", "from", "global", "if", "import", "in",
258 "is", "lambda", "nonlocal", "not", "or", "pass", "raise", "return",
259 "try", "while", "with", "yield",
262 #error Need keyword list for this major Python version
267 for (i = keywords; *i != NULL; ++i) {
268 if (strcmp (name, *i) == 0) {
277 _wrap_g_base_info_get_type (PyGIBaseInfo *self)
279 return PYGLIB_PyLong_FromLong (g_base_info_get_type (self->info));
283 _wrap_g_base_info_get_name (PyGIBaseInfo *self)
287 name = _safe_base_info_get_name (self->info);
289 /* escape keywords */
290 if (_pygi_is_python_keyword (name)) {
291 gchar *escaped = g_strconcat (name, "_", NULL);
292 PyObject *obj = PYGLIB_PyUnicode_FromString (escaped);
297 return PYGLIB_PyUnicode_FromString (name);
301 _wrap_g_base_info_get_name_unescaped (PyGIBaseInfo *self)
303 return _get_info_string (self, _safe_base_info_get_name);
307 _wrap_g_base_info_get_namespace (PyGIBaseInfo *self)
309 return _get_info_string (self, g_base_info_get_namespace);
313 _wrap_g_base_info_is_deprecated (PyGIBaseInfo *self)
315 if (g_base_info_is_deprecated (self->info))
322 _wrap_g_base_info_get_attribute (PyGIBaseInfo *self, PyObject *arg)
327 if (!PYGLIB_PyUnicode_Check (arg)) {
328 PyErr_SetString (PyExc_TypeError, "expected string name");
332 name = PYGLIB_PyUnicode_AsString (arg);
333 value = g_base_info_get_attribute (self->info, name);
337 return PYGLIB_PyUnicode_FromString (value);
341 _wrap_g_base_info_get_container (PyGIBaseInfo *self)
343 /* Note: don't use _get_child_info because g_base_info_get_container
344 * is marked as [transfer none] and therefore returns a borrowed ref.
348 info = g_base_info_get_container (self->info);
354 return _pygi_info_new (info);
358 static PyMethodDef _PyGIBaseInfo_methods[] = {
359 { "get_type", (PyCFunction) _wrap_g_base_info_get_type, METH_NOARGS },
360 { "get_name", (PyCFunction) _wrap_g_base_info_get_name, METH_NOARGS },
361 { "get_name_unescaped", (PyCFunction) _wrap_g_base_info_get_name_unescaped, METH_NOARGS },
362 { "get_namespace", (PyCFunction) _wrap_g_base_info_get_namespace, METH_NOARGS },
363 { "is_deprecated", (PyCFunction) _wrap_g_base_info_is_deprecated, METH_NOARGS },
364 { "get_attribute", (PyCFunction) _wrap_g_base_info_get_attribute, METH_O },
365 { "get_container", (PyCFunction) _wrap_g_base_info_get_container, METH_NOARGS },
366 { "equal", (PyCFunction) _wrap_g_base_info_equal, METH_O },
370 /* _base_info_getattro:
372 * The usage of __getattr__ is needed because the get/set method table
373 * does not work for __doc__.
376 _base_info_getattro(PyGIBaseInfo *self, PyObject *name)
380 static PyObject *docstr;
381 if (docstr == NULL) {
382 docstr= PYGLIB_PyUnicode_InternFromString("__doc__");
388 PYGLIB_PyUnicode_InternInPlace (&name);
390 if (name == docstr) {
391 result = _generate_doc_string (self);
393 result = PyObject_GenericGetAttr ((PyObject *)self, name);
401 _base_info_attr_name(PyGIBaseInfo *self, void *closure)
403 return _wrap_g_base_info_get_name (self);
407 _base_info_attr_module(PyGIBaseInfo *self, void *closure)
409 return PYGLIB_PyUnicode_FromFormat ("gi.repository.%s",
410 g_base_info_get_namespace (self->info));
413 static PyGetSetDef _base_info_getsets[] = {
414 { "__name__", (getter)_base_info_attr_name, (setter)0, "Name", NULL},
415 { "__module__", (getter)_base_info_attr_module, (setter)0, "Module name", NULL},
420 _pygi_info_new (GIBaseInfo *info)
422 GIInfoType info_type;
423 PyTypeObject *type = NULL;
426 info_type = g_base_info_get_type (info);
430 case GI_INFO_TYPE_INVALID:
431 PyErr_SetString (PyExc_RuntimeError, "Invalid info type");
433 case GI_INFO_TYPE_FUNCTION:
434 type = &PyGIFunctionInfo_Type;
436 case GI_INFO_TYPE_CALLBACK:
437 type = &PyGICallbackInfo_Type;
439 case GI_INFO_TYPE_STRUCT:
440 case GI_INFO_TYPE_BOXED:
441 type = &PyGIStructInfo_Type;
443 case GI_INFO_TYPE_ENUM:
444 case GI_INFO_TYPE_FLAGS:
445 type = &PyGIEnumInfo_Type;
447 case GI_INFO_TYPE_OBJECT:
448 type = &PyGIObjectInfo_Type;
450 case GI_INFO_TYPE_INTERFACE:
451 type = &PyGIInterfaceInfo_Type;
453 case GI_INFO_TYPE_CONSTANT:
454 type = &PyGIConstantInfo_Type;
456 case GI_INFO_TYPE_UNION:
457 type = &PyGIUnionInfo_Type;
459 case GI_INFO_TYPE_VALUE:
460 type = &PyGIValueInfo_Type;
462 case GI_INFO_TYPE_SIGNAL:
463 type = &PyGISignalInfo_Type;
465 case GI_INFO_TYPE_VFUNC:
466 type = &PyGIVFuncInfo_Type;
468 case GI_INFO_TYPE_PROPERTY:
469 type = &PyGIPropertyInfo_Type;
471 case GI_INFO_TYPE_FIELD:
472 type = &PyGIFieldInfo_Type;
474 case GI_INFO_TYPE_ARG:
475 type = &PyGIArgInfo_Type;
477 case GI_INFO_TYPE_TYPE:
478 type = &PyGITypeInfo_Type;
480 case GI_INFO_TYPE_UNRESOLVED:
481 type = &PyGIUnresolvedInfo_Type;
484 g_assert_not_reached();
488 self = (PyGIBaseInfo *) type->tp_alloc (type, 0);
493 self->info = g_base_info_ref (info);
494 self->inst_weakreflist = NULL;
497 return (PyObject *) self;
501 _pygi_object_get_gi_info (PyObject *object,
505 GIBaseInfo *info = NULL;
507 py_info = PyObject_GetAttrString (object, "__info__");
508 if (py_info == NULL) {
511 if (!PyObject_TypeCheck (py_info, type)) {
512 PyErr_Format (PyExc_TypeError, "attribute '__info__' must be %s, not %s",
513 type->tp_name, Py_TYPE(&py_info)->tp_name);
517 info = ( (PyGIBaseInfo *) py_info)->info;
518 g_base_info_ref (info);
528 PYGLIB_DEFINE_TYPE ("gi.CallableInfo", PyGICallableInfo_Type, PyGICallableInfo);
530 /* _callable_info_call:
532 * Shared wrapper for invoke which can be bound (instance method or class constructor)
533 * or unbound (function or static method).
536 _callable_info_call (PyGICallableInfo *self, PyObject *args, PyObject *kwargs)
538 /* Insert the bound arg at the beginning of the invoke method args. */
539 if (self->py_bound_arg) {
542 Py_ssize_t argcount = PyTuple_Size (args);
543 PyObject *newargs = PyTuple_New (argcount + 1);
547 Py_INCREF (self->py_bound_arg);
548 PyTuple_SET_ITEM (newargs, 0, self->py_bound_arg);
550 for (i = 0; i < argcount; i++) {
551 PyObject *v = PyTuple_GET_ITEM (args, i);
553 PyTuple_SET_ITEM (newargs, i+1, v);
556 /* Invoke with the original GI info struct this wrapper was based upon.
557 * This is necessary to maintain the same cache for all bound versions.
559 result = _wrap_g_callable_info_invoke ((PyGIBaseInfo *)self->py_unbound_info,
565 /* We should never have an unbound info when calling when calling invoke
566 * at this point because the descriptor implementation on sub-classes
567 * should return "self" not a copy when there is no bound arg.
569 g_assert (self->py_unbound_info == NULL);
570 return _wrap_g_callable_info_invoke ((PyGIBaseInfo *)self, args, kwargs);
575 /* _function_info_call:
577 * Specialization of _callable_info_call for GIFunctionInfo which
578 * handles constructor error conditions.
581 _function_info_call (PyGICallableInfo *self, PyObject *args, PyObject *kwargs)
583 if (self->py_bound_arg) {
584 GIFunctionInfoFlags flags;
586 /* Ensure constructors are only called as class methods on the class
587 * implementing the constructor and not on sub-classes.
589 flags = g_function_info_get_flags ( (GIFunctionInfo*) self->base.info);
590 if (flags & GI_FUNCTION_IS_CONSTRUCTOR) {
591 PyObject *py_str_name;
592 const gchar *str_name;
593 GIBaseInfo *container_info = g_base_info_get_container (self->base.info);
594 g_assert (container_info != NULL);
596 py_str_name = PyObject_GetAttrString (self->py_bound_arg, "__name__");
597 if (py_str_name == NULL)
600 if (PyUnicode_Check (py_str_name) ) {
601 PyObject *tmp = PyUnicode_AsUTF8String (py_str_name);
602 Py_DECREF (py_str_name);
606 #if PY_VERSION_HEX < 0x03000000
607 str_name = PyString_AsString (py_str_name);
609 str_name = PyBytes_AsString (py_str_name);
612 if (strcmp (str_name, _safe_base_info_get_name (container_info))) {
613 PyErr_Format (PyExc_TypeError,
614 "%s constructor cannot be used to create instances of "
616 _safe_base_info_get_name (container_info),
618 Py_DECREF (py_str_name);
621 Py_DECREF (py_str_name);
625 return _callable_info_call (self, args, kwargs);
628 /* _new_bound_callable_info
630 * Utility function for sub-classes to create a bound version of themself.
632 static PyGICallableInfo *
633 _new_bound_callable_info (PyGICallableInfo *self, PyObject *bound_arg)
635 PyGICallableInfo *new_self;
637 /* Return self if this is already bound or there is nothing passed to bind. */
638 if (self->py_bound_arg != NULL || bound_arg == NULL || bound_arg == Py_None) {
639 Py_INCREF ((PyObject *)self);
643 new_self = (PyGICallableInfo *)_pygi_info_new (self->base.info);
644 if (new_self == NULL)
647 Py_INCREF ((PyObject *)self);
648 new_self->py_unbound_info = (struct PyGICallableInfo *)self;
650 Py_INCREF (bound_arg);
651 new_self->py_bound_arg = bound_arg;
656 /* _function_info_descr_get
658 * Descriptor protocol implementation for functions, methods, and constructors.
661 _function_info_descr_get (PyGICallableInfo *self, PyObject *obj, PyObject *type) {
662 GIFunctionInfoFlags flags;
663 PyObject *bound_arg = NULL;
665 flags = g_function_info_get_flags ( (GIFunctionInfo*) self->base.info);
666 if (flags & GI_FUNCTION_IS_CONSTRUCTOR) {
668 bound_arg = (PyObject *)(Py_TYPE(obj));
671 } else if (flags & GI_FUNCTION_IS_METHOD) {
675 return (PyObject *)_new_bound_callable_info (self, bound_arg);
678 /* _vfunc_info_descr_get
680 * Descriptor protocol implementation for virtual functions.
683 _vfunc_info_descr_get (PyGICallableInfo *self, PyObject *obj, PyObject *type) {
685 PyObject *bound_arg = NULL;
687 bound_arg = PyObject_GetAttrString (type, "__gtype__");
688 if (bound_arg == NULL)
691 /* _new_bound_callable_info adds its own ref so free the one from GetAttrString */
692 result = (PyObject *)_new_bound_callable_info (self, bound_arg);
693 Py_DECREF (bound_arg);
698 _callable_info_dealloc (PyGICallableInfo *self)
700 Py_CLEAR (self->py_unbound_info);
701 Py_CLEAR (self->py_bound_arg);
703 PyGIBaseInfo_Type.tp_dealloc ((PyObject *) self);
707 _wrap_g_callable_info_get_arguments (PyGIBaseInfo *self)
709 return _make_infos_tuple (self, g_callable_info_get_n_args, g_callable_info_get_arg);
713 _wrap_g_callable_info_get_return_type (PyGIBaseInfo *self)
715 return _get_child_info (self, g_callable_info_get_return_type);
719 _wrap_g_callable_info_get_caller_owns (PyGIBaseInfo *self)
721 return PYGLIB_PyLong_FromLong (
722 g_callable_info_get_caller_owns (self->info) );
726 _wrap_g_callable_info_may_return_null (PyGIBaseInfo *self)
728 return PyBool_FromLong (
729 g_callable_info_may_return_null (self->info) );
733 _wrap_g_callable_info_get_return_attribute (PyGIBaseInfo *self, PyObject *py_name)
738 if (!PYGLIB_PyUnicode_Check (py_name)) {
739 PyErr_SetString (PyExc_TypeError, "expected string name");
743 name = PYGLIB_PyUnicode_AsString (py_name);
744 attr = g_callable_info_get_return_attribute (self->info, name);
746 return PYGLIB_PyUnicode_FromString (
747 g_callable_info_get_return_attribute (self->info, name));
749 PyErr_Format(PyExc_AttributeError, "return attribute %s not found", name);
754 static PyMethodDef _PyGICallableInfo_methods[] = {
755 { "invoke", (PyCFunction) _wrap_g_callable_info_invoke, METH_VARARGS | METH_KEYWORDS },
756 { "get_arguments", (PyCFunction) _wrap_g_callable_info_get_arguments, METH_NOARGS },
757 { "get_return_type", (PyCFunction) _wrap_g_callable_info_get_return_type, METH_NOARGS },
758 { "get_caller_owns", (PyCFunction) _wrap_g_callable_info_get_caller_owns, METH_NOARGS },
759 { "may_return_null", (PyCFunction) _wrap_g_callable_info_may_return_null, METH_NOARGS },
760 { "get_return_attribute", (PyCFunction) _wrap_g_callable_info_get_return_attribute, METH_O },
765 PYGLIB_DEFINE_TYPE ("gi.CallbackInfo", PyGICallbackInfo_Type, PyGIBaseInfo);
767 static PyMethodDef _PyGICallbackInfo_methods[] = {
771 /* ErrorDomainInfo */
772 PYGLIB_DEFINE_TYPE ("gi.ErrorDomainInfo", PyGIErrorDomainInfo_Type, PyGIBaseInfo);
774 static PyMethodDef _PyGIErrorDomainInfo_methods[] = {
779 PYGLIB_DEFINE_TYPE ("gi.SignalInfo", PyGISignalInfo_Type, PyGICallableInfo);
782 _wrap_g_signal_info_get_flags (PyGIBaseInfo *self)
784 return PYGLIB_PyLong_FromLong (
785 g_signal_info_get_flags ((GISignalInfo *)self->info) );
789 _wrap_g_signal_info_get_class_closure (PyGIBaseInfo *self)
791 return _get_child_info (self, g_signal_info_get_class_closure);
795 _wrap_g_signal_info_true_stops_emit (PyGIBaseInfo *self)
797 return PyBool_FromLong (
798 g_signal_info_true_stops_emit ((GISignalInfo *)self->info) );
801 static PyMethodDef _PyGISignalInfo_methods[] = {
802 { "get_flags", (PyCFunction) _wrap_g_signal_info_get_flags, METH_NOARGS },
803 { "get_class_closure", (PyCFunction) _wrap_g_signal_info_get_class_closure, METH_NOARGS },
804 { "true_stops_emit", (PyCFunction) _wrap_g_signal_info_true_stops_emit, METH_NOARGS },
809 PYGLIB_DEFINE_TYPE ("gi.PropertyInfo", PyGIPropertyInfo_Type, PyGIBaseInfo);
812 _wrap_g_property_info_get_flags (PyGIBaseInfo *self)
814 return PYGLIB_PyLong_FromLong (
815 g_property_info_get_flags ((GIPropertyInfo *)self->info) );
819 _wrap_g_property_info_get_type (PyGIBaseInfo *self)
821 return _get_child_info (self, g_property_info_get_type);
825 _wrap_g_property_info_get_ownership_transfer (PyGIBaseInfo *self)
827 return PYGLIB_PyLong_FromLong (
828 g_property_info_get_ownership_transfer ((GIPropertyInfo *)self->info) );
831 static PyMethodDef _PyGIPropertyInfo_methods[] = {
832 { "get_flags", (PyCFunction) _wrap_g_property_info_get_flags, METH_NOARGS },
833 { "get_type", (PyCFunction) _wrap_g_property_info_get_type, METH_NOARGS },
834 { "get_ownership_transfer", (PyCFunction) _wrap_g_property_info_get_ownership_transfer, METH_NOARGS },
840 PYGLIB_DEFINE_TYPE ("gi.ArgInfo", PyGIArgInfo_Type, PyGIBaseInfo);
843 _wrap_g_arg_info_get_direction (PyGIBaseInfo *self)
845 return PYGLIB_PyLong_FromLong (
846 g_arg_info_get_direction ((GIArgInfo*)self->info) );
850 _wrap_g_arg_info_is_caller_allocates (PyGIBaseInfo *self)
852 return PyBool_FromLong (
853 g_arg_info_is_caller_allocates ((GIArgInfo*)self->info) );
857 _wrap_g_arg_info_is_return_value (PyGIBaseInfo *self)
859 return PyBool_FromLong (
860 g_arg_info_is_return_value ((GIArgInfo*)self->info) );
864 _wrap_g_arg_info_is_optional (PyGIBaseInfo *self)
866 return PyBool_FromLong (
867 g_arg_info_is_optional ((GIArgInfo*)self->info) );
871 _wrap_g_arg_info_may_be_null (PyGIBaseInfo *self)
873 return PyBool_FromLong (
874 g_arg_info_may_be_null ((GIArgInfo*)self->info) );
878 _wrap_g_arg_info_get_ownership_transfer (PyGIBaseInfo *self)
880 return PYGLIB_PyLong_FromLong (
881 g_arg_info_get_ownership_transfer ((GIArgInfo *)self->info) );
885 _wrap_g_arg_info_get_scope (PyGIBaseInfo *self)
887 return PYGLIB_PyLong_FromLong (
888 g_arg_info_get_scope ((GIArgInfo *)self->info) );
892 _wrap_g_arg_info_get_closure (PyGIBaseInfo *self)
894 return PYGLIB_PyLong_FromLong (
895 g_arg_info_get_closure ((GIArgInfo *)self->info) );
899 _wrap_g_arg_info_get_destroy (PyGIBaseInfo *self)
901 return PYGLIB_PyLong_FromLong (
902 g_arg_info_get_destroy ((GIArgInfo *)self->info) );
906 _wrap_g_arg_info_get_type (PyGIBaseInfo *self)
908 return _get_child_info (self, g_arg_info_get_type);
911 /* _g_arg_get_pytype_hint
913 * Returns new value reference to a string hinting at the python type
914 * which can be used for the given gi argument info.
917 _g_arg_get_pytype_hint (PyGIBaseInfo *self)
919 GIArgInfo *arg_info = (GIArgInfo*)self->info;
920 GITypeInfo type_info;
924 g_arg_info_load_type(arg_info, &type_info);
925 type_tag = g_type_info_get_tag(&type_info);
927 /* First attempt getting a python type object. */
928 py_type = _pygi_get_py_type_hint(type_tag);
929 if (py_type != Py_None && PyObject_HasAttrString(py_type, "__name__")) {
930 PyObject *name = PyObject_GetAttrString(py_type, "__name__");
935 if (type_tag == GI_TYPE_TAG_INTERFACE) {
936 const char *info_name;
938 GIBaseInfo *iface = g_type_info_get_interface(&type_info);
941 info_name = _safe_base_info_get_name (iface);
942 if (info_name == NULL) {
943 g_base_info_unref (iface);
944 return PYGLIB_PyUnicode_FromString(g_type_tag_to_string(type_tag));
947 name = g_strdup_printf("%s.%s",
948 g_base_info_get_namespace(iface),
950 g_base_info_unref(iface);
951 py_string = PYGLIB_PyUnicode_FromString(name);
955 return PYGLIB_PyUnicode_FromString(g_type_tag_to_string(type_tag));
959 static PyMethodDef _PyGIArgInfo_methods[] = {
960 { "get_direction", (PyCFunction) _wrap_g_arg_info_get_direction, METH_NOARGS },
961 { "is_caller_allocates", (PyCFunction) _wrap_g_arg_info_is_caller_allocates, METH_NOARGS },
962 { "is_return_value", (PyCFunction) _wrap_g_arg_info_is_return_value, METH_NOARGS },
963 { "is_optional", (PyCFunction) _wrap_g_arg_info_is_optional, METH_NOARGS },
964 { "may_be_null", (PyCFunction) _wrap_g_arg_info_may_be_null, METH_NOARGS },
965 { "get_ownership_transfer", (PyCFunction) _wrap_g_arg_info_get_ownership_transfer, METH_NOARGS },
966 { "get_scope", (PyCFunction) _wrap_g_arg_info_get_scope, METH_NOARGS },
967 { "get_closure", (PyCFunction) _wrap_g_arg_info_get_closure, METH_NOARGS },
968 { "get_destroy", (PyCFunction) _wrap_g_arg_info_get_destroy, METH_NOARGS },
969 { "get_type", (PyCFunction) _wrap_g_arg_info_get_type, METH_NOARGS },
970 { "get_pytype_hint", (PyCFunction) _g_arg_get_pytype_hint, METH_NOARGS },
976 PYGLIB_DEFINE_TYPE ("gi.TypeInfo", PyGITypeInfo_Type, PyGIBaseInfo);
979 _wrap_g_type_info_is_pointer (PyGIBaseInfo *self)
981 return PyBool_FromLong (g_type_info_is_pointer (self->info));
985 _wrap_g_type_info_get_tag (PyGIBaseInfo *self)
987 return PYGLIB_PyLong_FromLong (g_type_info_get_tag (self->info));
991 _wrap_g_type_info_get_tag_as_string (PyGIBaseInfo *self)
993 GITypeTag tag = g_type_info_get_tag (self->info);
994 return PYGLIB_PyUnicode_FromString (g_type_tag_to_string(tag));
998 _wrap_g_type_info_get_param_type (PyGIBaseInfo *self, PyObject *py_n)
1004 if (!PYGLIB_PyLong_Check (py_n)) {
1005 PyErr_SetString(PyExc_TypeError, "expected integer value");
1009 n = PYGLIB_PyLong_AsLong (py_n);
1010 info = (GIBaseInfo *) g_type_info_get_param_type ( (GITypeInfo *) self->info, n);
1015 py_info = _pygi_info_new (info);
1016 g_base_info_unref (info);
1021 _wrap_g_type_info_get_interface (PyGIBaseInfo *self)
1023 return _get_child_info (self, g_type_info_get_interface);
1027 _wrap_g_type_info_get_array_length (PyGIBaseInfo *self)
1029 return PYGLIB_PyLong_FromLong (g_type_info_get_array_length (self->info));
1033 _wrap_g_type_info_get_array_fixed_size (PyGIBaseInfo *self)
1035 return PYGLIB_PyLong_FromLong (g_type_info_get_array_fixed_size (self->info));
1039 _wrap_g_type_info_is_zero_terminated (PyGIBaseInfo *self)
1041 return PyBool_FromLong (g_type_info_is_zero_terminated (self->info));
1045 _wrap_g_type_info_get_array_type (PyGIBaseInfo *self)
1047 return PYGLIB_PyLong_FromLong (g_type_info_get_array_type (self->info));
1050 static PyMethodDef _PyGITypeInfo_methods[] = {
1051 { "is_pointer", (PyCFunction) _wrap_g_type_info_is_pointer, METH_NOARGS },
1052 { "get_tag", (PyCFunction) _wrap_g_type_info_get_tag, METH_NOARGS },
1053 { "get_tag_as_string", (PyCFunction) _wrap_g_type_info_get_tag_as_string, METH_NOARGS },
1054 { "get_param_type", (PyCFunction) _wrap_g_type_info_get_param_type, METH_O },
1055 { "get_interface", (PyCFunction) _wrap_g_type_info_get_interface, METH_NOARGS },
1056 { "get_array_length", (PyCFunction) _wrap_g_type_info_get_array_length, METH_NOARGS },
1057 { "get_array_fixed_size", (PyCFunction) _wrap_g_type_info_get_array_fixed_size, METH_NOARGS },
1058 { "is_zero_terminated", (PyCFunction) _wrap_g_type_info_is_zero_terminated, METH_NOARGS },
1059 { "get_array_type", (PyCFunction) _wrap_g_type_info_get_array_type, METH_NOARGS },
1065 PYGLIB_DEFINE_TYPE ("gi.FunctionInfo", PyGIFunctionInfo_Type, PyGICallableInfo);
1068 _wrap_g_function_info_is_constructor (PyGIBaseInfo *self)
1070 GIFunctionInfoFlags flags;
1071 gboolean is_constructor;
1073 flags = g_function_info_get_flags ( (GIFunctionInfo*) self->info);
1074 is_constructor = flags & GI_FUNCTION_IS_CONSTRUCTOR;
1076 return PyBool_FromLong (is_constructor);
1080 _wrap_g_function_info_is_method (PyGIBaseInfo *self)
1082 GIFunctionInfoFlags flags;
1085 flags = g_function_info_get_flags ( (GIFunctionInfo*) self->info);
1086 is_method = flags & GI_FUNCTION_IS_METHOD;
1088 return PyBool_FromLong (is_method);
1092 _pygi_g_type_tag_size (GITypeTag type_tag)
1097 case GI_TYPE_TAG_BOOLEAN:
1098 size = sizeof (gboolean);
1100 case GI_TYPE_TAG_INT8:
1101 case GI_TYPE_TAG_UINT8:
1102 size = sizeof (gint8);
1104 case GI_TYPE_TAG_INT16:
1105 case GI_TYPE_TAG_UINT16:
1106 size = sizeof (gint16);
1108 case GI_TYPE_TAG_INT32:
1109 case GI_TYPE_TAG_UINT32:
1110 size = sizeof (gint32);
1112 case GI_TYPE_TAG_INT64:
1113 case GI_TYPE_TAG_UINT64:
1114 size = sizeof (gint64);
1116 case GI_TYPE_TAG_FLOAT:
1117 size = sizeof (gfloat);
1119 case GI_TYPE_TAG_DOUBLE:
1120 size = sizeof (gdouble);
1122 case GI_TYPE_TAG_GTYPE:
1123 size = sizeof (GType);
1125 case GI_TYPE_TAG_UNICHAR:
1126 size = sizeof (gunichar);
1128 case GI_TYPE_TAG_VOID:
1129 case GI_TYPE_TAG_UTF8:
1130 case GI_TYPE_TAG_FILENAME:
1131 case GI_TYPE_TAG_ARRAY:
1132 case GI_TYPE_TAG_INTERFACE:
1133 case GI_TYPE_TAG_GLIST:
1134 case GI_TYPE_TAG_GSLIST:
1135 case GI_TYPE_TAG_GHASH:
1136 case GI_TYPE_TAG_ERROR:
1137 PyErr_Format (PyExc_TypeError,
1138 "Unable to know the size (assuming %s is not a pointer)",
1139 g_type_tag_to_string (type_tag));
1147 _pygi_g_type_info_size (GITypeInfo *type_info)
1153 type_tag = g_type_info_get_tag (type_info);
1155 case GI_TYPE_TAG_BOOLEAN:
1156 case GI_TYPE_TAG_INT8:
1157 case GI_TYPE_TAG_UINT8:
1158 case GI_TYPE_TAG_INT16:
1159 case GI_TYPE_TAG_UINT16:
1160 case GI_TYPE_TAG_INT32:
1161 case GI_TYPE_TAG_UINT32:
1162 case GI_TYPE_TAG_INT64:
1163 case GI_TYPE_TAG_UINT64:
1164 case GI_TYPE_TAG_FLOAT:
1165 case GI_TYPE_TAG_DOUBLE:
1166 case GI_TYPE_TAG_GTYPE:
1167 case GI_TYPE_TAG_UNICHAR:
1168 size = _pygi_g_type_tag_size (type_tag);
1169 g_assert (size > 0);
1171 case GI_TYPE_TAG_INTERFACE:
1174 GIInfoType info_type;
1176 info = g_type_info_get_interface (type_info);
1177 info_type = g_base_info_get_type (info);
1179 switch (info_type) {
1180 case GI_INFO_TYPE_STRUCT:
1181 if (g_type_info_is_pointer (type_info)) {
1182 size = sizeof (gpointer);
1184 size = g_struct_info_get_size ( (GIStructInfo *) info);
1187 case GI_INFO_TYPE_UNION:
1188 if (g_type_info_is_pointer (type_info)) {
1189 size = sizeof (gpointer);
1191 size = g_union_info_get_size ( (GIUnionInfo *) info);
1194 case GI_INFO_TYPE_ENUM:
1195 case GI_INFO_TYPE_FLAGS:
1196 if (g_type_info_is_pointer (type_info)) {
1197 size = sizeof (gpointer);
1201 type_tag = g_enum_info_get_storage_type ( (GIEnumInfo *) info);
1202 size = _pygi_g_type_tag_size (type_tag);
1205 case GI_INFO_TYPE_BOXED:
1206 case GI_INFO_TYPE_OBJECT:
1207 case GI_INFO_TYPE_INTERFACE:
1208 case GI_INFO_TYPE_CALLBACK:
1209 size = sizeof (gpointer);
1211 case GI_INFO_TYPE_VFUNC:
1212 case GI_INFO_TYPE_INVALID:
1213 case GI_INFO_TYPE_FUNCTION:
1214 case GI_INFO_TYPE_CONSTANT:
1215 case GI_INFO_TYPE_VALUE:
1216 case GI_INFO_TYPE_SIGNAL:
1217 case GI_INFO_TYPE_PROPERTY:
1218 case GI_INFO_TYPE_FIELD:
1219 case GI_INFO_TYPE_ARG:
1220 case GI_INFO_TYPE_TYPE:
1221 case GI_INFO_TYPE_UNRESOLVED:
1223 g_assert_not_reached();
1227 g_base_info_unref (info);
1230 case GI_TYPE_TAG_ARRAY:
1231 case GI_TYPE_TAG_VOID:
1232 case GI_TYPE_TAG_UTF8:
1233 case GI_TYPE_TAG_FILENAME:
1234 case GI_TYPE_TAG_GLIST:
1235 case GI_TYPE_TAG_GSLIST:
1236 case GI_TYPE_TAG_GHASH:
1237 case GI_TYPE_TAG_ERROR:
1238 size = sizeof (gpointer);
1246 _wrap_g_function_info_get_symbol (PyGIBaseInfo *self)
1248 return _get_info_string (self, g_function_info_get_symbol);
1252 _wrap_g_function_info_get_flags (PyGIBaseInfo *self)
1254 return PYGLIB_PyLong_FromLong (g_function_info_get_flags (self->info));
1258 _wrap_g_function_info_get_property (PyGIBaseInfo *self)
1260 return _get_child_info (self, g_function_info_get_property);
1264 _wrap_g_function_info_get_vfunc (PyGIBaseInfo *self)
1266 return _get_child_info (self, g_function_info_get_vfunc);
1269 static PyMethodDef _PyGIFunctionInfo_methods[] = {
1270 { "is_constructor", (PyCFunction) _wrap_g_function_info_is_constructor, METH_NOARGS },
1271 { "is_method", (PyCFunction) _wrap_g_function_info_is_method, METH_NOARGS },
1272 { "get_symbol", (PyCFunction) _wrap_g_function_info_get_symbol, METH_NOARGS },
1273 { "get_flags", (PyCFunction) _wrap_g_function_info_get_flags, METH_NOARGS },
1274 { "get_property", (PyCFunction) _wrap_g_function_info_get_property, METH_NOARGS },
1275 { "get_vfunc", (PyCFunction) _wrap_g_function_info_get_vfunc, METH_NOARGS },
1279 /* RegisteredTypeInfo */
1280 PYGLIB_DEFINE_TYPE ("gi.RegisteredTypeInfo", PyGIRegisteredTypeInfo_Type, PyGIBaseInfo);
1283 _wrap_g_registered_type_info_get_type_name (PyGIBaseInfo *self)
1285 return _get_info_string (self, g_registered_type_info_get_type_name);
1289 _wrap_g_registered_type_info_get_type_init (PyGIBaseInfo *self)
1291 return _get_info_string (self, g_registered_type_info_get_type_init);
1295 _wrap_g_registered_type_info_get_g_type (PyGIBaseInfo *self)
1299 type = g_registered_type_info_get_g_type ( (GIRegisteredTypeInfo *) self->info);
1301 return pyg_type_wrapper_new (type);
1304 static PyMethodDef _PyGIRegisteredTypeInfo_methods[] = {
1305 { "get_type_name", (PyCFunction) _wrap_g_registered_type_info_get_type_name, METH_NOARGS },
1306 { "get_type_init", (PyCFunction) _wrap_g_registered_type_info_get_type_init, METH_NOARGS },
1307 { "get_g_type", (PyCFunction) _wrap_g_registered_type_info_get_g_type, METH_NOARGS },
1313 PYGLIB_DEFINE_TYPE ("StructInfo", PyGIStructInfo_Type, PyGIBaseInfo);
1316 _wrap_g_struct_info_get_fields (PyGIBaseInfo *self)
1318 return _make_infos_tuple (self, g_struct_info_get_n_fields, g_struct_info_get_field);
1322 _wrap_g_struct_info_get_methods (PyGIBaseInfo *self)
1324 return _make_infos_tuple (self, g_struct_info_get_n_methods, g_struct_info_get_method);
1328 _wrap_g_struct_info_get_size (PyGIBaseInfo *self)
1330 return PYGLIB_PyLong_FromSize_t (g_struct_info_get_size (self->info));
1334 _wrap_g_struct_info_get_alignment (PyGIBaseInfo *self)
1336 return PYGLIB_PyLong_FromSize_t (g_struct_info_get_alignment (self->info));
1340 _wrap_g_struct_info_is_gtype_struct (PyGIBaseInfo *self)
1342 return PyBool_FromLong (g_struct_info_is_gtype_struct (self->info));
1346 _wrap_g_struct_info_is_foreign (PyGIBaseInfo *self)
1348 return PyBool_FromLong (g_struct_info_is_foreign (self->info));
1351 static PyMethodDef _PyGIStructInfo_methods[] = {
1352 { "get_fields", (PyCFunction) _wrap_g_struct_info_get_fields, METH_NOARGS },
1353 { "get_methods", (PyCFunction) _wrap_g_struct_info_get_methods, METH_NOARGS },
1354 { "get_size", (PyCFunction) _wrap_g_struct_info_get_size, METH_NOARGS },
1355 { "get_alignment", (PyCFunction) _wrap_g_struct_info_get_alignment, METH_NOARGS },
1356 { "is_gtype_struct", (PyCFunction) _wrap_g_struct_info_is_gtype_struct, METH_NOARGS },
1357 { "is_foreign", (PyCFunction) _wrap_g_struct_info_is_foreign, METH_NOARGS },
1362 pygi_g_struct_info_is_simple (GIStructInfo *struct_info)
1365 gsize n_field_infos;
1370 n_field_infos = g_struct_info_get_n_fields (struct_info);
1372 for (i = 0; i < n_field_infos && is_simple; i++) {
1373 GIFieldInfo *field_info;
1374 GITypeInfo *field_type_info;
1375 GITypeTag field_type_tag;
1377 field_info = g_struct_info_get_field (struct_info, i);
1378 field_type_info = g_field_info_get_type (field_info);
1381 field_type_tag = g_type_info_get_tag (field_type_info);
1383 switch (field_type_tag) {
1384 case GI_TYPE_TAG_BOOLEAN:
1385 case GI_TYPE_TAG_INT8:
1386 case GI_TYPE_TAG_UINT8:
1387 case GI_TYPE_TAG_INT16:
1388 case GI_TYPE_TAG_UINT16:
1389 case GI_TYPE_TAG_INT32:
1390 case GI_TYPE_TAG_UINT32:
1391 case GI_TYPE_TAG_INT64:
1392 case GI_TYPE_TAG_UINT64:
1393 case GI_TYPE_TAG_FLOAT:
1394 case GI_TYPE_TAG_DOUBLE:
1395 case GI_TYPE_TAG_UNICHAR:
1396 if (g_type_info_is_pointer (field_type_info)) {
1400 case GI_TYPE_TAG_VOID:
1401 case GI_TYPE_TAG_GTYPE:
1402 case GI_TYPE_TAG_ERROR:
1403 case GI_TYPE_TAG_UTF8:
1404 case GI_TYPE_TAG_FILENAME:
1405 case GI_TYPE_TAG_ARRAY:
1406 case GI_TYPE_TAG_GLIST:
1407 case GI_TYPE_TAG_GSLIST:
1408 case GI_TYPE_TAG_GHASH:
1411 case GI_TYPE_TAG_INTERFACE:
1414 GIInfoType info_type;
1416 info = g_type_info_get_interface (field_type_info);
1417 info_type = g_base_info_get_type (info);
1419 switch (info_type) {
1420 case GI_INFO_TYPE_STRUCT:
1421 if (g_type_info_is_pointer (field_type_info)) {
1424 is_simple = pygi_g_struct_info_is_simple ( (GIStructInfo *) info);
1427 case GI_INFO_TYPE_UNION:
1431 case GI_INFO_TYPE_ENUM:
1432 case GI_INFO_TYPE_FLAGS:
1433 if (g_type_info_is_pointer (field_type_info)) {
1437 case GI_INFO_TYPE_BOXED:
1438 case GI_INFO_TYPE_OBJECT:
1439 case GI_INFO_TYPE_CALLBACK:
1440 case GI_INFO_TYPE_INTERFACE:
1443 case GI_INFO_TYPE_VFUNC:
1444 case GI_INFO_TYPE_INVALID:
1445 case GI_INFO_TYPE_FUNCTION:
1446 case GI_INFO_TYPE_CONSTANT:
1447 case GI_INFO_TYPE_VALUE:
1448 case GI_INFO_TYPE_SIGNAL:
1449 case GI_INFO_TYPE_PROPERTY:
1450 case GI_INFO_TYPE_FIELD:
1451 case GI_INFO_TYPE_ARG:
1452 case GI_INFO_TYPE_TYPE:
1453 case GI_INFO_TYPE_UNRESOLVED:
1455 g_assert_not_reached();
1459 g_base_info_unref (info);
1464 g_base_info_unref ( (GIBaseInfo *) field_type_info);
1465 g_base_info_unref ( (GIBaseInfo *) field_info);
1473 PYGLIB_DEFINE_TYPE ("gi.EnumInfo", PyGIEnumInfo_Type, PyGIBaseInfo);
1476 _wrap_g_enum_info_get_values (PyGIBaseInfo *self)
1478 return _make_infos_tuple (self, g_enum_info_get_n_values, g_enum_info_get_value);
1482 _wrap_g_enum_info_is_flags (PyGIBaseInfo *self)
1484 GIInfoType info_type = g_base_info_get_type ((GIBaseInfo *) self->info);
1486 if (info_type == GI_INFO_TYPE_ENUM) {
1488 } else if (info_type == GI_INFO_TYPE_FLAGS) {
1491 g_assert_not_reached();
1496 _wrap_g_enum_info_get_methods (PyGIBaseInfo *self)
1498 return _make_infos_tuple (self, g_enum_info_get_n_methods, g_enum_info_get_method);
1502 _wrap_g_enum_info_get_storage_type (PyGIBaseInfo *self)
1504 return PYGLIB_PyLong_FromLong (g_enum_info_get_storage_type ((GIBaseInfo *) self->info));
1507 static PyMethodDef _PyGIEnumInfo_methods[] = {
1508 { "get_values", (PyCFunction) _wrap_g_enum_info_get_values, METH_NOARGS },
1509 { "is_flags", (PyCFunction) _wrap_g_enum_info_is_flags, METH_NOARGS },
1510 { "get_methods", (PyCFunction) _wrap_g_enum_info_get_methods, METH_NOARGS },
1511 { "get_storage_type", (PyCFunction) _wrap_g_enum_info_get_storage_type, METH_NOARGS },
1517 PYGLIB_DEFINE_TYPE ("ObjectInfo", PyGIObjectInfo_Type, PyGIBaseInfo);
1520 _wrap_g_object_info_get_parent (PyGIBaseInfo *self)
1522 return _get_child_info (self, g_object_info_get_parent);
1526 _wrap_g_object_info_get_methods (PyGIBaseInfo *self)
1528 return _make_infos_tuple (self, g_object_info_get_n_methods, g_object_info_get_method);
1532 _wrap_g_object_info_find_method (PyGIBaseInfo *self, PyObject *py_name)
1534 return _get_child_info_by_name (self, py_name, g_object_info_find_method);
1538 _wrap_g_object_info_get_fields (PyGIBaseInfo *self)
1540 return _make_infos_tuple (self, g_object_info_get_n_fields, g_object_info_get_field);
1544 _wrap_g_object_info_get_properties (PyGIBaseInfo *self)
1546 return _make_infos_tuple (self, g_object_info_get_n_properties, g_object_info_get_property);
1550 _wrap_g_object_info_get_signals (PyGIBaseInfo *self)
1552 return _make_infos_tuple (self, g_object_info_get_n_signals, g_object_info_get_signal);
1556 _wrap_g_object_info_get_interfaces (PyGIBaseInfo *self)
1558 return _make_infos_tuple (self, g_object_info_get_n_interfaces, g_object_info_get_interface);
1562 _wrap_g_object_info_get_constants (PyGIBaseInfo *self)
1564 return _make_infos_tuple (self, g_object_info_get_n_constants, g_object_info_get_constant);
1568 _wrap_g_object_info_get_vfuncs (PyGIBaseInfo *self)
1570 return _make_infos_tuple (self, g_object_info_get_n_vfuncs, g_object_info_get_vfunc);
1574 _wrap_g_object_info_get_abstract (PyGIBaseInfo *self)
1576 gboolean is_abstract = g_object_info_get_abstract ( (GIObjectInfo*) self->info);
1577 return PyBool_FromLong (is_abstract);
1581 _wrap_g_object_info_get_type_name (PyGIBaseInfo *self)
1583 return _get_info_string (self, g_object_info_get_type_name);
1587 _wrap_g_object_info_get_type_init (PyGIBaseInfo *self)
1589 return _get_info_string (self, g_object_info_get_type_init);
1593 _wrap_g_object_info_get_fundamental (PyGIBaseInfo *self)
1595 return PyBool_FromLong (g_object_info_get_fundamental ( (GIObjectInfo*) self->info));
1599 _wrap_g_object_info_get_class_struct (PyGIBaseInfo *self)
1601 return _get_child_info (self, g_object_info_get_class_struct);
1605 _wrap_g_object_info_find_vfunc (PyGIBaseInfo *self, PyObject *py_name)
1607 return _get_child_info_by_name (self, py_name, g_object_info_find_vfunc);
1611 _wrap_g_object_info_get_unref_function (PyGIBaseInfo *self)
1613 return _get_info_string (self, g_object_info_get_unref_function);
1617 _wrap_g_object_info_get_ref_function (PyGIBaseInfo *self)
1619 return _get_info_string (self, g_object_info_get_ref_function);
1623 _wrap_g_object_info_get_set_value_function (PyGIBaseInfo *self)
1625 return _get_info_string (self, g_object_info_get_set_value_function);
1629 _wrap_g_object_info_get_get_value_function (PyGIBaseInfo *self)
1631 return _get_info_string (self, g_object_info_get_get_value_function);
1634 static PyMethodDef _PyGIObjectInfo_methods[] = {
1635 { "get_parent", (PyCFunction) _wrap_g_object_info_get_parent, METH_NOARGS },
1636 { "get_methods", (PyCFunction) _wrap_g_object_info_get_methods, METH_NOARGS },
1637 { "find_method", (PyCFunction) _wrap_g_object_info_find_method, METH_O },
1638 { "get_fields", (PyCFunction) _wrap_g_object_info_get_fields, METH_NOARGS },
1639 { "get_properties", (PyCFunction) _wrap_g_object_info_get_properties, METH_NOARGS },
1640 { "get_signals", (PyCFunction) _wrap_g_object_info_get_signals, METH_NOARGS },
1641 { "get_interfaces", (PyCFunction) _wrap_g_object_info_get_interfaces, METH_NOARGS },
1642 { "get_constants", (PyCFunction) _wrap_g_object_info_get_constants, METH_NOARGS },
1643 { "get_vfuncs", (PyCFunction) _wrap_g_object_info_get_vfuncs, METH_NOARGS },
1644 { "find_vfunc", (PyCFunction) _wrap_g_object_info_find_vfunc, METH_O },
1645 { "get_abstract", (PyCFunction) _wrap_g_object_info_get_abstract, METH_NOARGS },
1646 { "get_type_name", (PyCFunction) _wrap_g_object_info_get_type_name, METH_NOARGS },
1647 { "get_type_init", (PyCFunction) _wrap_g_object_info_get_type_init, METH_NOARGS },
1648 { "get_fundamental", (PyCFunction) _wrap_g_object_info_get_fundamental, METH_NOARGS },
1649 { "get_class_struct", (PyCFunction) _wrap_g_object_info_get_class_struct, METH_NOARGS },
1650 { "get_unref_function", (PyCFunction) _wrap_g_object_info_get_unref_function, METH_NOARGS },
1651 { "get_ref_function", (PyCFunction) _wrap_g_object_info_get_ref_function, METH_NOARGS },
1652 { "get_set_value_function", (PyCFunction) _wrap_g_object_info_get_set_value_function, METH_NOARGS },
1653 { "get_get_value_function", (PyCFunction) _wrap_g_object_info_get_get_value_function, METH_NOARGS },
1658 /* GIInterfaceInfo */
1659 PYGLIB_DEFINE_TYPE ("InterfaceInfo", PyGIInterfaceInfo_Type, PyGIBaseInfo);
1662 _wrap_g_interface_info_get_methods (PyGIBaseInfo *self)
1664 return _make_infos_tuple (self, g_interface_info_get_n_methods, g_interface_info_get_method);
1668 _wrap_g_interface_info_find_method (PyGIBaseInfo *self, PyObject *py_name)
1670 return _get_child_info_by_name (self, py_name, g_interface_info_find_method);
1674 _wrap_g_interface_info_get_constants (PyGIBaseInfo *self)
1676 return _make_infos_tuple (self, g_interface_info_get_n_constants, g_interface_info_get_constant);
1680 _wrap_g_interface_info_get_vfuncs (PyGIBaseInfo *self)
1682 return _make_infos_tuple (self, g_interface_info_get_n_vfuncs, g_interface_info_get_vfunc);
1686 _wrap_g_interface_info_find_vfunc (PyGIBaseInfo *self, PyObject *py_name)
1688 return _get_child_info_by_name (self, py_name, g_interface_info_find_vfunc);
1692 _wrap_g_interface_info_get_prerequisites (PyGIBaseInfo *self)
1694 return _make_infos_tuple (self, g_interface_info_get_n_prerequisites, g_interface_info_get_prerequisite);
1698 _wrap_g_interface_info_get_properties (PyGIBaseInfo *self)
1700 return _make_infos_tuple (self, g_interface_info_get_n_properties, g_interface_info_get_property);
1704 _wrap_g_interface_info_get_iface_struct (PyGIBaseInfo *self)
1706 return _get_child_info (self, g_interface_info_get_iface_struct);
1710 _wrap_g_interface_info_get_signals (PyGIBaseInfo *self)
1712 return _make_infos_tuple (self, g_interface_info_get_n_signals, g_interface_info_get_signal);
1716 _wrap_g_interface_info_find_signal (PyGIBaseInfo *self, PyObject *py_name)
1718 return _get_child_info_by_name (self, py_name, g_interface_info_find_signal);
1721 static PyMethodDef _PyGIInterfaceInfo_methods[] = {
1722 { "get_prerequisites", (PyCFunction) _wrap_g_interface_info_get_prerequisites, METH_NOARGS },
1723 { "get_properties", (PyCFunction) _wrap_g_interface_info_get_properties, METH_NOARGS },
1724 { "get_methods", (PyCFunction) _wrap_g_interface_info_get_methods, METH_NOARGS },
1725 { "find_method", (PyCFunction) _wrap_g_interface_info_find_method, METH_O },
1726 { "get_signals", (PyCFunction) _wrap_g_interface_info_get_signals, METH_NOARGS },
1727 { "find_signal", (PyCFunction) _wrap_g_interface_info_find_signal, METH_O },
1728 { "get_vfuncs", (PyCFunction) _wrap_g_interface_info_get_vfuncs, METH_NOARGS },
1729 { "get_constants", (PyCFunction) _wrap_g_interface_info_get_constants, METH_NOARGS },
1730 { "get_iface_struct", (PyCFunction) _wrap_g_interface_info_get_iface_struct, METH_NOARGS },
1731 { "find_vfunc", (PyCFunction) _wrap_g_interface_info_find_vfunc, METH_O },
1735 /* GIConstantInfo */
1736 PYGLIB_DEFINE_TYPE ("gi.ConstantInfo", PyGIConstantInfo_Type, PyGIBaseInfo);
1739 _wrap_g_constant_info_get_value (PyGIBaseInfo *self)
1741 GITypeInfo *type_info;
1744 gboolean free_array = FALSE;
1746 if (g_constant_info_get_value ( (GIConstantInfo *) self->info, &value) < 0) {
1747 PyErr_SetString (PyExc_RuntimeError, "unable to get value");
1751 type_info = g_constant_info_get_type ( (GIConstantInfo *) self->info);
1753 if (g_type_info_get_tag (type_info) == GI_TYPE_TAG_ARRAY) {
1754 value.v_pointer = _pygi_argument_to_array (&value, NULL, NULL, NULL,
1755 type_info, &free_array);
1758 py_value = _pygi_argument_to_object (&value, type_info, GI_TRANSFER_NOTHING);
1761 g_array_free (value.v_pointer, FALSE);
1764 g_constant_info_free_value (self->info, &value);
1765 g_base_info_unref ( (GIBaseInfo *) type_info);
1770 static PyMethodDef _PyGIConstantInfo_methods[] = {
1771 { "get_value", (PyCFunction) _wrap_g_constant_info_get_value, METH_NOARGS },
1776 PYGLIB_DEFINE_TYPE ("gi.ValueInfo", PyGIValueInfo_Type, PyGIBaseInfo);
1779 _wrap_g_value_info_get_value (PyGIBaseInfo *self)
1783 value = g_value_info_get_value ( (GIValueInfo *) self->info);
1785 return PYGLIB_PyLong_FromLong (value);
1789 static PyMethodDef _PyGIValueInfo_methods[] = {
1790 { "get_value", (PyCFunction) _wrap_g_value_info_get_value, METH_NOARGS },
1796 PYGLIB_DEFINE_TYPE ("gi.FieldInfo", PyGIFieldInfo_Type, PyGIBaseInfo);
1799 _wrap_g_field_info_get_value (PyGIBaseInfo *self,
1803 GIBaseInfo *container_info;
1804 GIInfoType container_info_type;
1806 GITypeInfo *field_type_info;
1808 PyObject *py_value = NULL;
1809 gboolean free_array = FALSE;
1811 memset(&value, 0, sizeof(GIArgument));
1813 if (!PyArg_ParseTuple (args, "O:FieldInfo.get_value", &instance)) {
1817 container_info = g_base_info_get_container (self->info);
1818 g_assert (container_info != NULL);
1820 /* Check the instance. */
1821 if (!_pygi_g_registered_type_info_check_object ( (GIRegisteredTypeInfo *) container_info, TRUE, instance)) {
1822 _PyGI_ERROR_PREFIX ("argument 1: ");
1826 /* Get the pointer to the container. */
1827 container_info_type = g_base_info_get_type (container_info);
1828 switch (container_info_type) {
1829 case GI_INFO_TYPE_UNION:
1830 case GI_INFO_TYPE_STRUCT:
1831 pointer = pyg_boxed_get (instance, void);
1833 case GI_INFO_TYPE_OBJECT:
1834 pointer = pygobject_get (instance);
1837 /* Other types don't have fields. */
1838 g_assert_not_reached();
1841 /* Get the field's value. */
1842 field_type_info = g_field_info_get_type ( (GIFieldInfo *) self->info);
1844 /* A few types are not handled by g_field_info_get_field, so do it here. */
1845 if (!g_type_info_is_pointer (field_type_info)
1846 && g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_INTERFACE) {
1848 GIInfoType info_type;
1850 if (! (g_field_info_get_flags ( (GIFieldInfo *) self->info) & GI_FIELD_IS_READABLE)) {
1851 PyErr_SetString (PyExc_RuntimeError, "field is not readable");
1855 info = g_type_info_get_interface (field_type_info);
1857 info_type = g_base_info_get_type (info);
1859 g_base_info_unref (info);
1861 switch (info_type) {
1862 case GI_INFO_TYPE_UNION:
1863 PyErr_SetString (PyExc_NotImplementedError, "getting an union is not supported yet");
1865 case GI_INFO_TYPE_STRUCT:
1869 offset = g_field_info_get_offset ( (GIFieldInfo *) self->info);
1871 value.v_pointer = (char*) pointer + offset;
1873 goto argument_to_object;
1881 if (!g_field_info_get_field ( (GIFieldInfo *) self->info, pointer, &value)) {
1882 PyErr_SetString (PyExc_RuntimeError, "unable to get the value");
1886 if (g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_ARRAY) {
1887 value.v_pointer = _pygi_argument_to_array (&value, NULL, NULL, NULL,
1888 field_type_info, &free_array);
1892 py_value = _pygi_argument_to_object (&value, field_type_info, GI_TRANSFER_NOTHING);
1895 g_array_free (value.v_pointer, FALSE);
1899 g_base_info_unref ( (GIBaseInfo *) field_type_info);
1905 _wrap_g_field_info_set_value (PyGIBaseInfo *self,
1910 GIBaseInfo *container_info;
1911 GIInfoType container_info_type;
1913 GITypeInfo *field_type_info;
1915 PyObject *retval = NULL;
1917 if (!PyArg_ParseTuple (args, "OO:FieldInfo.set_value", &instance, &py_value)) {
1921 container_info = g_base_info_get_container (self->info);
1922 g_assert (container_info != NULL);
1924 /* Check the instance. */
1925 if (!_pygi_g_registered_type_info_check_object ( (GIRegisteredTypeInfo *) container_info, TRUE, instance)) {
1926 _PyGI_ERROR_PREFIX ("argument 1: ");
1930 /* Get the pointer to the container. */
1931 container_info_type = g_base_info_get_type (container_info);
1932 switch (container_info_type) {
1933 case GI_INFO_TYPE_UNION:
1934 case GI_INFO_TYPE_STRUCT:
1935 pointer = pyg_boxed_get (instance, void);
1937 case GI_INFO_TYPE_OBJECT:
1938 pointer = pygobject_get (instance);
1941 /* Other types don't have fields. */
1942 g_assert_not_reached();
1945 field_type_info = g_field_info_get_type ( (GIFieldInfo *) self->info);
1947 /* Check the value. */
1951 retval = _pygi_g_type_info_check_object (field_type_info, py_value, TRUE);
1957 _PyGI_ERROR_PREFIX ("argument 2: ");
1962 /* Set the field's value. */
1963 /* A few types are not handled by g_field_info_set_field, so do it here. */
1964 if (!g_type_info_is_pointer (field_type_info)
1965 && g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_INTERFACE) {
1967 GIInfoType info_type;
1969 if (! (g_field_info_get_flags ( (GIFieldInfo *) self->info) & GI_FIELD_IS_WRITABLE)) {
1970 PyErr_SetString (PyExc_RuntimeError, "field is not writable");
1974 info = g_type_info_get_interface (field_type_info);
1976 info_type = g_base_info_get_type (info);
1978 switch (info_type) {
1979 case GI_INFO_TYPE_UNION:
1980 PyErr_SetString (PyExc_NotImplementedError, "setting an union is not supported yet");
1982 case GI_INFO_TYPE_STRUCT:
1988 is_simple = pygi_g_struct_info_is_simple ( (GIStructInfo *) info);
1991 PyErr_SetString (PyExc_TypeError,
1992 "cannot set a structure which has no well-defined ownership transfer rules");
1993 g_base_info_unref (info);
1997 value = _pygi_argument_from_object (py_value, field_type_info, GI_TRANSFER_NOTHING);
1998 if (PyErr_Occurred()) {
1999 g_base_info_unref (info);
2003 offset = g_field_info_get_offset ( (GIFieldInfo *) self->info);
2004 size = g_struct_info_get_size ( (GIStructInfo *) info);
2005 g_assert (size > 0);
2007 g_memmove ((char*) pointer + offset, value.v_pointer, size);
2009 g_base_info_unref (info);
2019 g_base_info_unref (info);
2020 } else if (g_type_info_is_pointer (field_type_info)
2021 && (g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_VOID
2022 || g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_UTF8)) {
2024 value = _pygi_argument_from_object (py_value, field_type_info, GI_TRANSFER_NOTHING);
2025 if (PyErr_Occurred()) {
2029 offset = g_field_info_get_offset ((GIFieldInfo *) self->info);
2030 G_STRUCT_MEMBER (gpointer, pointer, offset) = (gpointer)value.v_pointer;
2036 value = _pygi_argument_from_object (py_value, field_type_info, GI_TRANSFER_EVERYTHING);
2037 if (PyErr_Occurred()) {
2041 if (!g_field_info_set_field ( (GIFieldInfo *) self->info, pointer, &value)) {
2042 _pygi_argument_release (&value, field_type_info, GI_TRANSFER_NOTHING, GI_DIRECTION_IN);
2043 PyErr_SetString (PyExc_RuntimeError, "unable to set value for field");
2050 g_base_info_unref ( (GIBaseInfo *) field_type_info);
2052 Py_XINCREF (retval);
2057 _wrap_g_field_info_get_flags (PyGIBaseInfo *self)
2059 return PYGLIB_PyLong_FromLong (g_field_info_get_flags (self->info));
2063 _wrap_g_field_info_get_size (PyGIBaseInfo *self)
2065 return PYGLIB_PyLong_FromLong (g_field_info_get_size (self->info));
2069 _wrap_g_field_info_get_offset (PyGIBaseInfo *self)
2071 return PYGLIB_PyLong_FromLong (g_field_info_get_offset (self->info));
2075 _wrap_g_field_info_get_type (PyGIBaseInfo *self)
2077 return _get_child_info (self, g_field_info_get_type);
2080 static PyMethodDef _PyGIFieldInfo_methods[] = {
2081 { "get_value", (PyCFunction) _wrap_g_field_info_get_value, METH_VARARGS },
2082 { "set_value", (PyCFunction) _wrap_g_field_info_set_value, METH_VARARGS },
2083 { "get_flags", (PyCFunction) _wrap_g_field_info_get_flags, METH_VARARGS },
2084 { "get_size", (PyCFunction) _wrap_g_field_info_get_size, METH_VARARGS },
2085 { "get_offset", (PyCFunction) _wrap_g_field_info_get_offset, METH_VARARGS },
2086 { "get_type", (PyCFunction) _wrap_g_field_info_get_type, METH_VARARGS },
2091 /* GIUnresolvedInfo */
2092 PYGLIB_DEFINE_TYPE ("gi.UnresolvedInfo", PyGIUnresolvedInfo_Type, PyGIBaseInfo);
2094 static PyMethodDef _PyGIUnresolvedInfo_methods[] = {
2099 PYGLIB_DEFINE_TYPE ("gi.VFuncInfo", PyGIVFuncInfo_Type, PyGICallableInfo);
2102 _wrap_g_vfunc_info_get_flags (PyGIBaseInfo *self)
2104 return PYGLIB_PyLong_FromLong (g_vfunc_info_get_flags ((GIVFuncInfo *) self->info));
2108 _wrap_g_vfunc_info_get_offset (PyGIBaseInfo *self)
2110 return PYGLIB_PyLong_FromLong (g_vfunc_info_get_offset ((GIVFuncInfo *) self->info));
2114 _wrap_g_vfunc_info_get_signal (PyGIBaseInfo *self)
2116 return _get_child_info (self, g_vfunc_info_get_signal);
2120 _wrap_g_vfunc_info_get_invoker (PyGIBaseInfo *self)
2122 return _get_child_info (self, g_vfunc_info_get_invoker);
2125 static PyMethodDef _PyGIVFuncInfo_methods[] = {
2126 { "get_flags", (PyCFunction) _wrap_g_vfunc_info_get_flags, METH_NOARGS },
2127 { "get_offset", (PyCFunction) _wrap_g_vfunc_info_get_offset, METH_NOARGS },
2128 { "get_signal", (PyCFunction) _wrap_g_vfunc_info_get_signal, METH_NOARGS },
2129 { "get_invoker", (PyCFunction) _wrap_g_vfunc_info_get_invoker, METH_NOARGS },
2135 PYGLIB_DEFINE_TYPE ("gi.UnionInfo", PyGIUnionInfo_Type, PyGIBaseInfo);
2138 _wrap_g_union_info_get_fields (PyGIBaseInfo *self)
2140 return _make_infos_tuple (self, g_union_info_get_n_fields, g_union_info_get_field);
2144 _wrap_g_union_info_get_methods (PyGIBaseInfo *self)
2146 return _make_infos_tuple (self, g_union_info_get_n_methods, g_union_info_get_method);
2149 static PyMethodDef _PyGIUnionInfo_methods[] = {
2150 { "get_fields", (PyCFunction) _wrap_g_union_info_get_fields, METH_NOARGS },
2151 { "get_methods", (PyCFunction) _wrap_g_union_info_get_methods, METH_NOARGS },
2158 _pygi_g_base_info_get_fullname (GIBaseInfo *info)
2160 GIBaseInfo *container_info;
2163 container_info = g_base_info_get_container (info);
2164 if (container_info != NULL) {
2165 fullname = g_strdup_printf ("%s.%s.%s",
2166 g_base_info_get_namespace (container_info),
2167 _safe_base_info_get_name (container_info),
2168 _safe_base_info_get_name (info));
2170 fullname = g_strdup_printf ("%s.%s",
2171 g_base_info_get_namespace (info),
2172 _safe_base_info_get_name (info));
2175 if (fullname == NULL) {
2184 _pygi_info_register_types (PyObject *m)
2186 #define _PyGI_REGISTER_TYPE(m, type, cname, base) \
2187 Py_TYPE(&type) = &PyType_Type; \
2188 type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE); \
2189 type.tp_weaklistoffset = offsetof(PyGIBaseInfo, inst_weakreflist); \
2190 type.tp_methods = _PyGI##cname##_methods; \
2191 type.tp_base = &base; \
2192 if (PyType_Ready(&type)) \
2194 if (PyModule_AddObject(m, #cname, (PyObject *)&type)) \
2197 Py_TYPE(&PyGIBaseInfo_Type) = &PyType_Type;
2199 PyGIBaseInfo_Type.tp_dealloc = (destructor) _base_info_dealloc;
2200 PyGIBaseInfo_Type.tp_repr = (reprfunc) _base_info_repr;
2201 PyGIBaseInfo_Type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
2202 PyGIBaseInfo_Type.tp_weaklistoffset = offsetof(PyGIBaseInfo, inst_weakreflist);
2203 PyGIBaseInfo_Type.tp_methods = _PyGIBaseInfo_methods;
2204 PyGIBaseInfo_Type.tp_richcompare = (richcmpfunc)_base_info_richcompare;
2205 PyGIBaseInfo_Type.tp_getset = _base_info_getsets;
2206 PyGIBaseInfo_Type.tp_getattro = (getattrofunc) _base_info_getattro;
2208 if (PyType_Ready(&PyGIBaseInfo_Type))
2210 if (PyModule_AddObject(m, "BaseInfo", (PyObject *)&PyGIBaseInfo_Type))
2213 _PyGI_REGISTER_TYPE (m, PyGICallableInfo_Type, CallableInfo,
2215 PyGICallableInfo_Type.tp_call = (ternaryfunc) _callable_info_call;
2216 PyGICallableInfo_Type.tp_dealloc = (destructor) _callable_info_dealloc;
2218 _PyGI_REGISTER_TYPE (m, PyGIFunctionInfo_Type, FunctionInfo,
2219 PyGICallableInfo_Type);
2220 PyGIFunctionInfo_Type.tp_call = (ternaryfunc) _function_info_call;
2221 PyGIFunctionInfo_Type.tp_descr_get = (descrgetfunc) _function_info_descr_get;
2223 _PyGI_REGISTER_TYPE (m, PyGIVFuncInfo_Type, VFuncInfo,
2224 PyGICallableInfo_Type);
2225 PyGIVFuncInfo_Type.tp_descr_get = (descrgetfunc) _vfunc_info_descr_get;
2227 _PyGI_REGISTER_TYPE (m, PyGISignalInfo_Type, SignalInfo,
2228 PyGICallableInfo_Type);
2230 _PyGI_REGISTER_TYPE (m, PyGIUnresolvedInfo_Type, UnresolvedInfo,
2232 _PyGI_REGISTER_TYPE (m, PyGICallbackInfo_Type, CallbackInfo,
2234 _PyGI_REGISTER_TYPE (m, PyGIRegisteredTypeInfo_Type, RegisteredTypeInfo,
2236 _PyGI_REGISTER_TYPE (m, PyGIStructInfo_Type, StructInfo,
2237 PyGIRegisteredTypeInfo_Type);
2238 _PyGI_REGISTER_TYPE (m, PyGIEnumInfo_Type, EnumInfo,
2239 PyGIRegisteredTypeInfo_Type);
2240 _PyGI_REGISTER_TYPE (m, PyGIObjectInfo_Type, ObjectInfo,
2241 PyGIRegisteredTypeInfo_Type);
2242 _PyGI_REGISTER_TYPE (m, PyGIInterfaceInfo_Type, InterfaceInfo,
2243 PyGIRegisteredTypeInfo_Type);
2244 _PyGI_REGISTER_TYPE (m, PyGIConstantInfo_Type, ConstantInfo,
2246 _PyGI_REGISTER_TYPE (m, PyGIValueInfo_Type, ValueInfo,
2248 _PyGI_REGISTER_TYPE (m, PyGIFieldInfo_Type, FieldInfo,
2250 _PyGI_REGISTER_TYPE (m, PyGIUnionInfo_Type, UnionInfo,
2251 PyGIRegisteredTypeInfo_Type);
2252 _PyGI_REGISTER_TYPE (m, PyGIErrorDomainInfo_Type, ErrorDomainInfo,
2254 _PyGI_REGISTER_TYPE (m, PyGIPropertyInfo_Type, PropertyInfo,
2256 _PyGI_REGISTER_TYPE (m, PyGIArgInfo_Type, ArgInfo,
2258 _PyGI_REGISTER_TYPE (m, PyGITypeInfo_Type, TypeInfo,
2261 #undef _PyGI_REGISTER_TYPE
2263 #define _PyGI_ENUM_BEGIN(name) \
2265 const char *__enum_name = #name; \
2266 PyObject *__enum_value = NULL; \
2267 PyObject *__new_enum_cls = NULL; \
2268 PyObject *__enum_instance_dict = PyDict_New(); \
2269 PyObject *__module_name = PyObject_GetAttrString (m, "__name__"); \
2270 PyDict_SetItemString (__enum_instance_dict, "__module__", __module_name); \
2271 Py_DECREF (__module_name);
2273 #define _PyGI_ENUM_ADD_VALUE(prefix, name) \
2274 __enum_value = PYGLIB_PyLong_FromLong (prefix##_##name); \
2275 if (PyDict_SetItemString(__enum_instance_dict, #name, __enum_value)) { \
2276 Py_DECREF (__enum_instance_dict); \
2277 Py_DECREF (__enum_value); \
2280 Py_DECREF (__enum_value);
2282 #define _PyGI_ENUM_END \
2283 __new_enum_cls = PyObject_CallFunction ((PyObject *)&PyType_Type, "s(O)O", \
2284 __enum_name, (PyObject *)&PyType_Type, \
2285 __enum_instance_dict); \
2286 Py_DECREF (__enum_instance_dict); \
2287 PyModule_AddObject (m, __enum_name, __new_enum_cls); /* steals ref */ \
2292 _PyGI_ENUM_BEGIN (Direction)
2293 _PyGI_ENUM_ADD_VALUE (GI_DIRECTION, IN)
2294 _PyGI_ENUM_ADD_VALUE (GI_DIRECTION, OUT)
2295 _PyGI_ENUM_ADD_VALUE (GI_DIRECTION, INOUT)
2300 _PyGI_ENUM_BEGIN (Transfer)
2301 _PyGI_ENUM_ADD_VALUE (GI_TRANSFER, NOTHING)
2302 _PyGI_ENUM_ADD_VALUE (GI_TRANSFER, CONTAINER)
2303 _PyGI_ENUM_ADD_VALUE (GI_TRANSFER, EVERYTHING)
2307 _PyGI_ENUM_BEGIN (ArrayType)
2308 _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE, C)
2309 _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE, ARRAY)
2310 _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE, PTR_ARRAY)
2311 _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE, BYTE_ARRAY)
2315 _PyGI_ENUM_BEGIN (ScopeType)
2316 _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE, INVALID)
2317 _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE, CALL)
2318 _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE, ASYNC)
2319 _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE, NOTIFIED)
2322 /* GIVFuncInfoFlags */
2323 _PyGI_ENUM_BEGIN (VFuncInfoFlags)
2324 _PyGI_ENUM_ADD_VALUE (GI_VFUNC_MUST, CHAIN_UP)
2325 _PyGI_ENUM_ADD_VALUE (GI_VFUNC_MUST, OVERRIDE)
2326 _PyGI_ENUM_ADD_VALUE (GI_VFUNC_MUST, NOT_OVERRIDE)
2329 /* GIFieldInfoFlags */
2330 _PyGI_ENUM_BEGIN (FieldInfoFlags)
2331 _PyGI_ENUM_ADD_VALUE (GI_FIELD, IS_READABLE)
2332 _PyGI_ENUM_ADD_VALUE (GI_FIELD, IS_WRITABLE)
2335 /* GIFunctionInfoFlags */
2336 _PyGI_ENUM_BEGIN (FunctionInfoFlags)
2337 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, IS_METHOD)
2338 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, IS_CONSTRUCTOR)
2339 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, IS_GETTER)
2340 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, IS_SETTER)
2341 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, WRAPS_VFUNC)
2342 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION, THROWS)
2346 _PyGI_ENUM_BEGIN (TypeTag)
2348 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, VOID)
2349 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, BOOLEAN)
2350 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, INT8)
2351 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UINT8)
2352 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, INT16)
2353 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UINT16)
2354 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, INT32)
2355 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UINT32)
2356 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, INT64)
2357 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UINT64)
2358 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, FLOAT)
2359 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, DOUBLE)
2360 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, GTYPE)
2361 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UTF8)
2362 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, FILENAME)
2364 /* Non-basic types; compare with G_TYPE_TAG_IS_BASIC */
2365 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, ARRAY)
2366 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, INTERFACE)
2367 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, GLIST)
2368 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, GSLIST)
2369 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, GHASH)
2370 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, ERROR)
2372 /* Another basic type */
2373 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG, UNICHAR)
2377 _PyGI_ENUM_BEGIN (InfoType)
2378 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, INVALID)
2379 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, FUNCTION)
2380 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, CALLBACK)
2381 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, STRUCT)
2382 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, BOXED)
2383 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, ENUM)
2384 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, FLAGS)
2385 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, OBJECT)
2386 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, INTERFACE)
2387 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, CONSTANT)
2388 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, INVALID_0)
2389 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, UNION)
2390 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, VALUE)
2391 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, SIGNAL)
2392 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, VFUNC)
2393 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, PROPERTY)
2394 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, FIELD)
2395 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, ARG)
2396 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, TYPE)
2397 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE, UNRESOLVED)
2400 #undef _PyGI_ENUM_BEGIN
2401 #undef _PyGI_ENUM_ADD_VALUE
2402 #undef _PyGI_ENUM_END