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"
30 #include "pygi-basictype.h"
31 #include "pygi-type.h"
33 /* _generate_doc_string
35 * C wrapper to call Python implemented "gi.docstring.generate_doc_string"
38 _generate_doc_string(PyGIBaseInfo
*self
)
40 static PyObject
*_py_generate_doc_string
= NULL
;
42 if (_py_generate_doc_string
== NULL
) {
43 PyObject
*mod
= pygi_import_module ("gi.docstring");
47 _py_generate_doc_string
= PyObject_GetAttrString (mod
, "generate_doc_string");
48 if (_py_generate_doc_string
== NULL
) {
55 return PyObject_CallFunctionObjArgs (_py_generate_doc_string
, self
, NULL
);
59 _get_info_string (PyGIBaseInfo
*self
,
60 const gchar
* (*get_info_string
)(GIBaseInfo
*))
62 const gchar
*value
= get_info_string ((GIBaseInfo
*)self
->info
);
66 return pygi_utf8_to_py (value
);
70 _get_child_info (PyGIBaseInfo
*self
,
71 GIBaseInfo
* (*get_child_info
)(GIBaseInfo
*))
76 info
= get_child_info ((GIBaseInfo
*)self
->info
);
81 py_info
= _pygi_info_new (info
);
82 g_base_info_unref (info
);
88 _get_child_info_by_name (PyGIBaseInfo
*self
, PyObject
*py_name
,
89 GIBaseInfo
* (*get_child_info_by_name
)(GIBaseInfo
*, const gchar
*))
95 if (!pygi_utf8_from_py (py_name
, &name
))
98 info
= get_child_info_by_name ((GIObjectInfo
*)self
->info
, name
);
103 py_info
= _pygi_info_new (info
);
104 g_base_info_unref (info
);
111 * Build a tuple from the common API pattern in GI of having a
112 * function which returns a count and an indexed GIBaseInfo
113 * in the range of 0 to count;
116 _make_infos_tuple (PyGIBaseInfo
*self
,
117 gint (*get_n_infos
)(GIBaseInfo
*),
118 GIBaseInfo
* (*get_info
)(GIBaseInfo
*, gint
))
124 n_infos
= get_n_infos ( (GIBaseInfo
*) self
->info
);
126 infos
= PyTuple_New (n_infos
);
131 for (i
= 0; i
< n_infos
; i
++) {
135 info
= (GIBaseInfo
*) get_info (self
->info
, i
);
136 g_assert (info
!= NULL
);
138 py_info
= _pygi_info_new (info
);
140 g_base_info_unref (info
);
142 if (py_info
== NULL
) {
147 PyTuple_SET_ITEM (infos
, i
, py_info
);
156 /* We need to be careful about calling g_base_info_get_name because
157 * calling it with a GI_INFO_TYPE_TYPE will crash.
158 * See: https://bugzilla.gnome.org/show_bug.cgi?id=709456
161 _safe_base_info_get_name (GIBaseInfo
*info
)
163 if (g_base_info_get_type (info
) == GI_INFO_TYPE_TYPE
) {
164 return "type_type_instance";
166 return g_base_info_get_name (info
);
171 _base_info_dealloc (PyGIBaseInfo
*self
)
173 if (self
->inst_weakreflist
!= NULL
)
174 PyObject_ClearWeakRefs ( (PyObject
*) self
);
176 g_base_info_unref (self
->info
);
178 if (self
->cache
!= NULL
)
179 pygi_callable_cache_free ( (PyGICallableCache
*) self
->cache
);
181 Py_TYPE (self
)->tp_free ((PyObject
*)self
);
185 _base_info_repr (PyGIBaseInfo
*self
)
188 return PYGLIB_PyUnicode_FromFormat ("%s(%s)",
189 Py_TYPE( (PyObject
*) self
)->tp_name
,
190 _safe_base_info_get_name (self
->info
));
194 _wrap_g_base_info_equal (PyGIBaseInfo
*self
, PyObject
*other
)
196 GIBaseInfo
*other_info
;
198 if (!PyObject_TypeCheck (other
, &PyGIBaseInfo_Type
)) {
199 Py_INCREF (Py_NotImplemented
);
200 return Py_NotImplemented
;
203 other_info
= ((PyGIBaseInfo
*)other
)->info
;
204 if (g_base_info_equal (self
->info
, other_info
)) {
212 _base_info_richcompare (PyGIBaseInfo
*self
, PyObject
*other
, int op
)
218 return _wrap_g_base_info_equal (self
, other
);
220 res
= _wrap_g_base_info_equal (self
, other
);
221 if (res
== Py_True
) {
229 res
= Py_NotImplemented
;
236 PYGLIB_DEFINE_TYPE("gi.BaseInfo", PyGIBaseInfo_Type
, PyGIBaseInfo
);
239 _pygi_is_python_keyword (const gchar
*name
)
241 /* It may be better to use keyword.iskeyword(); keep in sync with
242 * python -c 'import keyword; print(keyword.kwlist)' */
243 #if PY_VERSION_HEX < 0x03000000
245 static const gchar
* keywords
[] = {"and", "as", "assert", "break", "class",
246 "continue", "def", "del", "elif", "else", "except", "exec", "finally",
247 "for", "from", "global", "if", "import", "in", "is", "lambda", "not",
248 "or", "pass", "print", "raise", "return", "try", "while", "with",
250 #elif PY_VERSION_HEX < 0x04000000
251 /* Python 3.x; note that we explicitly keep "print"; it is not a keyword
252 * any more, but we do not want to break API between Python versions */
253 static const gchar
* keywords
[] = {"False", "None", "True", "and", "as",
254 "assert", "break", "class", "continue", "def", "del", "elif", "else",
255 "except", "finally", "for", "from", "global", "if", "import", "in",
256 "is", "lambda", "nonlocal", "not", "or", "pass", "raise", "return",
257 "try", "while", "with", "yield",
260 #error Need keyword list for this major Python version
265 for (i
= keywords
; *i
!= NULL
; ++i
) {
266 if (strcmp (name
, *i
) == 0) {
275 _wrap_g_base_info_get_type (PyGIBaseInfo
*self
)
277 return pygi_guint_to_py (g_base_info_get_type (self
->info
));
281 _wrap_g_base_info_get_name (PyGIBaseInfo
*self
)
285 name
= _safe_base_info_get_name (self
->info
);
287 /* escape keywords */
288 if (_pygi_is_python_keyword (name
)) {
289 gchar
*escaped
= g_strconcat (name
, "_", NULL
);
290 PyObject
*obj
= pygi_utf8_to_py (escaped
);
295 return pygi_utf8_to_py (name
);
299 _wrap_g_base_info_get_name_unescaped (PyGIBaseInfo
*self
)
301 return _get_info_string (self
, _safe_base_info_get_name
);
305 _wrap_g_base_info_get_namespace (PyGIBaseInfo
*self
)
307 return _get_info_string (self
, g_base_info_get_namespace
);
311 _wrap_g_base_info_is_deprecated (PyGIBaseInfo
*self
)
313 if (g_base_info_is_deprecated (self
->info
))
320 _wrap_g_base_info_get_attribute (PyGIBaseInfo
*self
, PyObject
*arg
)
325 if (!pygi_utf8_from_py (arg
, &name
))
328 value
= g_base_info_get_attribute (self
->info
, name
);
332 return pygi_utf8_to_py (value
);
336 _wrap_g_base_info_get_container (PyGIBaseInfo
*self
)
338 /* Note: don't use _get_child_info because g_base_info_get_container
339 * is marked as [transfer none] and therefore returns a borrowed ref.
343 info
= g_base_info_get_container (self
->info
);
349 return _pygi_info_new (info
);
353 static PyMethodDef _PyGIBaseInfo_methods
[] = {
354 { "get_type", (PyCFunction
) _wrap_g_base_info_get_type
, METH_NOARGS
},
355 { "get_name", (PyCFunction
) _wrap_g_base_info_get_name
, METH_NOARGS
},
356 { "get_name_unescaped", (PyCFunction
) _wrap_g_base_info_get_name_unescaped
, METH_NOARGS
},
357 { "get_namespace", (PyCFunction
) _wrap_g_base_info_get_namespace
, METH_NOARGS
},
358 { "is_deprecated", (PyCFunction
) _wrap_g_base_info_is_deprecated
, METH_NOARGS
},
359 { "get_attribute", (PyCFunction
) _wrap_g_base_info_get_attribute
, METH_O
},
360 { "get_container", (PyCFunction
) _wrap_g_base_info_get_container
, METH_NOARGS
},
361 { "equal", (PyCFunction
) _wrap_g_base_info_equal
, METH_O
},
365 /* _base_info_getattro:
367 * The usage of __getattr__ is needed because the get/set method table
368 * does not work for __doc__.
371 _base_info_getattro(PyGIBaseInfo
*self
, PyObject
*name
)
375 static PyObject
*docstr
;
376 if (docstr
== NULL
) {
377 docstr
= PYGLIB_PyUnicode_InternFromString("__doc__");
383 PYGLIB_PyUnicode_InternInPlace (&name
);
385 if (name
== docstr
) {
386 result
= _generate_doc_string (self
);
388 result
= PyObject_GenericGetAttr ((PyObject
*)self
, name
);
396 _base_info_attr_name(PyGIBaseInfo
*self
, void *closure
)
398 return _wrap_g_base_info_get_name (self
);
402 _base_info_attr_module(PyGIBaseInfo
*self
, void *closure
)
404 return PYGLIB_PyUnicode_FromFormat ("gi.repository.%s",
405 g_base_info_get_namespace (self
->info
));
408 static PyGetSetDef _base_info_getsets
[] = {
409 { "__name__", (getter
)_base_info_attr_name
, (setter
)0, "Name", NULL
},
410 { "__module__", (getter
)_base_info_attr_module
, (setter
)0, "Module name", NULL
},
415 _pygi_info_new (GIBaseInfo
*info
)
417 GIInfoType info_type
;
418 PyTypeObject
*type
= NULL
;
421 info_type
= g_base_info_get_type (info
);
425 case GI_INFO_TYPE_INVALID
:
426 PyErr_SetString (PyExc_RuntimeError
, "Invalid info type");
428 case GI_INFO_TYPE_FUNCTION
:
429 type
= &PyGIFunctionInfo_Type
;
431 case GI_INFO_TYPE_CALLBACK
:
432 type
= &PyGICallbackInfo_Type
;
434 case GI_INFO_TYPE_STRUCT
:
435 case GI_INFO_TYPE_BOXED
:
436 type
= &PyGIStructInfo_Type
;
438 case GI_INFO_TYPE_ENUM
:
439 case GI_INFO_TYPE_FLAGS
:
440 type
= &PyGIEnumInfo_Type
;
442 case GI_INFO_TYPE_OBJECT
:
443 type
= &PyGIObjectInfo_Type
;
445 case GI_INFO_TYPE_INTERFACE
:
446 type
= &PyGIInterfaceInfo_Type
;
448 case GI_INFO_TYPE_CONSTANT
:
449 type
= &PyGIConstantInfo_Type
;
451 case GI_INFO_TYPE_UNION
:
452 type
= &PyGIUnionInfo_Type
;
454 case GI_INFO_TYPE_VALUE
:
455 type
= &PyGIValueInfo_Type
;
457 case GI_INFO_TYPE_SIGNAL
:
458 type
= &PyGISignalInfo_Type
;
460 case GI_INFO_TYPE_VFUNC
:
461 type
= &PyGIVFuncInfo_Type
;
463 case GI_INFO_TYPE_PROPERTY
:
464 type
= &PyGIPropertyInfo_Type
;
466 case GI_INFO_TYPE_FIELD
:
467 type
= &PyGIFieldInfo_Type
;
469 case GI_INFO_TYPE_ARG
:
470 type
= &PyGIArgInfo_Type
;
472 case GI_INFO_TYPE_TYPE
:
473 type
= &PyGITypeInfo_Type
;
475 case GI_INFO_TYPE_UNRESOLVED
:
476 type
= &PyGIUnresolvedInfo_Type
;
479 g_assert_not_reached();
483 self
= (PyGIBaseInfo
*) type
->tp_alloc (type
, 0);
488 self
->info
= g_base_info_ref (info
);
489 self
->inst_weakreflist
= NULL
;
492 return (PyObject
*) self
;
496 _pygi_object_get_gi_info (PyObject
*object
,
500 GIBaseInfo
*info
= NULL
;
502 py_info
= PyObject_GetAttrString (object
, "__info__");
503 if (py_info
== NULL
) {
506 if (!PyObject_TypeCheck (py_info
, type
)) {
507 PyErr_Format (PyExc_TypeError
, "attribute '__info__' must be %s, not %s",
508 type
->tp_name
, Py_TYPE(py_info
)->tp_name
);
512 info
= ( (PyGIBaseInfo
*) py_info
)->info
;
513 g_base_info_ref (info
);
523 PYGLIB_DEFINE_TYPE ("gi.CallableInfo", PyGICallableInfo_Type
, PyGICallableInfo
);
525 /* _callable_info_call:
527 * Shared wrapper for invoke which can be bound (instance method or class constructor)
528 * or unbound (function or static method).
531 _callable_info_call (PyGICallableInfo
*self
, PyObject
*args
, PyObject
*kwargs
)
533 /* Insert the bound arg at the beginning of the invoke method args. */
534 if (self
->py_bound_arg
) {
537 Py_ssize_t argcount
= PyTuple_Size (args
);
538 PyObject
*newargs
= PyTuple_New (argcount
+ 1);
542 Py_INCREF (self
->py_bound_arg
);
543 PyTuple_SET_ITEM (newargs
, 0, self
->py_bound_arg
);
545 for (i
= 0; i
< argcount
; i
++) {
546 PyObject
*v
= PyTuple_GET_ITEM (args
, i
);
548 PyTuple_SET_ITEM (newargs
, i
+1, v
);
551 /* Invoke with the original GI info struct this wrapper was based upon.
552 * This is necessary to maintain the same cache for all bound versions.
554 result
= _wrap_g_callable_info_invoke ((PyGIBaseInfo
*)self
->py_unbound_info
,
560 /* We should never have an unbound info when calling when calling invoke
561 * at this point because the descriptor implementation on sub-classes
562 * should return "self" not a copy when there is no bound arg.
564 g_assert (self
->py_unbound_info
== NULL
);
565 return _wrap_g_callable_info_invoke ((PyGIBaseInfo
*)self
, args
, kwargs
);
570 /* _function_info_call:
572 * Specialization of _callable_info_call for GIFunctionInfo which
573 * handles constructor error conditions.
576 _function_info_call (PyGICallableInfo
*self
, PyObject
*args
, PyObject
*kwargs
)
578 if (self
->py_bound_arg
) {
579 GIFunctionInfoFlags flags
;
581 /* Ensure constructors are only called as class methods on the class
582 * implementing the constructor and not on sub-classes.
584 flags
= g_function_info_get_flags ( (GIFunctionInfo
*) self
->base
.info
);
585 if (flags
& GI_FUNCTION_IS_CONSTRUCTOR
) {
586 PyObject
*py_str_name
;
587 const gchar
*str_name
;
588 GIBaseInfo
*container_info
= g_base_info_get_container (self
->base
.info
);
589 g_assert (container_info
!= NULL
);
591 py_str_name
= PyObject_GetAttrString (self
->py_bound_arg
, "__name__");
592 if (py_str_name
== NULL
)
595 if (PyUnicode_Check (py_str_name
) ) {
596 PyObject
*tmp
= PyUnicode_AsUTF8String (py_str_name
);
597 Py_DECREF (py_str_name
);
601 #if PY_VERSION_HEX < 0x03000000
602 str_name
= PyString_AsString (py_str_name
);
604 str_name
= PyBytes_AsString (py_str_name
);
607 if (strcmp (str_name
, _safe_base_info_get_name (container_info
))) {
608 PyErr_Format (PyExc_TypeError
,
609 "%s constructor cannot be used to create instances of "
611 _safe_base_info_get_name (container_info
),
613 Py_DECREF (py_str_name
);
616 Py_DECREF (py_str_name
);
620 return _callable_info_call (self
, args
, kwargs
);
623 /* _new_bound_callable_info
625 * Utility function for sub-classes to create a bound version of themself.
627 static PyGICallableInfo
*
628 _new_bound_callable_info (PyGICallableInfo
*self
, PyObject
*bound_arg
)
630 PyGICallableInfo
*new_self
;
632 /* Return self if this is already bound or there is nothing passed to bind. */
633 if (self
->py_bound_arg
!= NULL
|| bound_arg
== NULL
|| bound_arg
== Py_None
) {
634 Py_INCREF ((PyObject
*)self
);
638 new_self
= (PyGICallableInfo
*)_pygi_info_new (self
->base
.info
);
639 if (new_self
== NULL
)
642 Py_INCREF ((PyObject
*)self
);
643 new_self
->py_unbound_info
= (struct PyGICallableInfo
*)self
;
645 Py_INCREF (bound_arg
);
646 new_self
->py_bound_arg
= bound_arg
;
651 /* _function_info_descr_get
653 * Descriptor protocol implementation for functions, methods, and constructors.
656 _function_info_descr_get (PyGICallableInfo
*self
, PyObject
*obj
, PyObject
*type
) {
657 GIFunctionInfoFlags flags
;
658 PyObject
*bound_arg
= NULL
;
660 flags
= g_function_info_get_flags ( (GIFunctionInfo
*) self
->base
.info
);
661 if (flags
& GI_FUNCTION_IS_CONSTRUCTOR
) {
663 bound_arg
= (PyObject
*)(Py_TYPE(obj
));
666 } else if (flags
& GI_FUNCTION_IS_METHOD
) {
670 return (PyObject
*)_new_bound_callable_info (self
, bound_arg
);
673 /* _vfunc_info_descr_get
675 * Descriptor protocol implementation for virtual functions.
678 _vfunc_info_descr_get (PyGICallableInfo
*self
, PyObject
*obj
, PyObject
*type
) {
680 PyObject
*bound_arg
= NULL
;
682 bound_arg
= PyObject_GetAttrString (type
, "__gtype__");
683 if (bound_arg
== NULL
)
686 /* _new_bound_callable_info adds its own ref so free the one from GetAttrString */
687 result
= (PyObject
*)_new_bound_callable_info (self
, bound_arg
);
688 Py_DECREF (bound_arg
);
693 _callable_info_dealloc (PyGICallableInfo
*self
)
695 Py_CLEAR (self
->py_unbound_info
);
696 Py_CLEAR (self
->py_bound_arg
);
698 PyGIBaseInfo_Type
.tp_dealloc ((PyObject
*) self
);
702 _wrap_g_callable_info_get_arguments (PyGIBaseInfo
*self
)
704 return _make_infos_tuple (self
, g_callable_info_get_n_args
, g_callable_info_get_arg
);
708 _wrap_g_callable_info_get_return_type (PyGIBaseInfo
*self
)
710 return _get_child_info (self
, g_callable_info_get_return_type
);
714 _wrap_g_callable_info_get_caller_owns (PyGIBaseInfo
*self
)
716 return pygi_guint_to_py (
717 g_callable_info_get_caller_owns (self
->info
) );
721 _wrap_g_callable_info_may_return_null (PyGIBaseInfo
*self
)
723 return pygi_gboolean_to_py (
724 g_callable_info_may_return_null (self
->info
) );
728 _wrap_g_callable_info_skip_return (PyGIBaseInfo
*self
)
730 return pygi_gboolean_to_py (g_callable_info_skip_return (self
->info
));
734 _wrap_g_callable_info_get_return_attribute (PyGIBaseInfo
*self
, PyObject
*py_name
)
739 if (!pygi_utf8_from_py (py_name
, &name
))
742 attr
= g_callable_info_get_return_attribute (self
->info
, name
);
744 return pygi_utf8_to_py (
745 g_callable_info_get_return_attribute (self
->info
, name
));
747 PyErr_Format(PyExc_AttributeError
, "return attribute %s not found", name
);
753 _wrap_g_callable_info_can_throw_gerror (PyGIBaseInfo
*self
)
755 if (g_callable_info_can_throw_gerror (self
->info
))
761 static PyMethodDef _PyGICallableInfo_methods
[] = {
762 { "invoke", (PyCFunction
) _wrap_g_callable_info_invoke
, METH_VARARGS
| METH_KEYWORDS
},
763 { "get_arguments", (PyCFunction
) _wrap_g_callable_info_get_arguments
, METH_NOARGS
},
764 { "get_return_type", (PyCFunction
) _wrap_g_callable_info_get_return_type
, METH_NOARGS
},
765 { "get_caller_owns", (PyCFunction
) _wrap_g_callable_info_get_caller_owns
, METH_NOARGS
},
766 { "may_return_null", (PyCFunction
) _wrap_g_callable_info_may_return_null
, METH_NOARGS
},
767 { "skip_return", (PyCFunction
) _wrap_g_callable_info_skip_return
, METH_NOARGS
},
768 { "get_return_attribute", (PyCFunction
) _wrap_g_callable_info_get_return_attribute
, METH_O
},
769 { "can_throw_gerror", (PyCFunction
) _wrap_g_callable_info_can_throw_gerror
, METH_NOARGS
},
774 PYGLIB_DEFINE_TYPE ("gi.CallbackInfo", PyGICallbackInfo_Type
, PyGICallableInfo
);
776 static PyMethodDef _PyGICallbackInfo_methods
[] = {
780 /* ErrorDomainInfo */
781 PYGLIB_DEFINE_TYPE ("gi.ErrorDomainInfo", PyGIErrorDomainInfo_Type
, PyGIBaseInfo
);
783 static PyMethodDef _PyGIErrorDomainInfo_methods
[] = {
788 PYGLIB_DEFINE_TYPE ("gi.SignalInfo", PyGISignalInfo_Type
, PyGICallableInfo
);
791 _wrap_g_signal_info_get_flags (PyGIBaseInfo
*self
)
793 return pygi_guint_to_py (
794 g_signal_info_get_flags ((GISignalInfo
*)self
->info
) );
798 _wrap_g_signal_info_get_class_closure (PyGIBaseInfo
*self
)
800 return _get_child_info (self
, g_signal_info_get_class_closure
);
804 _wrap_g_signal_info_true_stops_emit (PyGIBaseInfo
*self
)
806 return pygi_gboolean_to_py (
807 g_signal_info_true_stops_emit ((GISignalInfo
*)self
->info
) );
810 static PyMethodDef _PyGISignalInfo_methods
[] = {
811 { "get_flags", (PyCFunction
) _wrap_g_signal_info_get_flags
, METH_NOARGS
},
812 { "get_class_closure", (PyCFunction
) _wrap_g_signal_info_get_class_closure
, METH_NOARGS
},
813 { "true_stops_emit", (PyCFunction
) _wrap_g_signal_info_true_stops_emit
, METH_NOARGS
},
818 PYGLIB_DEFINE_TYPE ("gi.PropertyInfo", PyGIPropertyInfo_Type
, PyGIBaseInfo
);
821 _wrap_g_property_info_get_flags (PyGIBaseInfo
*self
)
823 return pygi_guint_to_py (
824 g_property_info_get_flags ((GIPropertyInfo
*)self
->info
) );
828 _wrap_g_property_info_get_type (PyGIBaseInfo
*self
)
830 return _get_child_info (self
, g_property_info_get_type
);
834 _wrap_g_property_info_get_ownership_transfer (PyGIBaseInfo
*self
)
836 return pygi_guint_to_py (
837 g_property_info_get_ownership_transfer ((GIPropertyInfo
*)self
->info
) );
840 static PyMethodDef _PyGIPropertyInfo_methods
[] = {
841 { "get_flags", (PyCFunction
) _wrap_g_property_info_get_flags
, METH_NOARGS
},
842 { "get_type", (PyCFunction
) _wrap_g_property_info_get_type
, METH_NOARGS
},
843 { "get_ownership_transfer", (PyCFunction
) _wrap_g_property_info_get_ownership_transfer
, METH_NOARGS
},
849 PYGLIB_DEFINE_TYPE ("gi.ArgInfo", PyGIArgInfo_Type
, PyGIBaseInfo
);
852 _wrap_g_arg_info_get_direction (PyGIBaseInfo
*self
)
854 return pygi_guint_to_py (
855 g_arg_info_get_direction ((GIArgInfo
*)self
->info
) );
859 _wrap_g_arg_info_is_caller_allocates (PyGIBaseInfo
*self
)
861 return pygi_gboolean_to_py (
862 g_arg_info_is_caller_allocates ((GIArgInfo
*)self
->info
) );
866 _wrap_g_arg_info_is_return_value (PyGIBaseInfo
*self
)
868 return pygi_gboolean_to_py (
869 g_arg_info_is_return_value ((GIArgInfo
*)self
->info
) );
873 _wrap_g_arg_info_is_optional (PyGIBaseInfo
*self
)
875 return pygi_gboolean_to_py (
876 g_arg_info_is_optional ((GIArgInfo
*)self
->info
) );
880 _wrap_g_arg_info_may_be_null (PyGIBaseInfo
*self
)
882 return pygi_gboolean_to_py (
883 g_arg_info_may_be_null ((GIArgInfo
*)self
->info
) );
887 _wrap_g_arg_info_get_ownership_transfer (PyGIBaseInfo
*self
)
889 return pygi_guint_to_py (
890 g_arg_info_get_ownership_transfer ((GIArgInfo
*)self
->info
) );
894 _wrap_g_arg_info_get_scope (PyGIBaseInfo
*self
)
896 return pygi_guint_to_py (
897 g_arg_info_get_scope ((GIArgInfo
*)self
->info
) );
901 _wrap_g_arg_info_get_closure (PyGIBaseInfo
*self
)
903 return pygi_gint_to_py (
904 g_arg_info_get_closure ((GIArgInfo
*)self
->info
) );
908 _wrap_g_arg_info_get_destroy (PyGIBaseInfo
*self
)
910 return pygi_gint_to_py (
911 g_arg_info_get_destroy ((GIArgInfo
*)self
->info
) );
915 _wrap_g_arg_info_get_type (PyGIBaseInfo
*self
)
917 return _get_child_info (self
, g_arg_info_get_type
);
920 static PyMethodDef _PyGIArgInfo_methods
[] = {
921 { "get_direction", (PyCFunction
) _wrap_g_arg_info_get_direction
, METH_NOARGS
},
922 { "is_caller_allocates", (PyCFunction
) _wrap_g_arg_info_is_caller_allocates
, METH_NOARGS
},
923 { "is_return_value", (PyCFunction
) _wrap_g_arg_info_is_return_value
, METH_NOARGS
},
924 { "is_optional", (PyCFunction
) _wrap_g_arg_info_is_optional
, METH_NOARGS
},
925 { "may_be_null", (PyCFunction
) _wrap_g_arg_info_may_be_null
, METH_NOARGS
},
926 { "get_ownership_transfer", (PyCFunction
) _wrap_g_arg_info_get_ownership_transfer
, METH_NOARGS
},
927 { "get_scope", (PyCFunction
) _wrap_g_arg_info_get_scope
, METH_NOARGS
},
928 { "get_closure", (PyCFunction
) _wrap_g_arg_info_get_closure
, METH_NOARGS
},
929 { "get_destroy", (PyCFunction
) _wrap_g_arg_info_get_destroy
, METH_NOARGS
},
930 { "get_type", (PyCFunction
) _wrap_g_arg_info_get_type
, METH_NOARGS
},
936 PYGLIB_DEFINE_TYPE ("gi.TypeInfo", PyGITypeInfo_Type
, PyGIBaseInfo
);
939 _wrap_g_type_info_is_pointer (PyGIBaseInfo
*self
)
941 return pygi_gboolean_to_py (g_type_info_is_pointer (self
->info
));
945 _wrap_g_type_info_get_tag (PyGIBaseInfo
*self
)
947 return pygi_guint_to_py (g_type_info_get_tag (self
->info
));
951 _wrap_g_type_info_get_tag_as_string (PyGIBaseInfo
*self
)
953 GITypeTag tag
= g_type_info_get_tag (self
->info
);
954 return pygi_utf8_to_py (g_type_tag_to_string(tag
));
958 _wrap_g_type_info_get_param_type (PyGIBaseInfo
*self
, PyObject
*py_n
)
964 if (!pygi_gint_from_py (py_n
, &n
))
967 info
= (GIBaseInfo
*) g_type_info_get_param_type ( (GITypeInfo
*) self
->info
, n
);
972 py_info
= _pygi_info_new (info
);
973 g_base_info_unref (info
);
978 _wrap_g_type_info_get_interface (PyGIBaseInfo
*self
)
980 return _get_child_info (self
, g_type_info_get_interface
);
984 _wrap_g_type_info_get_array_length (PyGIBaseInfo
*self
)
986 return pygi_gint_to_py (g_type_info_get_array_length (self
->info
));
990 _wrap_g_type_info_get_array_fixed_size (PyGIBaseInfo
*self
)
992 return pygi_gint_to_py (g_type_info_get_array_fixed_size (self
->info
));
996 _wrap_g_type_info_is_zero_terminated (PyGIBaseInfo
*self
)
998 return pygi_gboolean_to_py (g_type_info_is_zero_terminated (self
->info
));
1002 _wrap_g_type_info_get_array_type (PyGIBaseInfo
*self
)
1004 return pygi_guint_to_py (g_type_info_get_array_type (self
->info
));
1007 static PyMethodDef _PyGITypeInfo_methods
[] = {
1008 { "is_pointer", (PyCFunction
) _wrap_g_type_info_is_pointer
, METH_NOARGS
},
1009 { "get_tag", (PyCFunction
) _wrap_g_type_info_get_tag
, METH_NOARGS
},
1010 { "get_tag_as_string", (PyCFunction
) _wrap_g_type_info_get_tag_as_string
, METH_NOARGS
},
1011 { "get_param_type", (PyCFunction
) _wrap_g_type_info_get_param_type
, METH_O
},
1012 { "get_interface", (PyCFunction
) _wrap_g_type_info_get_interface
, METH_NOARGS
},
1013 { "get_array_length", (PyCFunction
) _wrap_g_type_info_get_array_length
, METH_NOARGS
},
1014 { "get_array_fixed_size", (PyCFunction
) _wrap_g_type_info_get_array_fixed_size
, METH_NOARGS
},
1015 { "is_zero_terminated", (PyCFunction
) _wrap_g_type_info_is_zero_terminated
, METH_NOARGS
},
1016 { "get_array_type", (PyCFunction
) _wrap_g_type_info_get_array_type
, METH_NOARGS
},
1022 PYGLIB_DEFINE_TYPE ("gi.FunctionInfo", PyGIFunctionInfo_Type
, PyGICallableInfo
);
1025 _wrap_g_function_info_is_constructor (PyGIBaseInfo
*self
)
1027 GIFunctionInfoFlags flags
;
1028 gboolean is_constructor
;
1030 flags
= g_function_info_get_flags ( (GIFunctionInfo
*) self
->info
);
1031 is_constructor
= flags
& GI_FUNCTION_IS_CONSTRUCTOR
;
1033 return pygi_gboolean_to_py (is_constructor
);
1037 _wrap_g_function_info_is_method (PyGIBaseInfo
*self
)
1039 GIFunctionInfoFlags flags
;
1042 flags
= g_function_info_get_flags ( (GIFunctionInfo
*) self
->info
);
1043 is_method
= flags
& GI_FUNCTION_IS_METHOD
;
1045 return pygi_gboolean_to_py (is_method
);
1049 _pygi_g_type_tag_size (GITypeTag type_tag
)
1054 case GI_TYPE_TAG_BOOLEAN
:
1055 size
= sizeof (gboolean
);
1057 case GI_TYPE_TAG_INT8
:
1058 case GI_TYPE_TAG_UINT8
:
1059 size
= sizeof (gint8
);
1061 case GI_TYPE_TAG_INT16
:
1062 case GI_TYPE_TAG_UINT16
:
1063 size
= sizeof (gint16
);
1065 case GI_TYPE_TAG_INT32
:
1066 case GI_TYPE_TAG_UINT32
:
1067 size
= sizeof (gint32
);
1069 case GI_TYPE_TAG_INT64
:
1070 case GI_TYPE_TAG_UINT64
:
1071 size
= sizeof (gint64
);
1073 case GI_TYPE_TAG_FLOAT
:
1074 size
= sizeof (gfloat
);
1076 case GI_TYPE_TAG_DOUBLE
:
1077 size
= sizeof (gdouble
);
1079 case GI_TYPE_TAG_GTYPE
:
1080 size
= sizeof (GType
);
1082 case GI_TYPE_TAG_UNICHAR
:
1083 size
= sizeof (gunichar
);
1085 case GI_TYPE_TAG_VOID
:
1086 case GI_TYPE_TAG_UTF8
:
1087 case GI_TYPE_TAG_FILENAME
:
1088 case GI_TYPE_TAG_ARRAY
:
1089 case GI_TYPE_TAG_INTERFACE
:
1090 case GI_TYPE_TAG_GLIST
:
1091 case GI_TYPE_TAG_GSLIST
:
1092 case GI_TYPE_TAG_GHASH
:
1093 case GI_TYPE_TAG_ERROR
:
1094 PyErr_Format (PyExc_TypeError
,
1095 "Unable to know the size (assuming %s is not a pointer)",
1096 g_type_tag_to_string (type_tag
));
1106 _pygi_g_type_info_size (GITypeInfo
*type_info
)
1112 type_tag
= g_type_info_get_tag (type_info
);
1114 case GI_TYPE_TAG_BOOLEAN
:
1115 case GI_TYPE_TAG_INT8
:
1116 case GI_TYPE_TAG_UINT8
:
1117 case GI_TYPE_TAG_INT16
:
1118 case GI_TYPE_TAG_UINT16
:
1119 case GI_TYPE_TAG_INT32
:
1120 case GI_TYPE_TAG_UINT32
:
1121 case GI_TYPE_TAG_INT64
:
1122 case GI_TYPE_TAG_UINT64
:
1123 case GI_TYPE_TAG_FLOAT
:
1124 case GI_TYPE_TAG_DOUBLE
:
1125 case GI_TYPE_TAG_GTYPE
:
1126 case GI_TYPE_TAG_UNICHAR
:
1127 size
= _pygi_g_type_tag_size (type_tag
);
1128 g_assert (size
> 0);
1130 case GI_TYPE_TAG_INTERFACE
:
1133 GIInfoType info_type
;
1135 info
= g_type_info_get_interface (type_info
);
1136 info_type
= g_base_info_get_type (info
);
1138 switch (info_type
) {
1139 case GI_INFO_TYPE_STRUCT
:
1140 if (g_type_info_is_pointer (type_info
)) {
1141 size
= sizeof (gpointer
);
1143 size
= g_struct_info_get_size ( (GIStructInfo
*) info
);
1146 case GI_INFO_TYPE_UNION
:
1147 if (g_type_info_is_pointer (type_info
)) {
1148 size
= sizeof (gpointer
);
1150 size
= g_union_info_get_size ( (GIUnionInfo
*) info
);
1153 case GI_INFO_TYPE_ENUM
:
1154 case GI_INFO_TYPE_FLAGS
:
1155 if (g_type_info_is_pointer (type_info
)) {
1156 size
= sizeof (gpointer
);
1158 GITypeTag enum_type_tag
;
1160 enum_type_tag
= g_enum_info_get_storage_type ( (GIEnumInfo
*) info
);
1161 size
= _pygi_g_type_tag_size (enum_type_tag
);
1164 case GI_INFO_TYPE_BOXED
:
1165 case GI_INFO_TYPE_OBJECT
:
1166 case GI_INFO_TYPE_INTERFACE
:
1167 case GI_INFO_TYPE_CALLBACK
:
1168 size
= sizeof (gpointer
);
1170 case GI_INFO_TYPE_VFUNC
:
1171 case GI_INFO_TYPE_INVALID
:
1172 case GI_INFO_TYPE_FUNCTION
:
1173 case GI_INFO_TYPE_CONSTANT
:
1174 case GI_INFO_TYPE_VALUE
:
1175 case GI_INFO_TYPE_SIGNAL
:
1176 case GI_INFO_TYPE_PROPERTY
:
1177 case GI_INFO_TYPE_FIELD
:
1178 case GI_INFO_TYPE_ARG
:
1179 case GI_INFO_TYPE_TYPE
:
1180 case GI_INFO_TYPE_UNRESOLVED
:
1182 g_assert_not_reached();
1186 g_base_info_unref (info
);
1189 case GI_TYPE_TAG_ARRAY
:
1190 case GI_TYPE_TAG_VOID
:
1191 case GI_TYPE_TAG_UTF8
:
1192 case GI_TYPE_TAG_FILENAME
:
1193 case GI_TYPE_TAG_GLIST
:
1194 case GI_TYPE_TAG_GSLIST
:
1195 case GI_TYPE_TAG_GHASH
:
1196 case GI_TYPE_TAG_ERROR
:
1197 size
= sizeof (gpointer
);
1207 _wrap_g_function_info_get_symbol (PyGIBaseInfo
*self
)
1209 return _get_info_string (self
, g_function_info_get_symbol
);
1213 _wrap_g_function_info_get_flags (PyGIBaseInfo
*self
)
1215 return pygi_guint_to_py (g_function_info_get_flags (self
->info
));
1219 _wrap_g_function_info_get_property (PyGIBaseInfo
*self
)
1221 return _get_child_info (self
, g_function_info_get_property
);
1225 _wrap_g_function_info_get_vfunc (PyGIBaseInfo
*self
)
1227 return _get_child_info (self
, g_function_info_get_vfunc
);
1230 static PyMethodDef _PyGIFunctionInfo_methods
[] = {
1231 { "is_constructor", (PyCFunction
) _wrap_g_function_info_is_constructor
, METH_NOARGS
},
1232 { "is_method", (PyCFunction
) _wrap_g_function_info_is_method
, METH_NOARGS
},
1233 { "get_symbol", (PyCFunction
) _wrap_g_function_info_get_symbol
, METH_NOARGS
},
1234 { "get_flags", (PyCFunction
) _wrap_g_function_info_get_flags
, METH_NOARGS
},
1235 { "get_property", (PyCFunction
) _wrap_g_function_info_get_property
, METH_NOARGS
},
1236 { "get_vfunc", (PyCFunction
) _wrap_g_function_info_get_vfunc
, METH_NOARGS
},
1240 /* RegisteredTypeInfo */
1241 PYGLIB_DEFINE_TYPE ("gi.RegisteredTypeInfo", PyGIRegisteredTypeInfo_Type
, PyGIBaseInfo
);
1244 _wrap_g_registered_type_info_get_type_name (PyGIBaseInfo
*self
)
1246 return _get_info_string (self
, g_registered_type_info_get_type_name
);
1250 _wrap_g_registered_type_info_get_type_init (PyGIBaseInfo
*self
)
1252 return _get_info_string (self
, g_registered_type_info_get_type_init
);
1256 _wrap_g_registered_type_info_get_g_type (PyGIBaseInfo
*self
)
1260 type
= g_registered_type_info_get_g_type ( (GIRegisteredTypeInfo
*) self
->info
);
1262 return pyg_type_wrapper_new (type
);
1265 static PyMethodDef _PyGIRegisteredTypeInfo_methods
[] = {
1266 { "get_type_name", (PyCFunction
) _wrap_g_registered_type_info_get_type_name
, METH_NOARGS
},
1267 { "get_type_init", (PyCFunction
) _wrap_g_registered_type_info_get_type_init
, METH_NOARGS
},
1268 { "get_g_type", (PyCFunction
) _wrap_g_registered_type_info_get_g_type
, METH_NOARGS
},
1274 PYGLIB_DEFINE_TYPE ("StructInfo", PyGIStructInfo_Type
, PyGIBaseInfo
);
1277 _wrap_g_struct_info_get_fields (PyGIBaseInfo
*self
)
1279 return _make_infos_tuple (self
, g_struct_info_get_n_fields
, g_struct_info_get_field
);
1283 _wrap_g_struct_info_get_methods (PyGIBaseInfo
*self
)
1285 return _make_infos_tuple (self
, g_struct_info_get_n_methods
, g_struct_info_get_method
);
1289 _wrap_g_struct_info_get_size (PyGIBaseInfo
*self
)
1291 return pygi_gsize_to_py (g_struct_info_get_size (self
->info
));
1295 _wrap_g_struct_info_get_alignment (PyGIBaseInfo
*self
)
1297 return pygi_gsize_to_py (g_struct_info_get_alignment (self
->info
));
1301 _wrap_g_struct_info_is_gtype_struct (PyGIBaseInfo
*self
)
1303 return pygi_gboolean_to_py (g_struct_info_is_gtype_struct (self
->info
));
1307 _wrap_g_struct_info_is_foreign (PyGIBaseInfo
*self
)
1309 return pygi_gboolean_to_py (g_struct_info_is_foreign (self
->info
));
1312 static PyMethodDef _PyGIStructInfo_methods
[] = {
1313 { "get_fields", (PyCFunction
) _wrap_g_struct_info_get_fields
, METH_NOARGS
},
1314 { "get_methods", (PyCFunction
) _wrap_g_struct_info_get_methods
, METH_NOARGS
},
1315 { "get_size", (PyCFunction
) _wrap_g_struct_info_get_size
, METH_NOARGS
},
1316 { "get_alignment", (PyCFunction
) _wrap_g_struct_info_get_alignment
, METH_NOARGS
},
1317 { "is_gtype_struct", (PyCFunction
) _wrap_g_struct_info_is_gtype_struct
, METH_NOARGS
},
1318 { "is_foreign", (PyCFunction
) _wrap_g_struct_info_is_foreign
, METH_NOARGS
},
1323 pygi_g_struct_info_is_simple (GIStructInfo
*struct_info
)
1326 gsize n_field_infos
;
1331 n_field_infos
= g_struct_info_get_n_fields (struct_info
);
1333 for (i
= 0; i
< n_field_infos
&& is_simple
; i
++) {
1334 GIFieldInfo
*field_info
;
1335 GITypeInfo
*field_type_info
;
1336 GITypeTag field_type_tag
;
1338 field_info
= g_struct_info_get_field (struct_info
, i
);
1339 field_type_info
= g_field_info_get_type (field_info
);
1342 field_type_tag
= g_type_info_get_tag (field_type_info
);
1344 switch (field_type_tag
) {
1345 case GI_TYPE_TAG_BOOLEAN
:
1346 case GI_TYPE_TAG_INT8
:
1347 case GI_TYPE_TAG_UINT8
:
1348 case GI_TYPE_TAG_INT16
:
1349 case GI_TYPE_TAG_UINT16
:
1350 case GI_TYPE_TAG_INT32
:
1351 case GI_TYPE_TAG_UINT32
:
1352 case GI_TYPE_TAG_INT64
:
1353 case GI_TYPE_TAG_UINT64
:
1354 case GI_TYPE_TAG_FLOAT
:
1355 case GI_TYPE_TAG_DOUBLE
:
1356 case GI_TYPE_TAG_UNICHAR
:
1357 if (g_type_info_is_pointer (field_type_info
)) {
1361 case GI_TYPE_TAG_VOID
:
1362 case GI_TYPE_TAG_GTYPE
:
1363 case GI_TYPE_TAG_ERROR
:
1364 case GI_TYPE_TAG_UTF8
:
1365 case GI_TYPE_TAG_FILENAME
:
1366 case GI_TYPE_TAG_ARRAY
:
1367 case GI_TYPE_TAG_GLIST
:
1368 case GI_TYPE_TAG_GSLIST
:
1369 case GI_TYPE_TAG_GHASH
:
1372 case GI_TYPE_TAG_INTERFACE
:
1375 GIInfoType info_type
;
1377 info
= g_type_info_get_interface (field_type_info
);
1378 info_type
= g_base_info_get_type (info
);
1380 switch (info_type
) {
1381 case GI_INFO_TYPE_STRUCT
:
1382 if (g_type_info_is_pointer (field_type_info
)) {
1385 is_simple
= pygi_g_struct_info_is_simple ( (GIStructInfo
*) info
);
1388 case GI_INFO_TYPE_UNION
:
1392 case GI_INFO_TYPE_ENUM
:
1393 case GI_INFO_TYPE_FLAGS
:
1394 if (g_type_info_is_pointer (field_type_info
)) {
1398 case GI_INFO_TYPE_BOXED
:
1399 case GI_INFO_TYPE_OBJECT
:
1400 case GI_INFO_TYPE_CALLBACK
:
1401 case GI_INFO_TYPE_INTERFACE
:
1404 case GI_INFO_TYPE_VFUNC
:
1405 case GI_INFO_TYPE_INVALID
:
1406 case GI_INFO_TYPE_FUNCTION
:
1407 case GI_INFO_TYPE_CONSTANT
:
1408 case GI_INFO_TYPE_VALUE
:
1409 case GI_INFO_TYPE_SIGNAL
:
1410 case GI_INFO_TYPE_PROPERTY
:
1411 case GI_INFO_TYPE_FIELD
:
1412 case GI_INFO_TYPE_ARG
:
1413 case GI_INFO_TYPE_TYPE
:
1414 case GI_INFO_TYPE_UNRESOLVED
:
1416 g_assert_not_reached();
1420 g_base_info_unref (info
);
1424 g_assert_not_reached();
1428 g_base_info_unref ( (GIBaseInfo
*) field_type_info
);
1429 g_base_info_unref ( (GIBaseInfo
*) field_info
);
1437 PYGLIB_DEFINE_TYPE ("gi.EnumInfo", PyGIEnumInfo_Type
, PyGIBaseInfo
);
1440 _wrap_g_enum_info_get_values (PyGIBaseInfo
*self
)
1442 return _make_infos_tuple (self
, g_enum_info_get_n_values
, g_enum_info_get_value
);
1446 _wrap_g_enum_info_is_flags (PyGIBaseInfo
*self
)
1448 GIInfoType info_type
= g_base_info_get_type ((GIBaseInfo
*) self
->info
);
1450 if (info_type
== GI_INFO_TYPE_ENUM
) {
1452 } else if (info_type
== GI_INFO_TYPE_FLAGS
) {
1455 g_assert_not_reached();
1460 _wrap_g_enum_info_get_methods (PyGIBaseInfo
*self
)
1462 return _make_infos_tuple (self
, g_enum_info_get_n_methods
, g_enum_info_get_method
);
1466 _wrap_g_enum_info_get_storage_type (PyGIBaseInfo
*self
)
1468 return pygi_guint_to_py (g_enum_info_get_storage_type ((GIBaseInfo
*) self
->info
));
1471 static PyMethodDef _PyGIEnumInfo_methods
[] = {
1472 { "get_values", (PyCFunction
) _wrap_g_enum_info_get_values
, METH_NOARGS
},
1473 { "is_flags", (PyCFunction
) _wrap_g_enum_info_is_flags
, METH_NOARGS
},
1474 { "get_methods", (PyCFunction
) _wrap_g_enum_info_get_methods
, METH_NOARGS
},
1475 { "get_storage_type", (PyCFunction
) _wrap_g_enum_info_get_storage_type
, METH_NOARGS
},
1481 PYGLIB_DEFINE_TYPE ("ObjectInfo", PyGIObjectInfo_Type
, PyGIBaseInfo
);
1484 _wrap_g_object_info_get_parent (PyGIBaseInfo
*self
)
1486 return _get_child_info (self
, g_object_info_get_parent
);
1490 _wrap_g_object_info_get_methods (PyGIBaseInfo
*self
)
1492 return _make_infos_tuple (self
, g_object_info_get_n_methods
, g_object_info_get_method
);
1496 _wrap_g_object_info_find_method (PyGIBaseInfo
*self
, PyObject
*py_name
)
1498 return _get_child_info_by_name (self
, py_name
, g_object_info_find_method
);
1502 _wrap_g_object_info_get_fields (PyGIBaseInfo
*self
)
1504 return _make_infos_tuple (self
, g_object_info_get_n_fields
, g_object_info_get_field
);
1508 _wrap_g_object_info_get_properties (PyGIBaseInfo
*self
)
1510 return _make_infos_tuple (self
, g_object_info_get_n_properties
, g_object_info_get_property
);
1514 _wrap_g_object_info_get_signals (PyGIBaseInfo
*self
)
1516 return _make_infos_tuple (self
, g_object_info_get_n_signals
, g_object_info_get_signal
);
1520 _wrap_g_object_info_get_interfaces (PyGIBaseInfo
*self
)
1522 return _make_infos_tuple (self
, g_object_info_get_n_interfaces
, g_object_info_get_interface
);
1526 _wrap_g_object_info_get_constants (PyGIBaseInfo
*self
)
1528 return _make_infos_tuple (self
, g_object_info_get_n_constants
, g_object_info_get_constant
);
1532 _wrap_g_object_info_get_vfuncs (PyGIBaseInfo
*self
)
1534 return _make_infos_tuple (self
, g_object_info_get_n_vfuncs
, g_object_info_get_vfunc
);
1538 _wrap_g_object_info_get_abstract (PyGIBaseInfo
*self
)
1540 gboolean is_abstract
= g_object_info_get_abstract ( (GIObjectInfo
*) self
->info
);
1541 return pygi_gboolean_to_py (is_abstract
);
1545 _wrap_g_object_info_get_type_name (PyGIBaseInfo
*self
)
1547 return _get_info_string (self
, g_object_info_get_type_name
);
1551 _wrap_g_object_info_get_type_init (PyGIBaseInfo
*self
)
1553 return _get_info_string (self
, g_object_info_get_type_init
);
1557 _wrap_g_object_info_get_fundamental (PyGIBaseInfo
*self
)
1559 return pygi_gboolean_to_py (g_object_info_get_fundamental ( (GIObjectInfo
*) self
->info
));
1563 _wrap_g_object_info_get_class_struct (PyGIBaseInfo
*self
)
1565 return _get_child_info (self
, g_object_info_get_class_struct
);
1569 _wrap_g_object_info_find_vfunc (PyGIBaseInfo
*self
, PyObject
*py_name
)
1571 return _get_child_info_by_name (self
, py_name
, g_object_info_find_vfunc
);
1575 _wrap_g_object_info_get_unref_function (PyGIBaseInfo
*self
)
1577 return _get_info_string (self
, g_object_info_get_unref_function
);
1581 _wrap_g_object_info_get_ref_function (PyGIBaseInfo
*self
)
1583 return _get_info_string (self
, g_object_info_get_ref_function
);
1587 _wrap_g_object_info_get_set_value_function (PyGIBaseInfo
*self
)
1589 return _get_info_string (self
, g_object_info_get_set_value_function
);
1593 _wrap_g_object_info_get_get_value_function (PyGIBaseInfo
*self
)
1595 return _get_info_string (self
, g_object_info_get_get_value_function
);
1598 static PyMethodDef _PyGIObjectInfo_methods
[] = {
1599 { "get_parent", (PyCFunction
) _wrap_g_object_info_get_parent
, METH_NOARGS
},
1600 { "get_methods", (PyCFunction
) _wrap_g_object_info_get_methods
, METH_NOARGS
},
1601 { "find_method", (PyCFunction
) _wrap_g_object_info_find_method
, METH_O
},
1602 { "get_fields", (PyCFunction
) _wrap_g_object_info_get_fields
, METH_NOARGS
},
1603 { "get_properties", (PyCFunction
) _wrap_g_object_info_get_properties
, METH_NOARGS
},
1604 { "get_signals", (PyCFunction
) _wrap_g_object_info_get_signals
, METH_NOARGS
},
1605 { "get_interfaces", (PyCFunction
) _wrap_g_object_info_get_interfaces
, METH_NOARGS
},
1606 { "get_constants", (PyCFunction
) _wrap_g_object_info_get_constants
, METH_NOARGS
},
1607 { "get_vfuncs", (PyCFunction
) _wrap_g_object_info_get_vfuncs
, METH_NOARGS
},
1608 { "find_vfunc", (PyCFunction
) _wrap_g_object_info_find_vfunc
, METH_O
},
1609 { "get_abstract", (PyCFunction
) _wrap_g_object_info_get_abstract
, METH_NOARGS
},
1610 { "get_type_name", (PyCFunction
) _wrap_g_object_info_get_type_name
, METH_NOARGS
},
1611 { "get_type_init", (PyCFunction
) _wrap_g_object_info_get_type_init
, METH_NOARGS
},
1612 { "get_fundamental", (PyCFunction
) _wrap_g_object_info_get_fundamental
, METH_NOARGS
},
1613 { "get_class_struct", (PyCFunction
) _wrap_g_object_info_get_class_struct
, METH_NOARGS
},
1614 { "get_unref_function", (PyCFunction
) _wrap_g_object_info_get_unref_function
, METH_NOARGS
},
1615 { "get_ref_function", (PyCFunction
) _wrap_g_object_info_get_ref_function
, METH_NOARGS
},
1616 { "get_set_value_function", (PyCFunction
) _wrap_g_object_info_get_set_value_function
, METH_NOARGS
},
1617 { "get_get_value_function", (PyCFunction
) _wrap_g_object_info_get_get_value_function
, METH_NOARGS
},
1622 /* GIInterfaceInfo */
1623 PYGLIB_DEFINE_TYPE ("InterfaceInfo", PyGIInterfaceInfo_Type
, PyGIBaseInfo
);
1626 _wrap_g_interface_info_get_methods (PyGIBaseInfo
*self
)
1628 return _make_infos_tuple (self
, g_interface_info_get_n_methods
, g_interface_info_get_method
);
1632 _wrap_g_interface_info_find_method (PyGIBaseInfo
*self
, PyObject
*py_name
)
1634 return _get_child_info_by_name (self
, py_name
, g_interface_info_find_method
);
1638 _wrap_g_interface_info_get_constants (PyGIBaseInfo
*self
)
1640 return _make_infos_tuple (self
, g_interface_info_get_n_constants
, g_interface_info_get_constant
);
1644 _wrap_g_interface_info_get_vfuncs (PyGIBaseInfo
*self
)
1646 return _make_infos_tuple (self
, g_interface_info_get_n_vfuncs
, g_interface_info_get_vfunc
);
1650 _wrap_g_interface_info_find_vfunc (PyGIBaseInfo
*self
, PyObject
*py_name
)
1652 return _get_child_info_by_name (self
, py_name
, g_interface_info_find_vfunc
);
1656 _wrap_g_interface_info_get_prerequisites (PyGIBaseInfo
*self
)
1658 return _make_infos_tuple (self
, g_interface_info_get_n_prerequisites
, g_interface_info_get_prerequisite
);
1662 _wrap_g_interface_info_get_properties (PyGIBaseInfo
*self
)
1664 return _make_infos_tuple (self
, g_interface_info_get_n_properties
, g_interface_info_get_property
);
1668 _wrap_g_interface_info_get_iface_struct (PyGIBaseInfo
*self
)
1670 return _get_child_info (self
, g_interface_info_get_iface_struct
);
1674 _wrap_g_interface_info_get_signals (PyGIBaseInfo
*self
)
1676 return _make_infos_tuple (self
, g_interface_info_get_n_signals
, g_interface_info_get_signal
);
1680 _wrap_g_interface_info_find_signal (PyGIBaseInfo
*self
, PyObject
*py_name
)
1682 return _get_child_info_by_name (self
, py_name
, g_interface_info_find_signal
);
1685 static PyMethodDef _PyGIInterfaceInfo_methods
[] = {
1686 { "get_prerequisites", (PyCFunction
) _wrap_g_interface_info_get_prerequisites
, METH_NOARGS
},
1687 { "get_properties", (PyCFunction
) _wrap_g_interface_info_get_properties
, METH_NOARGS
},
1688 { "get_methods", (PyCFunction
) _wrap_g_interface_info_get_methods
, METH_NOARGS
},
1689 { "find_method", (PyCFunction
) _wrap_g_interface_info_find_method
, METH_O
},
1690 { "get_signals", (PyCFunction
) _wrap_g_interface_info_get_signals
, METH_NOARGS
},
1691 { "find_signal", (PyCFunction
) _wrap_g_interface_info_find_signal
, METH_O
},
1692 { "get_vfuncs", (PyCFunction
) _wrap_g_interface_info_get_vfuncs
, METH_NOARGS
},
1693 { "get_constants", (PyCFunction
) _wrap_g_interface_info_get_constants
, METH_NOARGS
},
1694 { "get_iface_struct", (PyCFunction
) _wrap_g_interface_info_get_iface_struct
, METH_NOARGS
},
1695 { "find_vfunc", (PyCFunction
) _wrap_g_interface_info_find_vfunc
, METH_O
},
1699 /* GIConstantInfo */
1700 PYGLIB_DEFINE_TYPE ("gi.ConstantInfo", PyGIConstantInfo_Type
, PyGIBaseInfo
);
1703 _wrap_g_constant_info_get_value (PyGIBaseInfo
*self
)
1705 GITypeInfo
*type_info
;
1706 GIArgument value
= {0};
1708 gboolean free_array
= FALSE
;
1710 if (g_constant_info_get_value ( (GIConstantInfo
*) self
->info
, &value
) < 0) {
1711 PyErr_SetString (PyExc_RuntimeError
, "unable to get value");
1715 type_info
= g_constant_info_get_type ( (GIConstantInfo
*) self
->info
);
1717 if (g_type_info_get_tag (type_info
) == GI_TYPE_TAG_ARRAY
) {
1718 value
.v_pointer
= _pygi_argument_to_array (&value
, NULL
, NULL
, NULL
,
1719 type_info
, &free_array
);
1722 py_value
= _pygi_argument_to_object (&value
, type_info
, GI_TRANSFER_NOTHING
);
1725 g_array_free (value
.v_pointer
, FALSE
);
1728 g_constant_info_free_value (self
->info
, &value
);
1729 g_base_info_unref ( (GIBaseInfo
*) type_info
);
1734 static PyMethodDef _PyGIConstantInfo_methods
[] = {
1735 { "get_value", (PyCFunction
) _wrap_g_constant_info_get_value
, METH_NOARGS
},
1740 PYGLIB_DEFINE_TYPE ("gi.ValueInfo", PyGIValueInfo_Type
, PyGIBaseInfo
);
1743 _wrap_g_value_info_get_value (PyGIBaseInfo
*self
)
1747 value
= g_value_info_get_value ( (GIValueInfo
*) self
->info
);
1749 return pygi_gint64_to_py (value
);
1753 static PyMethodDef _PyGIValueInfo_methods
[] = {
1754 { "get_value", (PyCFunction
) _wrap_g_value_info_get_value
, METH_NOARGS
},
1760 PYGLIB_DEFINE_TYPE ("gi.FieldInfo", PyGIFieldInfo_Type
, PyGIBaseInfo
);
1763 _struct_field_array_length_marshal (gsize length_index
,
1764 void *container_ptr
,
1765 void *struct_data_ptr
)
1767 gssize array_len
= -1;
1768 GIFieldInfo
*array_len_field
= NULL
;
1769 GIArgument arg
= {0};
1770 GIBaseInfo
*container_info
= (GIBaseInfo
*)container_ptr
;
1772 switch (g_base_info_get_type (container_info
)) {
1773 case GI_INFO_TYPE_UNION
:
1774 array_len_field
= g_union_info_get_field ((GIUnionInfo
*)container_info
, length_index
);
1776 case GI_INFO_TYPE_STRUCT
:
1777 array_len_field
= g_struct_info_get_field ((GIStructInfo
*)container_info
, length_index
);
1779 case GI_INFO_TYPE_OBJECT
:
1780 array_len_field
= g_object_info_get_field ((GIObjectInfo
*)container_info
, length_index
);
1783 /* Other types don't have fields. */
1784 g_assert_not_reached();
1787 if (array_len_field
== NULL
) {
1791 if (g_field_info_get_field (array_len_field
, struct_data_ptr
, &arg
)) {
1792 GITypeInfo
*array_len_type_info
;
1794 array_len_type_info
= g_field_info_get_type (array_len_field
);
1795 if (array_len_type_info
== NULL
) {
1799 if (!pygi_argument_to_gssize (&arg
,
1800 g_type_info_get_tag (array_len_type_info
),
1805 g_base_info_unref (array_len_type_info
);
1809 g_base_info_unref (array_len_field
);
1814 _pygi_g_registered_type_info_check_object (GIRegisteredTypeInfo
*info
,
1815 gboolean is_instance
,
1822 gchar
*type_name_expected
= NULL
;
1823 GIInfoType interface_type
;
1825 interface_type
= g_base_info_get_type (info
);
1826 if ( (interface_type
== GI_INFO_TYPE_STRUCT
) &&
1827 (g_struct_info_is_foreign ( (GIStructInfo
*) info
))) {
1828 /* TODO: Could we check is the correct foreign type? */
1832 g_type
= g_registered_type_info_get_g_type (info
);
1833 if (g_type
!= G_TYPE_NONE
) {
1834 py_type
= pygi_type_get_from_g_type (g_type
);
1836 py_type
= pygi_type_import_by_gi_info ( (GIBaseInfo
*) info
);
1839 if (py_type
== NULL
) {
1843 g_assert (PyType_Check (py_type
));
1846 retval
= PyObject_IsInstance (object
, py_type
);
1848 type_name_expected
= _pygi_g_base_info_get_fullname (
1849 (GIBaseInfo
*) info
);
1852 if (!PyObject_Type (py_type
)) {
1853 type_name_expected
= "type";
1855 } else if (!PyType_IsSubtype ( (PyTypeObject
*) object
,
1856 (PyTypeObject
*) py_type
)) {
1857 type_name_expected
= _pygi_g_base_info_get_fullname (
1858 (GIBaseInfo
*) info
);
1865 Py_DECREF (py_type
);
1868 PyTypeObject
*object_type
;
1870 if (type_name_expected
== NULL
) {
1874 object_type
= (PyTypeObject
*) PyObject_Type (object
);
1875 if (object_type
== NULL
) {
1879 PyErr_Format (PyExc_TypeError
, "Must be %s, not %s",
1880 type_name_expected
, object_type
->tp_name
);
1882 g_free (type_name_expected
);
1889 _wrap_g_field_info_get_value (PyGIBaseInfo
*self
,
1893 GIBaseInfo
*container_info
;
1894 GIInfoType container_info_type
;
1896 GITypeInfo
*field_type_info
;
1898 PyObject
*py_value
= NULL
;
1899 gboolean free_array
= FALSE
;
1901 memset(&value
, 0, sizeof(GIArgument
));
1903 if (!PyArg_ParseTuple (args
, "O:FieldInfo.get_value", &instance
)) {
1907 container_info
= g_base_info_get_container (self
->info
);
1908 g_assert (container_info
!= NULL
);
1910 /* Check the instance. */
1911 if (!_pygi_g_registered_type_info_check_object ( (GIRegisteredTypeInfo
*) container_info
, TRUE
, instance
)) {
1912 _PyGI_ERROR_PREFIX ("argument 1: ");
1916 /* Get the pointer to the container. */
1917 container_info_type
= g_base_info_get_type (container_info
);
1918 switch (container_info_type
) {
1919 case GI_INFO_TYPE_UNION
:
1920 case GI_INFO_TYPE_STRUCT
:
1921 pointer
= pyg_boxed_get (instance
, void);
1923 case GI_INFO_TYPE_OBJECT
:
1924 pointer
= pygobject_get (instance
);
1927 /* Other types don't have fields. */
1928 g_assert_not_reached();
1931 /* Get the field's value. */
1932 field_type_info
= g_field_info_get_type ( (GIFieldInfo
*) self
->info
);
1934 /* A few types are not handled by g_field_info_get_field, so do it here. */
1935 if (!g_type_info_is_pointer (field_type_info
)
1936 && g_type_info_get_tag (field_type_info
) == GI_TYPE_TAG_INTERFACE
) {
1938 GIInfoType info_type
;
1940 if (! (g_field_info_get_flags ( (GIFieldInfo
*) self
->info
) & GI_FIELD_IS_READABLE
)) {
1941 PyErr_SetString (PyExc_RuntimeError
, "field is not readable");
1945 info
= g_type_info_get_interface (field_type_info
);
1947 info_type
= g_base_info_get_type (info
);
1949 g_base_info_unref (info
);
1951 switch (info_type
) {
1952 case GI_INFO_TYPE_UNION
:
1953 PyErr_SetString (PyExc_NotImplementedError
, "getting an union is not supported yet");
1955 case GI_INFO_TYPE_STRUCT
:
1959 offset
= g_field_info_get_offset ( (GIFieldInfo
*) self
->info
);
1961 value
.v_pointer
= (char*) pointer
+ offset
;
1963 goto argument_to_object
;
1971 if (!g_field_info_get_field ( (GIFieldInfo
*) self
->info
, pointer
, &value
)) {
1972 PyErr_SetString (PyExc_RuntimeError
, "unable to get the value");
1976 if (g_type_info_get_tag (field_type_info
) == GI_TYPE_TAG_ARRAY
) {
1977 value
.v_pointer
= _pygi_argument_to_array (&value
,
1978 _struct_field_array_length_marshal
,
1986 py_value
= _pygi_argument_to_object (&value
, field_type_info
, GI_TRANSFER_NOTHING
);
1989 g_array_free (value
.v_pointer
, FALSE
);
1993 g_base_info_unref ( (GIBaseInfo
*) field_type_info
);
1999 _wrap_g_field_info_set_value (PyGIBaseInfo
*self
,
2004 GIBaseInfo
*container_info
;
2005 GIInfoType container_info_type
;
2007 GITypeInfo
*field_type_info
;
2009 PyObject
*retval
= NULL
;
2011 if (!PyArg_ParseTuple (args
, "OO:FieldInfo.set_value", &instance
, &py_value
)) {
2015 container_info
= g_base_info_get_container (self
->info
);
2016 g_assert (container_info
!= NULL
);
2018 /* Check the instance. */
2019 if (!_pygi_g_registered_type_info_check_object ( (GIRegisteredTypeInfo
*) container_info
, TRUE
, instance
)) {
2020 _PyGI_ERROR_PREFIX ("argument 1: ");
2024 /* Get the pointer to the container. */
2025 container_info_type
= g_base_info_get_type (container_info
);
2026 switch (container_info_type
) {
2027 case GI_INFO_TYPE_UNION
:
2028 case GI_INFO_TYPE_STRUCT
:
2029 pointer
= pyg_boxed_get (instance
, void);
2031 case GI_INFO_TYPE_OBJECT
:
2032 pointer
= pygobject_get (instance
);
2035 /* Other types don't have fields. */
2036 g_assert_not_reached();
2039 field_type_info
= g_field_info_get_type ( (GIFieldInfo
*) self
->info
);
2041 /* Set the field's value. */
2042 /* A few types are not handled by g_field_info_set_field, so do it here. */
2043 if (!g_type_info_is_pointer (field_type_info
)
2044 && g_type_info_get_tag (field_type_info
) == GI_TYPE_TAG_INTERFACE
) {
2046 GIInfoType info_type
;
2048 if (! (g_field_info_get_flags ( (GIFieldInfo
*) self
->info
) & GI_FIELD_IS_WRITABLE
)) {
2049 PyErr_SetString (PyExc_RuntimeError
, "field is not writable");
2053 info
= g_type_info_get_interface (field_type_info
);
2055 info_type
= g_base_info_get_type (info
);
2057 switch (info_type
) {
2058 case GI_INFO_TYPE_UNION
:
2059 PyErr_SetString (PyExc_NotImplementedError
, "setting an union is not supported yet");
2061 case GI_INFO_TYPE_STRUCT
:
2067 is_simple
= pygi_g_struct_info_is_simple ( (GIStructInfo
*) info
);
2070 PyErr_SetString (PyExc_TypeError
,
2071 "cannot set a structure which has no well-defined ownership transfer rules");
2072 g_base_info_unref (info
);
2076 value
= _pygi_argument_from_object (py_value
, field_type_info
, GI_TRANSFER_NOTHING
);
2077 if (PyErr_Occurred()) {
2078 g_base_info_unref (info
);
2082 offset
= g_field_info_get_offset ( (GIFieldInfo
*) self
->info
);
2083 size
= g_struct_info_get_size ( (GIStructInfo
*) info
);
2084 g_assert (size
> 0);
2086 g_memmove ((char*) pointer
+ offset
, value
.v_pointer
, size
);
2088 g_base_info_unref (info
);
2098 g_base_info_unref (info
);
2099 } else if (g_type_info_is_pointer (field_type_info
)
2100 && (g_type_info_get_tag (field_type_info
) == GI_TYPE_TAG_VOID
2101 || g_type_info_get_tag (field_type_info
) == GI_TYPE_TAG_UTF8
)) {
2103 value
= _pygi_argument_from_object (py_value
, field_type_info
, GI_TRANSFER_NOTHING
);
2104 if (PyErr_Occurred()) {
2108 offset
= g_field_info_get_offset ((GIFieldInfo
*) self
->info
);
2109 G_STRUCT_MEMBER (gpointer
, pointer
, offset
) = (gpointer
)value
.v_pointer
;
2115 value
= _pygi_argument_from_object (py_value
, field_type_info
, GI_TRANSFER_EVERYTHING
);
2116 if (PyErr_Occurred()) {
2120 if (!g_field_info_set_field ( (GIFieldInfo
*) self
->info
, pointer
, &value
)) {
2121 _pygi_argument_release (&value
, field_type_info
, GI_TRANSFER_NOTHING
, GI_DIRECTION_IN
);
2122 PyErr_SetString (PyExc_RuntimeError
, "unable to set value for field");
2129 g_base_info_unref ( (GIBaseInfo
*) field_type_info
);
2131 Py_XINCREF (retval
);
2136 _wrap_g_field_info_get_flags (PyGIBaseInfo
*self
)
2138 return pygi_guint_to_py (g_field_info_get_flags (self
->info
));
2142 _wrap_g_field_info_get_size (PyGIBaseInfo
*self
)
2144 return pygi_gint_to_py (g_field_info_get_size (self
->info
));
2148 _wrap_g_field_info_get_offset (PyGIBaseInfo
*self
)
2150 return pygi_gint_to_py (g_field_info_get_offset (self
->info
));
2154 _wrap_g_field_info_get_type (PyGIBaseInfo
*self
)
2156 return _get_child_info (self
, g_field_info_get_type
);
2159 static PyMethodDef _PyGIFieldInfo_methods
[] = {
2160 { "get_value", (PyCFunction
) _wrap_g_field_info_get_value
, METH_VARARGS
},
2161 { "set_value", (PyCFunction
) _wrap_g_field_info_set_value
, METH_VARARGS
},
2162 { "get_flags", (PyCFunction
) _wrap_g_field_info_get_flags
, METH_VARARGS
},
2163 { "get_size", (PyCFunction
) _wrap_g_field_info_get_size
, METH_VARARGS
},
2164 { "get_offset", (PyCFunction
) _wrap_g_field_info_get_offset
, METH_VARARGS
},
2165 { "get_type", (PyCFunction
) _wrap_g_field_info_get_type
, METH_VARARGS
},
2170 /* GIUnresolvedInfo */
2171 PYGLIB_DEFINE_TYPE ("gi.UnresolvedInfo", PyGIUnresolvedInfo_Type
, PyGIBaseInfo
);
2173 static PyMethodDef _PyGIUnresolvedInfo_methods
[] = {
2178 PYGLIB_DEFINE_TYPE ("gi.VFuncInfo", PyGIVFuncInfo_Type
, PyGICallableInfo
);
2181 _wrap_g_vfunc_info_get_flags (PyGIBaseInfo
*self
)
2183 return pygi_guint_to_py (g_vfunc_info_get_flags ((GIVFuncInfo
*) self
->info
));
2187 _wrap_g_vfunc_info_get_offset (PyGIBaseInfo
*self
)
2189 return pygi_gint_to_py (g_vfunc_info_get_offset ((GIVFuncInfo
*) self
->info
));
2193 _wrap_g_vfunc_info_get_signal (PyGIBaseInfo
*self
)
2195 return _get_child_info (self
, g_vfunc_info_get_signal
);
2199 _wrap_g_vfunc_info_get_invoker (PyGIBaseInfo
*self
)
2201 return _get_child_info (self
, g_vfunc_info_get_invoker
);
2204 static PyMethodDef _PyGIVFuncInfo_methods
[] = {
2205 { "get_flags", (PyCFunction
) _wrap_g_vfunc_info_get_flags
, METH_NOARGS
},
2206 { "get_offset", (PyCFunction
) _wrap_g_vfunc_info_get_offset
, METH_NOARGS
},
2207 { "get_signal", (PyCFunction
) _wrap_g_vfunc_info_get_signal
, METH_NOARGS
},
2208 { "get_invoker", (PyCFunction
) _wrap_g_vfunc_info_get_invoker
, METH_NOARGS
},
2214 PYGLIB_DEFINE_TYPE ("gi.UnionInfo", PyGIUnionInfo_Type
, PyGIBaseInfo
);
2217 _wrap_g_union_info_get_fields (PyGIBaseInfo
*self
)
2219 return _make_infos_tuple (self
, g_union_info_get_n_fields
, g_union_info_get_field
);
2223 _wrap_g_union_info_get_methods (PyGIBaseInfo
*self
)
2225 return _make_infos_tuple (self
, g_union_info_get_n_methods
, g_union_info_get_method
);
2229 _wrap_g_union_info_get_size (PyGIBaseInfo
*self
)
2231 return pygi_gsize_to_py (g_union_info_get_size (self
->info
));
2234 static PyMethodDef _PyGIUnionInfo_methods
[] = {
2235 { "get_fields", (PyCFunction
) _wrap_g_union_info_get_fields
, METH_NOARGS
},
2236 { "get_methods", (PyCFunction
) _wrap_g_union_info_get_methods
, METH_NOARGS
},
2237 { "get_size", (PyCFunction
) _wrap_g_union_info_get_size
, METH_NOARGS
},
2244 _pygi_g_base_info_get_fullname (GIBaseInfo
*info
)
2246 GIBaseInfo
*container_info
;
2249 container_info
= g_base_info_get_container (info
);
2250 if (container_info
!= NULL
) {
2251 fullname
= g_strdup_printf ("%s.%s.%s",
2252 g_base_info_get_namespace (container_info
),
2253 _safe_base_info_get_name (container_info
),
2254 _safe_base_info_get_name (info
));
2256 fullname
= g_strdup_printf ("%s.%s",
2257 g_base_info_get_namespace (info
),
2258 _safe_base_info_get_name (info
));
2261 if (fullname
== NULL
) {
2270 * Returns 0 on success, or -1 and sets an exception.
2273 pygi_info_register_types (PyObject
*m
)
2275 #define _PyGI_REGISTER_TYPE(m, type, cname, base) \
2276 Py_TYPE(&type) = &PyType_Type; \
2277 type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE); \
2278 type.tp_weaklistoffset = offsetof(PyGIBaseInfo, inst_weakreflist); \
2279 type.tp_methods = _PyGI##cname##_methods; \
2280 type.tp_base = &base; \
2281 if (PyType_Ready(&type) < 0) \
2283 Py_INCREF ((PyObject *)&type); \
2284 if (PyModule_AddObject(m, #cname, (PyObject *)&type) < 0) { \
2285 Py_DECREF ((PyObject *)&type); \
2289 Py_TYPE(&PyGIBaseInfo_Type
) = &PyType_Type
;
2291 PyGIBaseInfo_Type
.tp_dealloc
= (destructor
) _base_info_dealloc
;
2292 PyGIBaseInfo_Type
.tp_repr
= (reprfunc
) _base_info_repr
;
2293 PyGIBaseInfo_Type
.tp_flags
= (Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
);
2294 PyGIBaseInfo_Type
.tp_weaklistoffset
= offsetof(PyGIBaseInfo
, inst_weakreflist
);
2295 PyGIBaseInfo_Type
.tp_methods
= _PyGIBaseInfo_methods
;
2296 PyGIBaseInfo_Type
.tp_richcompare
= (richcmpfunc
)_base_info_richcompare
;
2297 PyGIBaseInfo_Type
.tp_getset
= _base_info_getsets
;
2298 PyGIBaseInfo_Type
.tp_getattro
= (getattrofunc
) _base_info_getattro
;
2300 if (PyType_Ready(&PyGIBaseInfo_Type
) < 0)
2302 Py_INCREF ((PyObject
*)&PyGIBaseInfo_Type
);
2303 if (PyModule_AddObject(m
, "BaseInfo", (PyObject
*)&PyGIBaseInfo_Type
) < 0) {
2304 Py_DECREF ((PyObject
*)&PyGIBaseInfo_Type
);
2308 PyGICallableInfo_Type
.tp_call
= (ternaryfunc
) _callable_info_call
;
2309 PyGICallableInfo_Type
.tp_dealloc
= (destructor
) _callable_info_dealloc
;
2310 _PyGI_REGISTER_TYPE (m
, PyGICallableInfo_Type
, CallableInfo
,
2313 PyGIFunctionInfo_Type
.tp_call
= (ternaryfunc
) _function_info_call
;
2314 PyGIFunctionInfo_Type
.tp_descr_get
= (descrgetfunc
) _function_info_descr_get
;
2315 _PyGI_REGISTER_TYPE (m
, PyGIFunctionInfo_Type
, FunctionInfo
,
2316 PyGICallableInfo_Type
);
2318 PyGIVFuncInfo_Type
.tp_descr_get
= (descrgetfunc
) _vfunc_info_descr_get
;
2319 _PyGI_REGISTER_TYPE (m
, PyGIVFuncInfo_Type
, VFuncInfo
,
2320 PyGICallableInfo_Type
);
2322 _PyGI_REGISTER_TYPE (m
, PyGISignalInfo_Type
, SignalInfo
,
2323 PyGICallableInfo_Type
);
2325 _PyGI_REGISTER_TYPE (m
, PyGIUnresolvedInfo_Type
, UnresolvedInfo
,
2327 _PyGI_REGISTER_TYPE (m
, PyGICallbackInfo_Type
, CallbackInfo
,
2328 PyGICallableInfo_Type
);
2329 _PyGI_REGISTER_TYPE (m
, PyGIRegisteredTypeInfo_Type
, RegisteredTypeInfo
,
2331 _PyGI_REGISTER_TYPE (m
, PyGIStructInfo_Type
, StructInfo
,
2332 PyGIRegisteredTypeInfo_Type
);
2333 _PyGI_REGISTER_TYPE (m
, PyGIEnumInfo_Type
, EnumInfo
,
2334 PyGIRegisteredTypeInfo_Type
);
2335 _PyGI_REGISTER_TYPE (m
, PyGIObjectInfo_Type
, ObjectInfo
,
2336 PyGIRegisteredTypeInfo_Type
);
2337 _PyGI_REGISTER_TYPE (m
, PyGIInterfaceInfo_Type
, InterfaceInfo
,
2338 PyGIRegisteredTypeInfo_Type
);
2339 _PyGI_REGISTER_TYPE (m
, PyGIConstantInfo_Type
, ConstantInfo
,
2341 _PyGI_REGISTER_TYPE (m
, PyGIValueInfo_Type
, ValueInfo
,
2343 _PyGI_REGISTER_TYPE (m
, PyGIFieldInfo_Type
, FieldInfo
,
2345 _PyGI_REGISTER_TYPE (m
, PyGIUnionInfo_Type
, UnionInfo
,
2346 PyGIRegisteredTypeInfo_Type
);
2347 _PyGI_REGISTER_TYPE (m
, PyGIErrorDomainInfo_Type
, ErrorDomainInfo
,
2349 _PyGI_REGISTER_TYPE (m
, PyGIPropertyInfo_Type
, PropertyInfo
,
2351 _PyGI_REGISTER_TYPE (m
, PyGIArgInfo_Type
, ArgInfo
,
2353 _PyGI_REGISTER_TYPE (m
, PyGITypeInfo_Type
, TypeInfo
,
2356 #undef _PyGI_REGISTER_TYPE
2358 #define _PyGI_ENUM_BEGIN(name) \
2360 const char *__enum_name = #name; \
2361 PyObject *__enum_value = NULL; \
2362 PyObject *__new_enum_cls = NULL; \
2363 PyObject *__enum_instance_dict = PyDict_New(); \
2364 PyObject *__module_name = PyObject_GetAttrString (m, "__name__"); \
2365 PyDict_SetItemString (__enum_instance_dict, "__module__", __module_name); \
2366 Py_DECREF (__module_name);
2368 #define _PyGI_ENUM_ADD_VALUE(prefix, name) \
2369 __enum_value = pygi_guint_to_py (prefix##_##name); \
2370 if (PyDict_SetItemString(__enum_instance_dict, #name, __enum_value) < 0) { \
2371 Py_DECREF (__enum_instance_dict); \
2372 Py_DECREF (__enum_value); \
2375 Py_DECREF (__enum_value);
2377 #define _PyGI_ENUM_END \
2378 __new_enum_cls = PyObject_CallFunction ((PyObject *)&PyType_Type, "s(O)O", \
2379 __enum_name, (PyObject *)&PyType_Type, \
2380 __enum_instance_dict); \
2381 Py_DECREF (__enum_instance_dict); \
2382 PyModule_AddObject (m, __enum_name, __new_enum_cls); /* steals ref */ \
2387 _PyGI_ENUM_BEGIN (Direction
)
2388 _PyGI_ENUM_ADD_VALUE (GI_DIRECTION
, IN
)
2389 _PyGI_ENUM_ADD_VALUE (GI_DIRECTION
, OUT
)
2390 _PyGI_ENUM_ADD_VALUE (GI_DIRECTION
, INOUT
)
2395 _PyGI_ENUM_BEGIN (Transfer
)
2396 _PyGI_ENUM_ADD_VALUE (GI_TRANSFER
, NOTHING
)
2397 _PyGI_ENUM_ADD_VALUE (GI_TRANSFER
, CONTAINER
)
2398 _PyGI_ENUM_ADD_VALUE (GI_TRANSFER
, EVERYTHING
)
2402 _PyGI_ENUM_BEGIN (ArrayType
)
2403 _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE
, C
)
2404 _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE
, ARRAY
)
2405 _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE
, PTR_ARRAY
)
2406 _PyGI_ENUM_ADD_VALUE (GI_ARRAY_TYPE
, BYTE_ARRAY
)
2410 _PyGI_ENUM_BEGIN (ScopeType
)
2411 _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE
, INVALID
)
2412 _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE
, CALL
)
2413 _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE
, ASYNC
)
2414 _PyGI_ENUM_ADD_VALUE (GI_SCOPE_TYPE
, NOTIFIED
)
2417 /* GIVFuncInfoFlags */
2418 _PyGI_ENUM_BEGIN (VFuncInfoFlags
)
2419 _PyGI_ENUM_ADD_VALUE (GI_VFUNC_MUST
, CHAIN_UP
)
2420 _PyGI_ENUM_ADD_VALUE (GI_VFUNC_MUST
, OVERRIDE
)
2421 _PyGI_ENUM_ADD_VALUE (GI_VFUNC_MUST
, NOT_OVERRIDE
)
2424 /* GIFieldInfoFlags */
2425 _PyGI_ENUM_BEGIN (FieldInfoFlags
)
2426 _PyGI_ENUM_ADD_VALUE (GI_FIELD
, IS_READABLE
)
2427 _PyGI_ENUM_ADD_VALUE (GI_FIELD
, IS_WRITABLE
)
2430 /* GIFunctionInfoFlags */
2431 _PyGI_ENUM_BEGIN (FunctionInfoFlags
)
2432 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION
, IS_METHOD
)
2433 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION
, IS_CONSTRUCTOR
)
2434 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION
, IS_GETTER
)
2435 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION
, IS_SETTER
)
2436 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION
, WRAPS_VFUNC
)
2437 _PyGI_ENUM_ADD_VALUE (GI_FUNCTION
, THROWS
)
2441 _PyGI_ENUM_BEGIN (TypeTag
)
2443 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, VOID
)
2444 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, BOOLEAN
)
2445 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, INT8
)
2446 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, UINT8
)
2447 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, INT16
)
2448 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, UINT16
)
2449 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, INT32
)
2450 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, UINT32
)
2451 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, INT64
)
2452 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, UINT64
)
2453 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, FLOAT
)
2454 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, DOUBLE
)
2455 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, GTYPE
)
2456 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, UTF8
)
2457 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, FILENAME
)
2459 /* Non-basic types; compare with G_TYPE_TAG_IS_BASIC */
2460 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, ARRAY
)
2461 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, INTERFACE
)
2462 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, GLIST
)
2463 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, GSLIST
)
2464 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, GHASH
)
2465 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, ERROR
)
2467 /* Another basic type */
2468 _PyGI_ENUM_ADD_VALUE (GI_TYPE_TAG
, UNICHAR
)
2472 _PyGI_ENUM_BEGIN (InfoType
)
2473 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, INVALID
)
2474 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, FUNCTION
)
2475 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, CALLBACK
)
2476 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, STRUCT
)
2477 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, BOXED
)
2478 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, ENUM
)
2479 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, FLAGS
)
2480 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, OBJECT
)
2481 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, INTERFACE
)
2482 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, CONSTANT
)
2483 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, INVALID_0
)
2484 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, UNION
)
2485 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, VALUE
)
2486 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, SIGNAL
)
2487 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, VFUNC
)
2488 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, PROPERTY
)
2489 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, FIELD
)
2490 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, ARG
)
2491 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, TYPE
)
2492 _PyGI_ENUM_ADD_VALUE (GI_INFO_TYPE
, UNRESOLVED
)
2495 #undef _PyGI_ENUM_BEGIN
2496 #undef _PyGI_ENUM_ADD_VALUE
2497 #undef _PyGI_ENUM_END