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-python-compat.h"
24 #include "pygi-info.h"
25 #include "pygi-cache.h"
26 #include "pygi-invoke.h"
27 #include "pygi-type.h"
28 #include "pygi-argument.h"
29 #include "pygi-util.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
= PYGLIB_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 if (self
->cache
!= NULL
)
181 pygi_callable_cache_free ( (PyGICallableCache
*) self
->cache
);
183 Py_TYPE (self
)->tp_free ((PyObject
*)self
);
187 _base_info_repr (PyGIBaseInfo
*self
)
190 return PYGLIB_PyUnicode_FromFormat ("%s(%s)",
191 Py_TYPE( (PyObject
*) self
)->tp_name
,
192 _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_skip_return (PyGIBaseInfo
*self
)
735 return PyBool_FromLong (g_callable_info_skip_return (self
->info
));
739 _wrap_g_callable_info_get_return_attribute (PyGIBaseInfo
*self
, PyObject
*py_name
)
744 if (!PYGLIB_PyUnicode_Check (py_name
)) {
745 PyErr_SetString (PyExc_TypeError
, "expected string name");
749 name
= PYGLIB_PyUnicode_AsString (py_name
);
750 attr
= g_callable_info_get_return_attribute (self
->info
, name
);
752 return PYGLIB_PyUnicode_FromString (
753 g_callable_info_get_return_attribute (self
->info
, name
));
755 PyErr_Format(PyExc_AttributeError
, "return attribute %s not found", name
);
761 _wrap_g_callable_info_can_throw_gerror (PyGIBaseInfo
*self
)
763 if (g_callable_info_can_throw_gerror (self
->info
))
769 static PyMethodDef _PyGICallableInfo_methods
[] = {
770 { "invoke", (PyCFunction
) _wrap_g_callable_info_invoke
, METH_VARARGS
| METH_KEYWORDS
},
771 { "get_arguments", (PyCFunction
) _wrap_g_callable_info_get_arguments
, METH_NOARGS
},
772 { "get_return_type", (PyCFunction
) _wrap_g_callable_info_get_return_type
, METH_NOARGS
},
773 { "get_caller_owns", (PyCFunction
) _wrap_g_callable_info_get_caller_owns
, METH_NOARGS
},
774 { "may_return_null", (PyCFunction
) _wrap_g_callable_info_may_return_null
, METH_NOARGS
},
775 { "skip_return", (PyCFunction
) _wrap_g_callable_info_skip_return
, METH_NOARGS
},
776 { "get_return_attribute", (PyCFunction
) _wrap_g_callable_info_get_return_attribute
, METH_O
},
777 { "can_throw_gerror", (PyCFunction
) _wrap_g_callable_info_can_throw_gerror
, METH_NOARGS
},
782 PYGLIB_DEFINE_TYPE ("gi.CallbackInfo", PyGICallbackInfo_Type
, PyGICallableInfo
);
784 static PyMethodDef _PyGICallbackInfo_methods
[] = {
788 /* ErrorDomainInfo */
789 PYGLIB_DEFINE_TYPE ("gi.ErrorDomainInfo", PyGIErrorDomainInfo_Type
, PyGIBaseInfo
);
791 static PyMethodDef _PyGIErrorDomainInfo_methods
[] = {
796 PYGLIB_DEFINE_TYPE ("gi.SignalInfo", PyGISignalInfo_Type
, PyGICallableInfo
);
799 _wrap_g_signal_info_get_flags (PyGIBaseInfo
*self
)
801 return PYGLIB_PyLong_FromLong (
802 g_signal_info_get_flags ((GISignalInfo
*)self
->info
) );
806 _wrap_g_signal_info_get_class_closure (PyGIBaseInfo
*self
)
808 return _get_child_info (self
, g_signal_info_get_class_closure
);
812 _wrap_g_signal_info_true_stops_emit (PyGIBaseInfo
*self
)
814 return PyBool_FromLong (
815 g_signal_info_true_stops_emit ((GISignalInfo
*)self
->info
) );
818 static PyMethodDef _PyGISignalInfo_methods
[] = {
819 { "get_flags", (PyCFunction
) _wrap_g_signal_info_get_flags
, METH_NOARGS
},
820 { "get_class_closure", (PyCFunction
) _wrap_g_signal_info_get_class_closure
, METH_NOARGS
},
821 { "true_stops_emit", (PyCFunction
) _wrap_g_signal_info_true_stops_emit
, METH_NOARGS
},
826 PYGLIB_DEFINE_TYPE ("gi.PropertyInfo", PyGIPropertyInfo_Type
, PyGIBaseInfo
);
829 _wrap_g_property_info_get_flags (PyGIBaseInfo
*self
)
831 return PYGLIB_PyLong_FromLong (
832 g_property_info_get_flags ((GIPropertyInfo
*)self
->info
) );
836 _wrap_g_property_info_get_type (PyGIBaseInfo
*self
)
838 return _get_child_info (self
, g_property_info_get_type
);
842 _wrap_g_property_info_get_ownership_transfer (PyGIBaseInfo
*self
)
844 return PYGLIB_PyLong_FromLong (
845 g_property_info_get_ownership_transfer ((GIPropertyInfo
*)self
->info
) );
848 static PyMethodDef _PyGIPropertyInfo_methods
[] = {
849 { "get_flags", (PyCFunction
) _wrap_g_property_info_get_flags
, METH_NOARGS
},
850 { "get_type", (PyCFunction
) _wrap_g_property_info_get_type
, METH_NOARGS
},
851 { "get_ownership_transfer", (PyCFunction
) _wrap_g_property_info_get_ownership_transfer
, METH_NOARGS
},
857 PYGLIB_DEFINE_TYPE ("gi.ArgInfo", PyGIArgInfo_Type
, PyGIBaseInfo
);
860 _wrap_g_arg_info_get_direction (PyGIBaseInfo
*self
)
862 return PYGLIB_PyLong_FromLong (
863 g_arg_info_get_direction ((GIArgInfo
*)self
->info
) );
867 _wrap_g_arg_info_is_caller_allocates (PyGIBaseInfo
*self
)
869 return PyBool_FromLong (
870 g_arg_info_is_caller_allocates ((GIArgInfo
*)self
->info
) );
874 _wrap_g_arg_info_is_return_value (PyGIBaseInfo
*self
)
876 return PyBool_FromLong (
877 g_arg_info_is_return_value ((GIArgInfo
*)self
->info
) );
881 _wrap_g_arg_info_is_optional (PyGIBaseInfo
*self
)
883 return PyBool_FromLong (
884 g_arg_info_is_optional ((GIArgInfo
*)self
->info
) );
888 _wrap_g_arg_info_may_be_null (PyGIBaseInfo
*self
)
890 return PyBool_FromLong (
891 g_arg_info_may_be_null ((GIArgInfo
*)self
->info
) );
895 _wrap_g_arg_info_get_ownership_transfer (PyGIBaseInfo
*self
)
897 return PYGLIB_PyLong_FromLong (
898 g_arg_info_get_ownership_transfer ((GIArgInfo
*)self
->info
) );
902 _wrap_g_arg_info_get_scope (PyGIBaseInfo
*self
)
904 return PYGLIB_PyLong_FromLong (
905 g_arg_info_get_scope ((GIArgInfo
*)self
->info
) );
909 _wrap_g_arg_info_get_closure (PyGIBaseInfo
*self
)
911 return PYGLIB_PyLong_FromLong (
912 g_arg_info_get_closure ((GIArgInfo
*)self
->info
) );
916 _wrap_g_arg_info_get_destroy (PyGIBaseInfo
*self
)
918 return PYGLIB_PyLong_FromLong (
919 g_arg_info_get_destroy ((GIArgInfo
*)self
->info
) );
923 _wrap_g_arg_info_get_type (PyGIBaseInfo
*self
)
925 return _get_child_info (self
, g_arg_info_get_type
);
928 static PyMethodDef _PyGIArgInfo_methods
[] = {
929 { "get_direction", (PyCFunction
) _wrap_g_arg_info_get_direction
, METH_NOARGS
},
930 { "is_caller_allocates", (PyCFunction
) _wrap_g_arg_info_is_caller_allocates
, METH_NOARGS
},
931 { "is_return_value", (PyCFunction
) _wrap_g_arg_info_is_return_value
, METH_NOARGS
},
932 { "is_optional", (PyCFunction
) _wrap_g_arg_info_is_optional
, METH_NOARGS
},
933 { "may_be_null", (PyCFunction
) _wrap_g_arg_info_may_be_null
, METH_NOARGS
},
934 { "get_ownership_transfer", (PyCFunction
) _wrap_g_arg_info_get_ownership_transfer
, METH_NOARGS
},
935 { "get_scope", (PyCFunction
) _wrap_g_arg_info_get_scope
, METH_NOARGS
},
936 { "get_closure", (PyCFunction
) _wrap_g_arg_info_get_closure
, METH_NOARGS
},
937 { "get_destroy", (PyCFunction
) _wrap_g_arg_info_get_destroy
, METH_NOARGS
},
938 { "get_type", (PyCFunction
) _wrap_g_arg_info_get_type
, METH_NOARGS
},
944 PYGLIB_DEFINE_TYPE ("gi.TypeInfo", PyGITypeInfo_Type
, PyGIBaseInfo
);
947 _wrap_g_type_info_is_pointer (PyGIBaseInfo
*self
)
949 return PyBool_FromLong (g_type_info_is_pointer (self
->info
));
953 _wrap_g_type_info_get_tag (PyGIBaseInfo
*self
)
955 return PYGLIB_PyLong_FromLong (g_type_info_get_tag (self
->info
));
959 _wrap_g_type_info_get_tag_as_string (PyGIBaseInfo
*self
)
961 GITypeTag tag
= g_type_info_get_tag (self
->info
);
962 return PYGLIB_PyUnicode_FromString (g_type_tag_to_string(tag
));
966 _wrap_g_type_info_get_param_type (PyGIBaseInfo
*self
, PyObject
*py_n
)
972 if (!PYGLIB_PyLong_Check (py_n
)) {
973 PyErr_SetString(PyExc_TypeError
, "expected integer value");
977 n
= PYGLIB_PyLong_AsLong (py_n
);
978 info
= (GIBaseInfo
*) g_type_info_get_param_type ( (GITypeInfo
*) self
->info
, n
);
983 py_info
= _pygi_info_new (info
);
984 g_base_info_unref (info
);
989 _wrap_g_type_info_get_interface (PyGIBaseInfo
*self
)
991 return _get_child_info (self
, g_type_info_get_interface
);
995 _wrap_g_type_info_get_array_length (PyGIBaseInfo
*self
)
997 return PYGLIB_PyLong_FromLong (g_type_info_get_array_length (self
->info
));
1001 _wrap_g_type_info_get_array_fixed_size (PyGIBaseInfo
*self
)
1003 return PYGLIB_PyLong_FromLong (g_type_info_get_array_fixed_size (self
->info
));
1007 _wrap_g_type_info_is_zero_terminated (PyGIBaseInfo
*self
)
1009 return PyBool_FromLong (g_type_info_is_zero_terminated (self
->info
));
1013 _wrap_g_type_info_get_array_type (PyGIBaseInfo
*self
)
1015 return PYGLIB_PyLong_FromLong (g_type_info_get_array_type (self
->info
));
1018 static PyMethodDef _PyGITypeInfo_methods
[] = {
1019 { "is_pointer", (PyCFunction
) _wrap_g_type_info_is_pointer
, METH_NOARGS
},
1020 { "get_tag", (PyCFunction
) _wrap_g_type_info_get_tag
, METH_NOARGS
},
1021 { "get_tag_as_string", (PyCFunction
) _wrap_g_type_info_get_tag_as_string
, METH_NOARGS
},
1022 { "get_param_type", (PyCFunction
) _wrap_g_type_info_get_param_type
, METH_O
},
1023 { "get_interface", (PyCFunction
) _wrap_g_type_info_get_interface
, METH_NOARGS
},
1024 { "get_array_length", (PyCFunction
) _wrap_g_type_info_get_array_length
, METH_NOARGS
},
1025 { "get_array_fixed_size", (PyCFunction
) _wrap_g_type_info_get_array_fixed_size
, METH_NOARGS
},
1026 { "is_zero_terminated", (PyCFunction
) _wrap_g_type_info_is_zero_terminated
, METH_NOARGS
},
1027 { "get_array_type", (PyCFunction
) _wrap_g_type_info_get_array_type
, METH_NOARGS
},
1033 PYGLIB_DEFINE_TYPE ("gi.FunctionInfo", PyGIFunctionInfo_Type
, PyGICallableInfo
);
1036 _wrap_g_function_info_is_constructor (PyGIBaseInfo
*self
)
1038 GIFunctionInfoFlags flags
;
1039 gboolean is_constructor
;
1041 flags
= g_function_info_get_flags ( (GIFunctionInfo
*) self
->info
);
1042 is_constructor
= flags
& GI_FUNCTION_IS_CONSTRUCTOR
;
1044 return PyBool_FromLong (is_constructor
);
1048 _wrap_g_function_info_is_method (PyGIBaseInfo
*self
)
1050 GIFunctionInfoFlags flags
;
1053 flags
= g_function_info_get_flags ( (GIFunctionInfo
*) self
->info
);
1054 is_method
= flags
& GI_FUNCTION_IS_METHOD
;
1056 return PyBool_FromLong (is_method
);
1060 _pygi_g_type_tag_size (GITypeTag type_tag
)
1065 case GI_TYPE_TAG_BOOLEAN
:
1066 size
= sizeof (gboolean
);
1068 case GI_TYPE_TAG_INT8
:
1069 case GI_TYPE_TAG_UINT8
:
1070 size
= sizeof (gint8
);
1072 case GI_TYPE_TAG_INT16
:
1073 case GI_TYPE_TAG_UINT16
:
1074 size
= sizeof (gint16
);
1076 case GI_TYPE_TAG_INT32
:
1077 case GI_TYPE_TAG_UINT32
:
1078 size
= sizeof (gint32
);
1080 case GI_TYPE_TAG_INT64
:
1081 case GI_TYPE_TAG_UINT64
:
1082 size
= sizeof (gint64
);
1084 case GI_TYPE_TAG_FLOAT
:
1085 size
= sizeof (gfloat
);
1087 case GI_TYPE_TAG_DOUBLE
:
1088 size
= sizeof (gdouble
);
1090 case GI_TYPE_TAG_GTYPE
:
1091 size
= sizeof (GType
);
1093 case GI_TYPE_TAG_UNICHAR
:
1094 size
= sizeof (gunichar
);
1096 case GI_TYPE_TAG_VOID
:
1097 case GI_TYPE_TAG_UTF8
:
1098 case GI_TYPE_TAG_FILENAME
:
1099 case GI_TYPE_TAG_ARRAY
:
1100 case GI_TYPE_TAG_INTERFACE
:
1101 case GI_TYPE_TAG_GLIST
:
1102 case GI_TYPE_TAG_GSLIST
:
1103 case GI_TYPE_TAG_GHASH
:
1104 case GI_TYPE_TAG_ERROR
:
1105 PyErr_Format (PyExc_TypeError
,
1106 "Unable to know the size (assuming %s is not a pointer)",
1107 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
);
1169 GITypeTag enum_type_tag
;
1171 enum_type_tag
= g_enum_info_get_storage_type ( (GIEnumInfo
*) info
);
1172 size
= _pygi_g_type_tag_size (enum_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
);
1218 _wrap_g_function_info_get_symbol (PyGIBaseInfo
*self
)
1220 return _get_info_string (self
, g_function_info_get_symbol
);
1224 _wrap_g_function_info_get_flags (PyGIBaseInfo
*self
)
1226 return PYGLIB_PyLong_FromLong (g_function_info_get_flags (self
->info
));
1230 _wrap_g_function_info_get_property (PyGIBaseInfo
*self
)
1232 return _get_child_info (self
, g_function_info_get_property
);
1236 _wrap_g_function_info_get_vfunc (PyGIBaseInfo
*self
)
1238 return _get_child_info (self
, g_function_info_get_vfunc
);
1241 static PyMethodDef _PyGIFunctionInfo_methods
[] = {
1242 { "is_constructor", (PyCFunction
) _wrap_g_function_info_is_constructor
, METH_NOARGS
},
1243 { "is_method", (PyCFunction
) _wrap_g_function_info_is_method
, METH_NOARGS
},
1244 { "get_symbol", (PyCFunction
) _wrap_g_function_info_get_symbol
, METH_NOARGS
},
1245 { "get_flags", (PyCFunction
) _wrap_g_function_info_get_flags
, METH_NOARGS
},
1246 { "get_property", (PyCFunction
) _wrap_g_function_info_get_property
, METH_NOARGS
},
1247 { "get_vfunc", (PyCFunction
) _wrap_g_function_info_get_vfunc
, METH_NOARGS
},
1251 /* RegisteredTypeInfo */
1252 PYGLIB_DEFINE_TYPE ("gi.RegisteredTypeInfo", PyGIRegisteredTypeInfo_Type
, PyGIBaseInfo
);
1255 _wrap_g_registered_type_info_get_type_name (PyGIBaseInfo
*self
)
1257 return _get_info_string (self
, g_registered_type_info_get_type_name
);
1261 _wrap_g_registered_type_info_get_type_init (PyGIBaseInfo
*self
)
1263 return _get_info_string (self
, g_registered_type_info_get_type_init
);
1267 _wrap_g_registered_type_info_get_g_type (PyGIBaseInfo
*self
)
1271 type
= g_registered_type_info_get_g_type ( (GIRegisteredTypeInfo
*) self
->info
);
1273 return pyg_type_wrapper_new (type
);
1276 static PyMethodDef _PyGIRegisteredTypeInfo_methods
[] = {
1277 { "get_type_name", (PyCFunction
) _wrap_g_registered_type_info_get_type_name
, METH_NOARGS
},
1278 { "get_type_init", (PyCFunction
) _wrap_g_registered_type_info_get_type_init
, METH_NOARGS
},
1279 { "get_g_type", (PyCFunction
) _wrap_g_registered_type_info_get_g_type
, METH_NOARGS
},
1285 PYGLIB_DEFINE_TYPE ("StructInfo", PyGIStructInfo_Type
, PyGIBaseInfo
);
1288 _wrap_g_struct_info_get_fields (PyGIBaseInfo
*self
)
1290 return _make_infos_tuple (self
, g_struct_info_get_n_fields
, g_struct_info_get_field
);
1294 _wrap_g_struct_info_get_methods (PyGIBaseInfo
*self
)
1296 return _make_infos_tuple (self
, g_struct_info_get_n_methods
, g_struct_info_get_method
);
1300 _wrap_g_struct_info_get_size (PyGIBaseInfo
*self
)
1302 return PYGLIB_PyLong_FromSize_t (g_struct_info_get_size (self
->info
));
1306 _wrap_g_struct_info_get_alignment (PyGIBaseInfo
*self
)
1308 return PYGLIB_PyLong_FromSize_t (g_struct_info_get_alignment (self
->info
));
1312 _wrap_g_struct_info_is_gtype_struct (PyGIBaseInfo
*self
)
1314 return PyBool_FromLong (g_struct_info_is_gtype_struct (self
->info
));
1318 _wrap_g_struct_info_is_foreign (PyGIBaseInfo
*self
)
1320 return PyBool_FromLong (g_struct_info_is_foreign (self
->info
));
1323 static PyMethodDef _PyGIStructInfo_methods
[] = {
1324 { "get_fields", (PyCFunction
) _wrap_g_struct_info_get_fields
, METH_NOARGS
},
1325 { "get_methods", (PyCFunction
) _wrap_g_struct_info_get_methods
, METH_NOARGS
},
1326 { "get_size", (PyCFunction
) _wrap_g_struct_info_get_size
, METH_NOARGS
},
1327 { "get_alignment", (PyCFunction
) _wrap_g_struct_info_get_alignment
, METH_NOARGS
},
1328 { "is_gtype_struct", (PyCFunction
) _wrap_g_struct_info_is_gtype_struct
, METH_NOARGS
},
1329 { "is_foreign", (PyCFunction
) _wrap_g_struct_info_is_foreign
, METH_NOARGS
},
1334 pygi_g_struct_info_is_simple (GIStructInfo
*struct_info
)
1337 gsize n_field_infos
;
1342 n_field_infos
= g_struct_info_get_n_fields (struct_info
);
1344 for (i
= 0; i
< n_field_infos
&& is_simple
; i
++) {
1345 GIFieldInfo
*field_info
;
1346 GITypeInfo
*field_type_info
;
1347 GITypeTag field_type_tag
;
1349 field_info
= g_struct_info_get_field (struct_info
, i
);
1350 field_type_info
= g_field_info_get_type (field_info
);
1353 field_type_tag
= g_type_info_get_tag (field_type_info
);
1355 switch (field_type_tag
) {
1356 case GI_TYPE_TAG_BOOLEAN
:
1357 case GI_TYPE_TAG_INT8
:
1358 case GI_TYPE_TAG_UINT8
:
1359 case GI_TYPE_TAG_INT16
:
1360 case GI_TYPE_TAG_UINT16
:
1361 case GI_TYPE_TAG_INT32
:
1362 case GI_TYPE_TAG_UINT32
:
1363 case GI_TYPE_TAG_INT64
:
1364 case GI_TYPE_TAG_UINT64
:
1365 case GI_TYPE_TAG_FLOAT
:
1366 case GI_TYPE_TAG_DOUBLE
:
1367 case GI_TYPE_TAG_UNICHAR
:
1368 if (g_type_info_is_pointer (field_type_info
)) {
1372 case GI_TYPE_TAG_VOID
:
1373 case GI_TYPE_TAG_GTYPE
:
1374 case GI_TYPE_TAG_ERROR
:
1375 case GI_TYPE_TAG_UTF8
:
1376 case GI_TYPE_TAG_FILENAME
:
1377 case GI_TYPE_TAG_ARRAY
:
1378 case GI_TYPE_TAG_GLIST
:
1379 case GI_TYPE_TAG_GSLIST
:
1380 case GI_TYPE_TAG_GHASH
:
1383 case GI_TYPE_TAG_INTERFACE
:
1386 GIInfoType info_type
;
1388 info
= g_type_info_get_interface (field_type_info
);
1389 info_type
= g_base_info_get_type (info
);
1391 switch (info_type
) {
1392 case GI_INFO_TYPE_STRUCT
:
1393 if (g_type_info_is_pointer (field_type_info
)) {
1396 is_simple
= pygi_g_struct_info_is_simple ( (GIStructInfo
*) info
);
1399 case GI_INFO_TYPE_UNION
:
1403 case GI_INFO_TYPE_ENUM
:
1404 case GI_INFO_TYPE_FLAGS
:
1405 if (g_type_info_is_pointer (field_type_info
)) {
1409 case GI_INFO_TYPE_BOXED
:
1410 case GI_INFO_TYPE_OBJECT
:
1411 case GI_INFO_TYPE_CALLBACK
:
1412 case GI_INFO_TYPE_INTERFACE
:
1415 case GI_INFO_TYPE_VFUNC
:
1416 case GI_INFO_TYPE_INVALID
:
1417 case GI_INFO_TYPE_FUNCTION
:
1418 case GI_INFO_TYPE_CONSTANT
:
1419 case GI_INFO_TYPE_VALUE
:
1420 case GI_INFO_TYPE_SIGNAL
:
1421 case GI_INFO_TYPE_PROPERTY
:
1422 case GI_INFO_TYPE_FIELD
:
1423 case GI_INFO_TYPE_ARG
:
1424 case GI_INFO_TYPE_TYPE
:
1425 case GI_INFO_TYPE_UNRESOLVED
:
1427 g_assert_not_reached();
1431 g_base_info_unref (info
);
1435 g_assert_not_reached();
1439 g_base_info_unref ( (GIBaseInfo
*) field_type_info
);
1440 g_base_info_unref ( (GIBaseInfo
*) field_info
);
1448 PYGLIB_DEFINE_TYPE ("gi.EnumInfo", PyGIEnumInfo_Type
, PyGIBaseInfo
);
1451 _wrap_g_enum_info_get_values (PyGIBaseInfo
*self
)
1453 return _make_infos_tuple (self
, g_enum_info_get_n_values
, g_enum_info_get_value
);
1457 _wrap_g_enum_info_is_flags (PyGIBaseInfo
*self
)
1459 GIInfoType info_type
= g_base_info_get_type ((GIBaseInfo
*) self
->info
);
1461 if (info_type
== GI_INFO_TYPE_ENUM
) {
1463 } else if (info_type
== GI_INFO_TYPE_FLAGS
) {
1466 g_assert_not_reached();
1471 _wrap_g_enum_info_get_methods (PyGIBaseInfo
*self
)
1473 return _make_infos_tuple (self
, g_enum_info_get_n_methods
, g_enum_info_get_method
);
1477 _wrap_g_enum_info_get_storage_type (PyGIBaseInfo
*self
)
1479 return PYGLIB_PyLong_FromLong (g_enum_info_get_storage_type ((GIBaseInfo
*) self
->info
));
1482 static PyMethodDef _PyGIEnumInfo_methods
[] = {
1483 { "get_values", (PyCFunction
) _wrap_g_enum_info_get_values
, METH_NOARGS
},
1484 { "is_flags", (PyCFunction
) _wrap_g_enum_info_is_flags
, METH_NOARGS
},
1485 { "get_methods", (PyCFunction
) _wrap_g_enum_info_get_methods
, METH_NOARGS
},
1486 { "get_storage_type", (PyCFunction
) _wrap_g_enum_info_get_storage_type
, METH_NOARGS
},
1492 PYGLIB_DEFINE_TYPE ("ObjectInfo", PyGIObjectInfo_Type
, PyGIBaseInfo
);
1495 _wrap_g_object_info_get_parent (PyGIBaseInfo
*self
)
1497 return _get_child_info (self
, g_object_info_get_parent
);
1501 _wrap_g_object_info_get_methods (PyGIBaseInfo
*self
)
1503 return _make_infos_tuple (self
, g_object_info_get_n_methods
, g_object_info_get_method
);
1507 _wrap_g_object_info_find_method (PyGIBaseInfo
*self
, PyObject
*py_name
)
1509 return _get_child_info_by_name (self
, py_name
, g_object_info_find_method
);
1513 _wrap_g_object_info_get_fields (PyGIBaseInfo
*self
)
1515 return _make_infos_tuple (self
, g_object_info_get_n_fields
, g_object_info_get_field
);
1519 _wrap_g_object_info_get_properties (PyGIBaseInfo
*self
)
1521 return _make_infos_tuple (self
, g_object_info_get_n_properties
, g_object_info_get_property
);
1525 _wrap_g_object_info_get_signals (PyGIBaseInfo
*self
)
1527 return _make_infos_tuple (self
, g_object_info_get_n_signals
, g_object_info_get_signal
);
1531 _wrap_g_object_info_get_interfaces (PyGIBaseInfo
*self
)
1533 return _make_infos_tuple (self
, g_object_info_get_n_interfaces
, g_object_info_get_interface
);
1537 _wrap_g_object_info_get_constants (PyGIBaseInfo
*self
)
1539 return _make_infos_tuple (self
, g_object_info_get_n_constants
, g_object_info_get_constant
);
1543 _wrap_g_object_info_get_vfuncs (PyGIBaseInfo
*self
)
1545 return _make_infos_tuple (self
, g_object_info_get_n_vfuncs
, g_object_info_get_vfunc
);
1549 _wrap_g_object_info_get_abstract (PyGIBaseInfo
*self
)
1551 gboolean is_abstract
= g_object_info_get_abstract ( (GIObjectInfo
*) self
->info
);
1552 return PyBool_FromLong (is_abstract
);
1556 _wrap_g_object_info_get_type_name (PyGIBaseInfo
*self
)
1558 return _get_info_string (self
, g_object_info_get_type_name
);
1562 _wrap_g_object_info_get_type_init (PyGIBaseInfo
*self
)
1564 return _get_info_string (self
, g_object_info_get_type_init
);
1568 _wrap_g_object_info_get_fundamental (PyGIBaseInfo
*self
)
1570 return PyBool_FromLong (g_object_info_get_fundamental ( (GIObjectInfo
*) self
->info
));
1574 _wrap_g_object_info_get_class_struct (PyGIBaseInfo
*self
)
1576 return _get_child_info (self
, g_object_info_get_class_struct
);
1580 _wrap_g_object_info_find_vfunc (PyGIBaseInfo
*self
, PyObject
*py_name
)
1582 return _get_child_info_by_name (self
, py_name
, g_object_info_find_vfunc
);
1586 _wrap_g_object_info_get_unref_function (PyGIBaseInfo
*self
)
1588 return _get_info_string (self
, g_object_info_get_unref_function
);
1592 _wrap_g_object_info_get_ref_function (PyGIBaseInfo
*self
)
1594 return _get_info_string (self
, g_object_info_get_ref_function
);
1598 _wrap_g_object_info_get_set_value_function (PyGIBaseInfo
*self
)
1600 return _get_info_string (self
, g_object_info_get_set_value_function
);
1604 _wrap_g_object_info_get_get_value_function (PyGIBaseInfo
*self
)
1606 return _get_info_string (self
, g_object_info_get_get_value_function
);
1609 static PyMethodDef _PyGIObjectInfo_methods
[] = {
1610 { "get_parent", (PyCFunction
) _wrap_g_object_info_get_parent
, METH_NOARGS
},
1611 { "get_methods", (PyCFunction
) _wrap_g_object_info_get_methods
, METH_NOARGS
},
1612 { "find_method", (PyCFunction
) _wrap_g_object_info_find_method
, METH_O
},
1613 { "get_fields", (PyCFunction
) _wrap_g_object_info_get_fields
, METH_NOARGS
},
1614 { "get_properties", (PyCFunction
) _wrap_g_object_info_get_properties
, METH_NOARGS
},
1615 { "get_signals", (PyCFunction
) _wrap_g_object_info_get_signals
, METH_NOARGS
},
1616 { "get_interfaces", (PyCFunction
) _wrap_g_object_info_get_interfaces
, METH_NOARGS
},
1617 { "get_constants", (PyCFunction
) _wrap_g_object_info_get_constants
, METH_NOARGS
},
1618 { "get_vfuncs", (PyCFunction
) _wrap_g_object_info_get_vfuncs
, METH_NOARGS
},
1619 { "find_vfunc", (PyCFunction
) _wrap_g_object_info_find_vfunc
, METH_O
},
1620 { "get_abstract", (PyCFunction
) _wrap_g_object_info_get_abstract
, METH_NOARGS
},
1621 { "get_type_name", (PyCFunction
) _wrap_g_object_info_get_type_name
, METH_NOARGS
},
1622 { "get_type_init", (PyCFunction
) _wrap_g_object_info_get_type_init
, METH_NOARGS
},
1623 { "get_fundamental", (PyCFunction
) _wrap_g_object_info_get_fundamental
, METH_NOARGS
},
1624 { "get_class_struct", (PyCFunction
) _wrap_g_object_info_get_class_struct
, METH_NOARGS
},
1625 { "get_unref_function", (PyCFunction
) _wrap_g_object_info_get_unref_function
, METH_NOARGS
},
1626 { "get_ref_function", (PyCFunction
) _wrap_g_object_info_get_ref_function
, METH_NOARGS
},
1627 { "get_set_value_function", (PyCFunction
) _wrap_g_object_info_get_set_value_function
, METH_NOARGS
},
1628 { "get_get_value_function", (PyCFunction
) _wrap_g_object_info_get_get_value_function
, METH_NOARGS
},
1633 /* GIInterfaceInfo */
1634 PYGLIB_DEFINE_TYPE ("InterfaceInfo", PyGIInterfaceInfo_Type
, PyGIBaseInfo
);
1637 _wrap_g_interface_info_get_methods (PyGIBaseInfo
*self
)
1639 return _make_infos_tuple (self
, g_interface_info_get_n_methods
, g_interface_info_get_method
);
1643 _wrap_g_interface_info_find_method (PyGIBaseInfo
*self
, PyObject
*py_name
)
1645 return _get_child_info_by_name (self
, py_name
, g_interface_info_find_method
);
1649 _wrap_g_interface_info_get_constants (PyGIBaseInfo
*self
)
1651 return _make_infos_tuple (self
, g_interface_info_get_n_constants
, g_interface_info_get_constant
);
1655 _wrap_g_interface_info_get_vfuncs (PyGIBaseInfo
*self
)
1657 return _make_infos_tuple (self
, g_interface_info_get_n_vfuncs
, g_interface_info_get_vfunc
);
1661 _wrap_g_interface_info_find_vfunc (PyGIBaseInfo
*self
, PyObject
*py_name
)
1663 return _get_child_info_by_name (self
, py_name
, g_interface_info_find_vfunc
);
1667 _wrap_g_interface_info_get_prerequisites (PyGIBaseInfo
*self
)
1669 return _make_infos_tuple (self
, g_interface_info_get_n_prerequisites
, g_interface_info_get_prerequisite
);
1673 _wrap_g_interface_info_get_properties (PyGIBaseInfo
*self
)
1675 return _make_infos_tuple (self
, g_interface_info_get_n_properties
, g_interface_info_get_property
);
1679 _wrap_g_interface_info_get_iface_struct (PyGIBaseInfo
*self
)
1681 return _get_child_info (self
, g_interface_info_get_iface_struct
);
1685 _wrap_g_interface_info_get_signals (PyGIBaseInfo
*self
)
1687 return _make_infos_tuple (self
, g_interface_info_get_n_signals
, g_interface_info_get_signal
);
1691 _wrap_g_interface_info_find_signal (PyGIBaseInfo
*self
, PyObject
*py_name
)
1693 return _get_child_info_by_name (self
, py_name
, g_interface_info_find_signal
);
1696 static PyMethodDef _PyGIInterfaceInfo_methods
[] = {
1697 { "get_prerequisites", (PyCFunction
) _wrap_g_interface_info_get_prerequisites
, METH_NOARGS
},
1698 { "get_properties", (PyCFunction
) _wrap_g_interface_info_get_properties
, METH_NOARGS
},
1699 { "get_methods", (PyCFunction
) _wrap_g_interface_info_get_methods
, METH_NOARGS
},
1700 { "find_method", (PyCFunction
) _wrap_g_interface_info_find_method
, METH_O
},
1701 { "get_signals", (PyCFunction
) _wrap_g_interface_info_get_signals
, METH_NOARGS
},
1702 { "find_signal", (PyCFunction
) _wrap_g_interface_info_find_signal
, METH_O
},
1703 { "get_vfuncs", (PyCFunction
) _wrap_g_interface_info_get_vfuncs
, METH_NOARGS
},
1704 { "get_constants", (PyCFunction
) _wrap_g_interface_info_get_constants
, METH_NOARGS
},
1705 { "get_iface_struct", (PyCFunction
) _wrap_g_interface_info_get_iface_struct
, METH_NOARGS
},
1706 { "find_vfunc", (PyCFunction
) _wrap_g_interface_info_find_vfunc
, METH_O
},
1710 /* GIConstantInfo */
1711 PYGLIB_DEFINE_TYPE ("gi.ConstantInfo", PyGIConstantInfo_Type
, PyGIBaseInfo
);
1714 _wrap_g_constant_info_get_value (PyGIBaseInfo
*self
)
1716 GITypeInfo
*type_info
;
1717 GIArgument value
= {0};
1719 gboolean free_array
= FALSE
;
1721 if (g_constant_info_get_value ( (GIConstantInfo
*) self
->info
, &value
) < 0) {
1722 PyErr_SetString (PyExc_RuntimeError
, "unable to get value");
1726 type_info
= g_constant_info_get_type ( (GIConstantInfo
*) self
->info
);
1728 if (g_type_info_get_tag (type_info
) == GI_TYPE_TAG_ARRAY
) {
1729 value
.v_pointer
= _pygi_argument_to_array (&value
, NULL
, NULL
, NULL
,
1730 type_info
, &free_array
);
1733 py_value
= _pygi_argument_to_object (&value
, type_info
, GI_TRANSFER_NOTHING
);
1736 g_array_free (value
.v_pointer
, FALSE
);
1739 g_constant_info_free_value (self
->info
, &value
);
1740 g_base_info_unref ( (GIBaseInfo
*) type_info
);
1745 static PyMethodDef _PyGIConstantInfo_methods
[] = {
1746 { "get_value", (PyCFunction
) _wrap_g_constant_info_get_value
, METH_NOARGS
},
1751 PYGLIB_DEFINE_TYPE ("gi.ValueInfo", PyGIValueInfo_Type
, PyGIBaseInfo
);
1754 _wrap_g_value_info_get_value (PyGIBaseInfo
*self
)
1758 value
= g_value_info_get_value ( (GIValueInfo
*) self
->info
);
1760 return PYGLIB_PyLong_FromLong (value
);
1764 static PyMethodDef _PyGIValueInfo_methods
[] = {
1765 { "get_value", (PyCFunction
) _wrap_g_value_info_get_value
, METH_NOARGS
},
1771 PYGLIB_DEFINE_TYPE ("gi.FieldInfo", PyGIFieldInfo_Type
, PyGIBaseInfo
);
1774 _struct_field_array_length_marshal (gsize length_index
,
1775 void *container_ptr
,
1776 void *struct_data_ptr
)
1778 gssize array_len
= -1;
1779 GIFieldInfo
*array_len_field
= NULL
;
1780 GIArgument arg
= {0};
1781 GIBaseInfo
*container_info
= (GIBaseInfo
*)container_ptr
;
1783 switch (g_base_info_get_type (container_info
)) {
1784 case GI_INFO_TYPE_UNION
:
1785 array_len_field
= g_union_info_get_field ((GIUnionInfo
*)container_info
, length_index
);
1787 case GI_INFO_TYPE_STRUCT
:
1788 array_len_field
= g_struct_info_get_field ((GIStructInfo
*)container_info
, length_index
);
1790 case GI_INFO_TYPE_OBJECT
:
1791 array_len_field
= g_object_info_get_field ((GIObjectInfo
*)container_info
, length_index
);
1794 /* Other types don't have fields. */
1795 g_assert_not_reached();
1798 if (array_len_field
== NULL
) {
1802 if (g_field_info_get_field (array_len_field
, struct_data_ptr
, &arg
)) {
1803 GITypeInfo
*array_len_type_info
;
1805 array_len_type_info
= g_field_info_get_type (array_len_field
);
1806 if (array_len_type_info
== NULL
) {
1810 if (!pygi_argument_to_gssize (&arg
,
1811 g_type_info_get_tag (array_len_type_info
),
1816 g_base_info_unref (array_len_type_info
);
1820 g_base_info_unref (array_len_field
);
1825 _pygi_g_registered_type_info_check_object (GIRegisteredTypeInfo
*info
,
1826 gboolean is_instance
,
1833 gchar
*type_name_expected
= NULL
;
1834 GIInfoType interface_type
;
1836 interface_type
= g_base_info_get_type (info
);
1837 if ( (interface_type
== GI_INFO_TYPE_STRUCT
) &&
1838 (g_struct_info_is_foreign ( (GIStructInfo
*) info
))) {
1839 /* TODO: Could we check is the correct foreign type? */
1843 g_type
= g_registered_type_info_get_g_type (info
);
1844 if (g_type
!= G_TYPE_NONE
) {
1845 py_type
= _pygi_type_get_from_g_type (g_type
);
1847 py_type
= _pygi_type_import_by_gi_info ( (GIBaseInfo
*) info
);
1850 if (py_type
== NULL
) {
1854 g_assert (PyType_Check (py_type
));
1857 retval
= PyObject_IsInstance (object
, py_type
);
1859 type_name_expected
= _pygi_g_base_info_get_fullname (
1860 (GIBaseInfo
*) info
);
1863 if (!PyObject_Type (py_type
)) {
1864 type_name_expected
= "type";
1866 } else if (!PyType_IsSubtype ( (PyTypeObject
*) object
,
1867 (PyTypeObject
*) py_type
)) {
1868 type_name_expected
= _pygi_g_base_info_get_fullname (
1869 (GIBaseInfo
*) info
);
1876 Py_DECREF (py_type
);
1879 PyTypeObject
*object_type
;
1881 if (type_name_expected
== NULL
) {
1885 object_type
= (PyTypeObject
*) PyObject_Type (object
);
1886 if (object_type
== NULL
) {
1890 PyErr_Format (PyExc_TypeError
, "Must be %s, not %s",
1891 type_name_expected
, object_type
->tp_name
);
1893 g_free (type_name_expected
);
1900 _wrap_g_field_info_get_value (PyGIBaseInfo
*self
,
1904 GIBaseInfo
*container_info
;
1905 GIInfoType container_info_type
;
1907 GITypeInfo
*field_type_info
;
1909 PyObject
*py_value
= NULL
;
1910 gboolean free_array
= FALSE
;
1912 memset(&value
, 0, sizeof(GIArgument
));
1914 if (!PyArg_ParseTuple (args
, "O:FieldInfo.get_value", &instance
)) {
1918 container_info
= g_base_info_get_container (self
->info
);
1919 g_assert (container_info
!= NULL
);
1921 /* Check the instance. */
1922 if (!_pygi_g_registered_type_info_check_object ( (GIRegisteredTypeInfo
*) container_info
, TRUE
, instance
)) {
1923 _PyGI_ERROR_PREFIX ("argument 1: ");
1927 /* Get the pointer to the container. */
1928 container_info_type
= g_base_info_get_type (container_info
);
1929 switch (container_info_type
) {
1930 case GI_INFO_TYPE_UNION
:
1931 case GI_INFO_TYPE_STRUCT
:
1932 pointer
= pyg_boxed_get (instance
, void);
1934 case GI_INFO_TYPE_OBJECT
:
1935 pointer
= pygobject_get (instance
);
1938 /* Other types don't have fields. */
1939 g_assert_not_reached();
1942 /* Get the field's value. */
1943 field_type_info
= g_field_info_get_type ( (GIFieldInfo
*) self
->info
);
1945 /* A few types are not handled by g_field_info_get_field, so do it here. */
1946 if (!g_type_info_is_pointer (field_type_info
)
1947 && g_type_info_get_tag (field_type_info
) == GI_TYPE_TAG_INTERFACE
) {
1949 GIInfoType info_type
;
1951 if (! (g_field_info_get_flags ( (GIFieldInfo
*) self
->info
) & GI_FIELD_IS_READABLE
)) {
1952 PyErr_SetString (PyExc_RuntimeError
, "field is not readable");
1956 info
= g_type_info_get_interface (field_type_info
);
1958 info_type
= g_base_info_get_type (info
);
1960 g_base_info_unref (info
);
1962 switch (info_type
) {
1963 case GI_INFO_TYPE_UNION
:
1964 PyErr_SetString (PyExc_NotImplementedError
, "getting an union is not supported yet");
1966 case GI_INFO_TYPE_STRUCT
:
1970 offset
= g_field_info_get_offset ( (GIFieldInfo
*) self
->info
);
1972 value
.v_pointer
= (char*) pointer
+ offset
;
1974 goto argument_to_object
;
1982 if (!g_field_info_get_field ( (GIFieldInfo
*) self
->info
, pointer
, &value
)) {
1983 PyErr_SetString (PyExc_RuntimeError
, "unable to get the value");
1987 if (g_type_info_get_tag (field_type_info
) == GI_TYPE_TAG_ARRAY
) {
1988 value
.v_pointer
= _pygi_argument_to_array (&value
,
1989 _struct_field_array_length_marshal
,
1997 py_value
= _pygi_argument_to_object (&value
, field_type_info
, GI_TRANSFER_NOTHING
);
2000 g_array_free (value
.v_pointer
, FALSE
);
2004 g_base_info_unref ( (GIBaseInfo
*) field_type_info
);
2010 _wrap_g_field_info_set_value (PyGIBaseInfo
*self
,
2015 GIBaseInfo
*container_info
;
2016 GIInfoType container_info_type
;
2018 GITypeInfo
*field_type_info
;
2020 PyObject
*retval
= NULL
;
2022 if (!PyArg_ParseTuple (args
, "OO:FieldInfo.set_value", &instance
, &py_value
)) {
2026 container_info
= g_base_info_get_container (self
->info
);
2027 g_assert (container_info
!= NULL
);
2029 /* Check the instance. */
2030 if (!_pygi_g_registered_type_info_check_object ( (GIRegisteredTypeInfo
*) container_info
, TRUE
, instance
)) {
2031 _PyGI_ERROR_PREFIX ("argument 1: ");
2035 /* Get the pointer to the container. */
2036 container_info_type
= g_base_info_get_type (container_info
);
2037 switch (container_info_type
) {
2038 case GI_INFO_TYPE_UNION
:
2039 case GI_INFO_TYPE_STRUCT
:
2040 pointer
= pyg_boxed_get (instance
, void);
2042 case GI_INFO_TYPE_OBJECT
:
2043 pointer
= pygobject_get (instance
);
2046 /* Other types don't have fields. */
2047 g_assert_not_reached();
2050 field_type_info
= g_field_info_get_type ( (GIFieldInfo
*) self
->info
);
2052 /* Set the field's value. */
2053 /* A few types are not handled by g_field_info_set_field, so do it here. */
2054 if (!g_type_info_is_pointer (field_type_info
)
2055 && g_type_info_get_tag (field_type_info
) == GI_TYPE_TAG_INTERFACE
) {
2057 GIInfoType info_type
;
2059 if (! (g_field_info_get_flags ( (GIFieldInfo
*) self
->info
) & GI_FIELD_IS_WRITABLE
)) {
2060 PyErr_SetString (PyExc_RuntimeError
, "field is not writable");
2064 info
= g_type_info_get_interface (field_type_info
);
2066 info_type
= g_base_info_get_type (info
);
2068 switch (info_type
) {
2069 case GI_INFO_TYPE_UNION
:
2070 PyErr_SetString (PyExc_NotImplementedError
, "setting an union is not supported yet");
2072 case GI_INFO_TYPE_STRUCT
:
2078 is_simple
= pygi_g_struct_info_is_simple ( (GIStructInfo
*) info
);
2081 PyErr_SetString (PyExc_TypeError
,
2082 "cannot set a structure which has no well-defined ownership transfer rules");
2083 g_base_info_unref (info
);
2087 value
= _pygi_argument_from_object (py_value
, field_type_info
, GI_TRANSFER_NOTHING
);
2088 if (PyErr_Occurred()) {
2089 g_base_info_unref (info
);
2093 offset
= g_field_info_get_offset ( (GIFieldInfo
*) self
->info
);
2094 size
= g_struct_info_get_size ( (GIStructInfo
*) info
);
2095 g_assert (size
> 0);
2097 g_memmove ((char*) pointer
+ offset
, value
.v_pointer
, size
);
2099 g_base_info_unref (info
);
2109 g_base_info_unref (info
);
2110 } else if (g_type_info_is_pointer (field_type_info
)
2111 && (g_type_info_get_tag (field_type_info
) == GI_TYPE_TAG_VOID
2112 || g_type_info_get_tag (field_type_info
) == GI_TYPE_TAG_UTF8
)) {
2114 value
= _pygi_argument_from_object (py_value
, field_type_info
, GI_TRANSFER_NOTHING
);
2115 if (PyErr_Occurred()) {
2119 offset
= g_field_info_get_offset ((GIFieldInfo
*) self
->info
);
2120 G_STRUCT_MEMBER (gpointer
, pointer
, offset
) = (gpointer
)value
.v_pointer
;
2126 value
= _pygi_argument_from_object (py_value
, field_type_info
, GI_TRANSFER_EVERYTHING
);
2127 if (PyErr_Occurred()) {
2131 if (!g_field_info_set_field ( (GIFieldInfo
*) self
->info
, pointer
, &value
)) {
2132 _pygi_argument_release (&value
, field_type_info
, GI_TRANSFER_NOTHING
, GI_DIRECTION_IN
);
2133 PyErr_SetString (PyExc_RuntimeError
, "unable to set value for field");
2140 g_base_info_unref ( (GIBaseInfo
*) field_type_info
);
2142 Py_XINCREF (retval
);
2147 _wrap_g_field_info_get_flags (PyGIBaseInfo
*self
)
2149 return PYGLIB_PyLong_FromLong (g_field_info_get_flags (self
->info
));
2153 _wrap_g_field_info_get_size (PyGIBaseInfo
*self
)
2155 return PYGLIB_PyLong_FromLong (g_field_info_get_size (self
->info
));
2159 _wrap_g_field_info_get_offset (PyGIBaseInfo
*self
)
2161 return PYGLIB_PyLong_FromLong (g_field_info_get_offset (self
->info
));
2165 _wrap_g_field_info_get_type (PyGIBaseInfo
*self
)
2167 return _get_child_info (self
, g_field_info_get_type
);
2170 static PyMethodDef _PyGIFieldInfo_methods
[] = {
2171 { "get_value", (PyCFunction
) _wrap_g_field_info_get_value
, METH_VARARGS
},
2172 { "set_value", (PyCFunction
) _wrap_g_field_info_set_value
, METH_VARARGS
},
2173 { "get_flags", (PyCFunction
) _wrap_g_field_info_get_flags
, METH_VARARGS
},
2174 { "get_size", (PyCFunction
) _wrap_g_field_info_get_size
, METH_VARARGS
},
2175 { "get_offset", (PyCFunction
) _wrap_g_field_info_get_offset
, METH_VARARGS
},
2176 { "get_type", (PyCFunction
) _wrap_g_field_info_get_type
, METH_VARARGS
},
2181 /* GIUnresolvedInfo */
2182 PYGLIB_DEFINE_TYPE ("gi.UnresolvedInfo", PyGIUnresolvedInfo_Type
, PyGIBaseInfo
);
2184 static PyMethodDef _PyGIUnresolvedInfo_methods
[] = {
2189 PYGLIB_DEFINE_TYPE ("gi.VFuncInfo", PyGIVFuncInfo_Type
, PyGICallableInfo
);
2192 _wrap_g_vfunc_info_get_flags (PyGIBaseInfo
*self
)
2194 return PYGLIB_PyLong_FromLong (g_vfunc_info_get_flags ((GIVFuncInfo
*) self
->info
));
2198 _wrap_g_vfunc_info_get_offset (PyGIBaseInfo
*self
)
2200 return PYGLIB_PyLong_FromLong (g_vfunc_info_get_offset ((GIVFuncInfo
*) self
->info
));
2204 _wrap_g_vfunc_info_get_signal (PyGIBaseInfo
*self
)
2206 return _get_child_info (self
, g_vfunc_info_get_signal
);
2210 _wrap_g_vfunc_info_get_invoker (PyGIBaseInfo
*self
)
2212 return _get_child_info (self
, g_vfunc_info_get_invoker
);
2215 static PyMethodDef _PyGIVFuncInfo_methods
[] = {
2216 { "get_flags", (PyCFunction
) _wrap_g_vfunc_info_get_flags
, METH_NOARGS
},
2217 { "get_offset", (PyCFunction
) _wrap_g_vfunc_info_get_offset
, METH_NOARGS
},
2218 { "get_signal", (PyCFunction
) _wrap_g_vfunc_info_get_signal
, METH_NOARGS
},
2219 { "get_invoker", (PyCFunction
) _wrap_g_vfunc_info_get_invoker
, METH_NOARGS
},
2225 PYGLIB_DEFINE_TYPE ("gi.UnionInfo", PyGIUnionInfo_Type
, PyGIBaseInfo
);
2228 _wrap_g_union_info_get_fields (PyGIBaseInfo
*self
)
2230 return _make_infos_tuple (self
, g_union_info_get_n_fields
, g_union_info_get_field
);
2234 _wrap_g_union_info_get_methods (PyGIBaseInfo
*self
)
2236 return _make_infos_tuple (self
, g_union_info_get_n_methods
, g_union_info_get_method
);
2240 _wrap_g_union_info_get_size (PyGIBaseInfo
*self
)
2242 return PYGLIB_PyLong_FromSize_t (g_union_info_get_size (self
->info
));
2245 static PyMethodDef _PyGIUnionInfo_methods
[] = {
2246 { "get_fields", (PyCFunction
) _wrap_g_union_info_get_fields
, METH_NOARGS
},
2247 { "get_methods", (PyCFunction
) _wrap_g_union_info_get_methods
, METH_NOARGS
},
2248 { "get_size", (PyCFunction
) _wrap_g_union_info_get_size
, METH_NOARGS
},
2255 _pygi_g_base_info_get_fullname (GIBaseInfo
*info
)
2257 GIBaseInfo
*container_info
;
2260 container_info
= g_base_info_get_container (info
);
2261 if (container_info
!= NULL
) {
2262 fullname
= g_strdup_printf ("%s.%s.%s",
2263 g_base_info_get_namespace (container_info
),
2264 _safe_base_info_get_name (container_info
),
2265 _safe_base_info_get_name (info
));
2267 fullname
= g_strdup_printf ("%s.%s",
2268 g_base_info_get_namespace (info
),
2269 _safe_base_info_get_name (info
));
2272 if (fullname
== NULL
) {
2281 _pygi_info_register_types (PyObject
*m
)
2283 #define _PyGI_REGISTER_TYPE(m, type, cname, base) \
2284 Py_TYPE(&type) = &PyType_Type; \
2285 type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE); \
2286 type.tp_weaklistoffset = offsetof(PyGIBaseInfo, inst_weakreflist); \
2287 type.tp_methods = _PyGI##cname##_methods; \
2288 type.tp_base = &base; \
2289 if (PyType_Ready(&type)) \
2291 if (PyModule_AddObject(m, #cname, (PyObject *)&type)) \
2294 Py_TYPE(&PyGIBaseInfo_Type
) = &PyType_Type
;
2296 PyGIBaseInfo_Type
.tp_dealloc
= (destructor
) _base_info_dealloc
;
2297 PyGIBaseInfo_Type
.tp_repr
= (reprfunc
) _base_info_repr
;
2298 PyGIBaseInfo_Type
.tp_flags
= (Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
);
2299 PyGIBaseInfo_Type
.tp_weaklistoffset
= offsetof(PyGIBaseInfo
, inst_weakreflist
);
2300 PyGIBaseInfo_Type
.tp_methods
= _PyGIBaseInfo_methods
;
2301 PyGIBaseInfo_Type
.tp_richcompare
= (richcmpfunc
)_base_info_richcompare
;
2302 PyGIBaseInfo_Type
.tp_getset
= _base_info_getsets
;
2303 PyGIBaseInfo_Type
.tp_getattro
= (getattrofunc
) _base_info_getattro
;
2305 if (PyType_Ready(&PyGIBaseInfo_Type
))
2307 if (PyModule_AddObject(m
, "BaseInfo", (PyObject
*)&PyGIBaseInfo_Type
))
2310 _PyGI_REGISTER_TYPE (m
, PyGICallableInfo_Type
, CallableInfo
,
2312 PyGICallableInfo_Type
.tp_call
= (ternaryfunc
) _callable_info_call
;
2313 PyGICallableInfo_Type
.tp_dealloc
= (destructor
) _callable_info_dealloc
;
2315 _PyGI_REGISTER_TYPE (m
, PyGIFunctionInfo_Type
, FunctionInfo
,
2316 PyGICallableInfo_Type
);
2317 PyGIFunctionInfo_Type
.tp_call
= (ternaryfunc
) _function_info_call
;
2318 PyGIFunctionInfo_Type
.tp_descr_get
= (descrgetfunc
) _function_info_descr_get
;
2320 _PyGI_REGISTER_TYPE (m
, PyGIVFuncInfo_Type
, VFuncInfo
,
2321 PyGICallableInfo_Type
);
2322 PyGIVFuncInfo_Type
.tp_descr_get
= (descrgetfunc
) _vfunc_info_descr_get
;
2324 _PyGI_REGISTER_TYPE (m
, PyGISignalInfo_Type
, SignalInfo
,
2325 PyGICallableInfo_Type
);
2327 _PyGI_REGISTER_TYPE (m
, PyGIUnresolvedInfo_Type
, UnresolvedInfo
,
2329 _PyGI_REGISTER_TYPE (m
, PyGICallbackInfo_Type
, CallbackInfo
,
2330 PyGICallableInfo_Type
);
2331 _PyGI_REGISTER_TYPE (m
, PyGIRegisteredTypeInfo_Type
, RegisteredTypeInfo
,
2333 _PyGI_REGISTER_TYPE (m
, PyGIStructInfo_Type
, StructInfo
,
2334 PyGIRegisteredTypeInfo_Type
);
2335 _PyGI_REGISTER_TYPE (m
, PyGIEnumInfo_Type
, EnumInfo
,
2336 PyGIRegisteredTypeInfo_Type
);
2337 _PyGI_REGISTER_TYPE (m
, PyGIObjectInfo_Type
, ObjectInfo
,
2338 PyGIRegisteredTypeInfo_Type
);
2339 _PyGI_REGISTER_TYPE (m
, PyGIInterfaceInfo_Type
, InterfaceInfo
,
2340 PyGIRegisteredTypeInfo_Type
);
2341 _PyGI_REGISTER_TYPE (m
, PyGIConstantInfo_Type
, ConstantInfo
,
2343 _PyGI_REGISTER_TYPE (m
, PyGIValueInfo_Type
, ValueInfo
,
2345 _PyGI_REGISTER_TYPE (m
, PyGIFieldInfo_Type
, FieldInfo
,
2347 _PyGI_REGISTER_TYPE (m
, PyGIUnionInfo_Type
, UnionInfo
,
2348 PyGIRegisteredTypeInfo_Type
);
2349 _PyGI_REGISTER_TYPE (m
, PyGIErrorDomainInfo_Type
, ErrorDomainInfo
,
2351 _PyGI_REGISTER_TYPE (m
, PyGIPropertyInfo_Type
, PropertyInfo
,
2353 _PyGI_REGISTER_TYPE (m
, PyGIArgInfo_Type
, ArgInfo
,
2355 _PyGI_REGISTER_TYPE (m
, PyGITypeInfo_Type
, TypeInfo
,
2358 #undef _PyGI_REGISTER_TYPE
2360 #define _PyGI_ENUM_BEGIN(name) \
2362 const char *__enum_name = #name; \
2363 PyObject *__enum_value = NULL; \
2364 PyObject *__new_enum_cls = NULL; \
2365 PyObject *__enum_instance_dict = PyDict_New(); \
2366 PyObject *__module_name = PyObject_GetAttrString (m, "__name__"); \
2367 PyDict_SetItemString (__enum_instance_dict, "__module__", __module_name); \
2368 Py_DECREF (__module_name);
2370 #define _PyGI_ENUM_ADD_VALUE(prefix, name) \
2371 __enum_value = PYGLIB_PyLong_FromLong (prefix##_##name); \
2372 if (PyDict_SetItemString(__enum_instance_dict, #name, __enum_value)) { \
2373 Py_DECREF (__enum_instance_dict); \
2374 Py_DECREF (__enum_value); \
2377 Py_DECREF (__enum_value);
2379 #define _PyGI_ENUM_END \
2380 __new_enum_cls = PyObject_CallFunction ((PyObject *)&PyType_Type, "s(O)O", \
2381 __enum_name, (PyObject *)&PyType_Type, \
2382 __enum_instance_dict); \
2383 Py_DECREF (__enum_instance_dict); \
2384 PyModule_AddObject (m, __enum_name, __new_enum_cls); /* steals ref */ \
2389 _PyGI_ENUM_BEGIN (Direction
)
2390 _PyGI_ENUM_ADD_VALUE (GI_DIRECTION
, IN
)
2391 _PyGI_ENUM_ADD_VALUE (GI_DIRECTION
, OUT
)
2392 _PyGI_ENUM_ADD_VALUE (GI_DIRECTION
, INOUT
)
2397 _PyGI_ENUM_BEGIN (Transfer
)
2398 _PyGI_ENUM_ADD_VALUE (GI_TRANSFER
, NOTHING
)
2399 _PyGI_ENUM_ADD_VALUE (GI_TRANSFER
, CONTAINER
)
2400 _PyGI_ENUM_ADD_VALUE (GI_TRANSFER
, EVERYTHING
)
2404 _PyGI_ENUM_BEGIN (ArrayType
)
2405 _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE
, C
)
2406 _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE
, ARRAY
)
2407 _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE
, PTR_ARRAY
)
2408 _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE
, BYTE_ARRAY
)
2412 _PyGI_ENUM_BEGIN (ScopeType
)
2413 _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE
, INVALID
)
2414 _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE
, CALL
)
2415 _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE
, ASYNC
)
2416 _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE
, NOTIFIED
)
2419 /* GIVFuncInfoFlags */
2420 _PyGI_ENUM_BEGIN (VFuncInfoFlags
)
2421 _PyGI_ENUM_ADD_VALUE (GI_VFUNC_MUST
, CHAIN_UP
)
2422 _PyGI_ENUM_ADD_VALUE (GI_VFUNC_MUST
, OVERRIDE
)
2423 _PyGI_ENUM_ADD_VALUE (GI_VFUNC_MUST
, NOT_OVERRIDE
)
2426 /* GIFieldInfoFlags */
2427 _PyGI_ENUM_BEGIN (FieldInfoFlags
)
2428 _PyGI_ENUM_ADD_VALUE (GI_FIELD
, IS_READABLE
)
2429 _PyGI_ENUM_ADD_VALUE (GI_FIELD
, IS_WRITABLE
)
2432 /* GIFunctionInfoFlags */
2433 _PyGI_ENUM_BEGIN (FunctionInfoFlags
)
2434 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION
, IS_METHOD
)
2435 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION
, IS_CONSTRUCTOR
)
2436 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION
, IS_GETTER
)
2437 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION
, IS_SETTER
)
2438 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION
, WRAPS_VFUNC
)
2439 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION
, THROWS
)
2443 _PyGI_ENUM_BEGIN (TypeTag
)
2445 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, VOID
)
2446 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, BOOLEAN
)
2447 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, INT8
)
2448 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, UINT8
)
2449 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, INT16
)
2450 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, UINT16
)
2451 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, INT32
)
2452 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, UINT32
)
2453 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, INT64
)
2454 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, UINT64
)
2455 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, FLOAT
)
2456 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, DOUBLE
)
2457 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, GTYPE
)
2458 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, UTF8
)
2459 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, FILENAME
)
2461 /* Non-basic types; compare with G_TYPE_TAG_IS_BASIC */
2462 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, ARRAY
)
2463 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, INTERFACE
)
2464 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, GLIST
)
2465 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, GSLIST
)
2466 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, GHASH
)
2467 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, ERROR
)
2469 /* Another basic type */
2470 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, UNICHAR
)
2474 _PyGI_ENUM_BEGIN (InfoType
)
2475 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, INVALID
)
2476 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, FUNCTION
)
2477 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, CALLBACK
)
2478 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, STRUCT
)
2479 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, BOXED
)
2480 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, ENUM
)
2481 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, FLAGS
)
2482 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, OBJECT
)
2483 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, INTERFACE
)
2484 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, CONSTANT
)
2485 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, INVALID_0
)
2486 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, UNION
)
2487 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, VALUE
)
2488 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, SIGNAL
)
2489 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, VFUNC
)
2490 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, PROPERTY
)
2491 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, FIELD
)
2492 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, ARG
)
2493 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, TYPE
)
2494 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, UNRESOLVED
)
2497 #undef _PyGI_ENUM_BEGIN
2498 #undef _PyGI_ENUM_ADD_VALUE
2499 #undef _PyGI_ENUM_END