1 /* -*- Mode: C; c-basic-offset: 4 -*-
2 * pygtk- Python bindings for the GTK toolkit.
3 * Copyright (C) 1998-2003 James Henstridge
5 * pygtype.c: glue code to wrap the GType code.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
29 #include "pygobject-private.h"
30 #include "pygparamspec.h"
33 /* -------------- __gtype__ objects ---------------------------- */
40 PYGLIB_DEFINE_TYPE("gobject.GType", PyGTypeWrapper_Type, PyGTypeWrapper);
43 pyg_type_wrapper_richcompare(PyObject *self, PyObject *other, int op)
45 if (Py_TYPE(self) == Py_TYPE(other) && Py_TYPE(self) == &PyGTypeWrapper_Type)
46 return _pyglib_generic_long_richcompare(((PyGTypeWrapper*)self)->type,
47 ((PyGTypeWrapper*)other)->type,
50 Py_INCREF(Py_NotImplemented);
51 return Py_NotImplemented;
56 pyg_type_wrapper_hash(PyGTypeWrapper *self)
58 return (long)self->type;
62 pyg_type_wrapper_repr(PyGTypeWrapper *self)
65 const gchar *name = g_type_name(self->type);
67 g_snprintf(buf, sizeof(buf), "<GType %s (%lu)>",
68 name?name:"invalid", (unsigned long int) self->type);
69 return PYGLIB_PyUnicode_FromString(buf);
73 pyg_type_wrapper_dealloc(PyGTypeWrapper *self)
79 _pyg_type_key(GType type) {
82 if (g_type_is_a(type, G_TYPE_INTERFACE)) {
83 key = pyginterface_type_key;
84 } else if (g_type_is_a(type, G_TYPE_ENUM)) {
85 key = pygenum_class_key;
86 } else if (g_type_is_a(type, G_TYPE_FLAGS)) {
87 key = pygflags_class_key;
88 } else if (g_type_is_a(type, G_TYPE_POINTER)) {
89 key = pygpointer_class_key;
90 } else if (g_type_is_a(type, G_TYPE_BOXED)) {
91 key = pygboxed_type_key;
93 key = pygobject_class_key;
100 _wrap_g_type_wrapper__get_pytype(PyGTypeWrapper *self, void *closure)
105 key = _pyg_type_key(self->type);
107 py_type = g_type_get_qdata(self->type, key);
116 _wrap_g_type_wrapper__set_pytype(PyGTypeWrapper *self, PyObject* value, void *closure)
121 key = _pyg_type_key(self->type);
123 py_type = g_type_get_qdata(self->type, key);
125 if (value == Py_None)
126 g_type_set_qdata(self->type, key, NULL);
127 else if (PyType_Check(value)) {
129 g_type_set_qdata(self->type, key, value);
131 PyErr_SetString(PyExc_TypeError, "Value must be None or a type object");
139 _wrap_g_type_wrapper__get_name(PyGTypeWrapper *self, void *closure)
141 const char *name = g_type_name(self->type);
142 return PYGLIB_PyUnicode_FromString(name ? name : "invalid");
146 _wrap_g_type_wrapper__get_parent(PyGTypeWrapper *self, void *closure)
148 return pyg_type_wrapper_new(g_type_parent(self->type));
152 _wrap_g_type_wrapper__get_fundamental(PyGTypeWrapper *self, void *closure)
154 return pyg_type_wrapper_new(g_type_fundamental(self->type));
158 _wrap_g_type_wrapper__get_children(PyGTypeWrapper *self, void *closure)
164 children = g_type_children(self->type, &n_children);
166 retval = PyList_New(n_children);
167 for (i = 0; i < n_children; i++)
168 PyList_SetItem(retval, i, pyg_type_wrapper_new(children[i]));
175 _wrap_g_type_wrapper__get_interfaces(PyGTypeWrapper *self, void *closure)
177 guint n_interfaces, i;
181 interfaces = g_type_interfaces(self->type, &n_interfaces);
183 retval = PyList_New(n_interfaces);
184 for (i = 0; i < n_interfaces; i++)
185 PyList_SetItem(retval, i, pyg_type_wrapper_new(interfaces[i]));
192 _wrap_g_type_wrapper__get_depth(PyGTypeWrapper *self, void *closure)
194 return PYGLIB_PyLong_FromLong(g_type_depth(self->type));
197 static PyGetSetDef _PyGTypeWrapper_getsets[] = {
198 { "pytype", (getter)_wrap_g_type_wrapper__get_pytype, (setter)_wrap_g_type_wrapper__set_pytype },
199 { "name", (getter)_wrap_g_type_wrapper__get_name, (setter)0 },
200 { "fundamental", (getter)_wrap_g_type_wrapper__get_fundamental, (setter)0 },
201 { "parent", (getter)_wrap_g_type_wrapper__get_parent, (setter)0 },
202 { "children", (getter)_wrap_g_type_wrapper__get_children, (setter)0 },
203 { "interfaces", (getter)_wrap_g_type_wrapper__get_interfaces, (setter)0 },
204 { "depth", (getter)_wrap_g_type_wrapper__get_depth, (setter)0 },
205 { NULL, (getter)0, (setter)0 }
209 _wrap_g_type_is_interface(PyGTypeWrapper *self)
211 return PyBool_FromLong(G_TYPE_IS_INTERFACE(self->type));
215 _wrap_g_type_is_classed(PyGTypeWrapper *self)
217 return PyBool_FromLong(G_TYPE_IS_CLASSED(self->type));
221 _wrap_g_type_is_instantiatable(PyGTypeWrapper *self)
223 return PyBool_FromLong(G_TYPE_IS_INSTANTIATABLE(self->type));
227 _wrap_g_type_is_derivable(PyGTypeWrapper *self)
229 return PyBool_FromLong(G_TYPE_IS_DERIVABLE(self->type));
233 _wrap_g_type_is_deep_derivable(PyGTypeWrapper *self)
235 return PyBool_FromLong(G_TYPE_IS_DEEP_DERIVABLE(self->type));
239 _wrap_g_type_is_abstract(PyGTypeWrapper *self)
241 return PyBool_FromLong(G_TYPE_IS_ABSTRACT(self->type));
245 _wrap_g_type_is_value_abstract(PyGTypeWrapper *self)
247 return PyBool_FromLong(G_TYPE_IS_VALUE_ABSTRACT(self->type));
251 _wrap_g_type_is_value_type(PyGTypeWrapper *self)
253 return PyBool_FromLong(G_TYPE_IS_VALUE_TYPE(self->type));
257 _wrap_g_type_has_value_table(PyGTypeWrapper *self)
259 return PyBool_FromLong(G_TYPE_HAS_VALUE_TABLE(self->type));
263 _wrap_g_type_from_name(PyGTypeWrapper *_, PyObject *args)
268 if (!PyArg_ParseTuple(args, "s:GType.from_name", &type_name))
271 type = _pyg_type_from_name(type_name);
273 PyErr_SetString(PyExc_RuntimeError, "unknown type name");
277 return pyg_type_wrapper_new(type);
281 _wrap_g_type_is_a(PyGTypeWrapper *self, PyObject *args)
286 if (!PyArg_ParseTuple(args, "O:GType.is_a", &gparent))
288 else if ((parent = pyg_type_from_object(gparent)) == 0)
291 return PyBool_FromLong(g_type_is_a(self->type, parent));
294 static PyMethodDef _PyGTypeWrapper_methods[] = {
295 { "is_interface", (PyCFunction)_wrap_g_type_is_interface, METH_NOARGS },
296 { "is_classed", (PyCFunction)_wrap_g_type_is_classed, METH_NOARGS },
297 { "is_instantiatable", (PyCFunction)_wrap_g_type_is_instantiatable, METH_NOARGS },
298 { "is_derivable", (PyCFunction)_wrap_g_type_is_derivable, METH_NOARGS },
299 { "is_deep_derivable", (PyCFunction)_wrap_g_type_is_deep_derivable, METH_NOARGS },
300 { "is_abstract", (PyCFunction)_wrap_g_type_is_abstract, METH_NOARGS },
301 { "is_value_abstract", (PyCFunction)_wrap_g_type_is_value_abstract, METH_NOARGS },
302 { "is_value_type", (PyCFunction)_wrap_g_type_is_value_type, METH_NOARGS },
303 { "has_value_table", (PyCFunction)_wrap_g_type_has_value_table, METH_NOARGS },
304 { "from_name", (PyCFunction)_wrap_g_type_from_name, METH_VARARGS | METH_STATIC },
305 { "is_a", (PyCFunction)_wrap_g_type_is_a, METH_VARARGS },
310 pyg_type_wrapper_init(PyGTypeWrapper *self, PyObject *args, PyObject *kwargs)
312 static char *kwlist[] = { "object", NULL };
316 if (!PyArg_ParseTupleAndKeywords(args, kwargs,
321 if (!(type = pyg_type_from_object(py_object)))
330 * pyg_type_wrapper_new:
333 * Creates a Python wrapper for a GType.
335 * Returns: the Python wrapper.
338 pyg_type_wrapper_new(GType type)
340 PyGTypeWrapper *self;
342 self = (PyGTypeWrapper *)PyObject_NEW(PyGTypeWrapper,
343 &PyGTypeWrapper_Type);
348 return (PyObject *)self;
352 * pyg_type_from_object_strict:
353 * obj: a Python object
354 * strict: if set to TRUE, raises an exception if it can't perform the
357 * converts a python object to a GType. If strict is set, raises an
358 * exception if it can't perform the conversion, otherwise returns
361 * Returns: the corresponding GType, or 0 on error.
365 pyg_type_from_object_strict(PyObject *obj, gboolean strict)
372 PyErr_SetString(PyExc_TypeError, "can't get type from NULL object");
376 /* map some standard types to primitive GTypes ... */
379 if (PyType_Check(obj)) {
380 PyTypeObject *tp = (PyTypeObject *)obj;
382 if (tp == &PYGLIB_PyLong_Type)
384 else if (tp == &PyBool_Type)
385 return G_TYPE_BOOLEAN;
386 else if (tp == &PyLong_Type)
388 else if (tp == &PyFloat_Type)
389 return G_TYPE_DOUBLE;
390 else if (tp == &PYGLIB_PyUnicode_Type)
391 return G_TYPE_STRING;
392 else if (tp == &PyBaseObject_Type)
393 return PY_TYPE_OBJECT;
396 if (Py_TYPE(obj) == &PyGTypeWrapper_Type) {
397 return ((PyGTypeWrapper *)obj)->type;
401 if (PYGLIB_PyUnicode_Check(obj)) {
402 gchar *name = PYGLIB_PyUnicode_AsString(obj);
404 type = _pyg_type_from_name(name);
410 /* finally, look for a __gtype__ attribute on the object */
411 gtype = PyObject_GetAttrString(obj, "__gtype__");
414 if (Py_TYPE(gtype) == &PyGTypeWrapper_Type) {
415 type = ((PyGTypeWrapper *)gtype)->type;
424 /* Some API like those that take GValues can hold a python object as
425 * a pointer. This is potentially dangerous becuase everything is
426 * passed in as a PyObject so we can't actually type check it. Only
427 * fallback to PY_TYPE_OBJECT if strict checking is disabled
430 return PY_TYPE_OBJECT;
432 PyErr_SetString(PyExc_TypeError, "could not get typecode from object");
437 * pyg_type_from_object:
438 * obj: a Python object
440 * converts a python object to a GType. Raises an exception if it
441 * can't perform the conversion.
443 * Returns: the corresponding GType, or 0 on error.
446 pyg_type_from_object(PyObject *obj)
448 /* Legacy call always defaults to strict type checking */
449 return pyg_type_from_object_strict(obj, TRUE);
452 /* -------------- GValue marshalling ------------------ */
455 * pyg_enum_get_value:
456 * @enum_type: the GType of the flag.
457 * @obj: a Python object representing the flag value
458 * @val: a pointer to the location to store the integer representation of the flag.
460 * Converts a Python object to the integer equivalent. The conversion
461 * will depend on the type of the Python object. If the object is an
462 * integer, it is passed through directly. If it is a string, it will
463 * be treated as a full or short enum name as defined in the GType.
465 * Returns: 0 on success or -1 on failure
468 pyg_enum_get_value(GType enum_type, PyObject *obj, gint *val)
470 GEnumClass *eclass = NULL;
473 g_return_val_if_fail(val != NULL, -1);
477 } else if (PYGLIB_PyLong_Check(obj)) {
478 *val = PYGLIB_PyLong_AsLong(obj);
481 if (PyObject_TypeCheck(obj, &PyGEnum_Type) && ((PyGEnum *) obj)->gtype != enum_type) {
482 g_warning("expected enumeration type %s, but got %s instead",
483 g_type_name(enum_type),
484 g_type_name(((PyGEnum *) obj)->gtype));
486 /* Dumb code duplication, but probably not worth it to have yet another macro. */
487 } else if (PyLong_Check(obj)) {
488 *val = PyLong_AsLong(obj);
491 if (PyObject_TypeCheck(obj, &PyGEnum_Type) && ((PyGEnum *) obj)->gtype != enum_type) {
492 g_warning("expected enumeration type %s, but got %s instead",
493 g_type_name(enum_type),
494 g_type_name(((PyGEnum *) obj)->gtype));
496 } else if (PYGLIB_PyUnicode_Check(obj)) {
498 char *str = PYGLIB_PyUnicode_AsString(obj);
500 if (enum_type != G_TYPE_NONE)
501 eclass = G_ENUM_CLASS(g_type_class_ref(enum_type));
503 PyErr_SetString(PyExc_TypeError, "could not convert string to enum because there is no GType associated to look up the value");
506 info = g_enum_get_value_by_name(eclass, str);
507 g_type_class_unref(eclass);
510 info = g_enum_get_value_by_nick(eclass, str);
515 PyErr_SetString(PyExc_TypeError, "could not convert string");
519 PyErr_SetString(PyExc_TypeError,"enum values must be strings or ints");
526 * pyg_flags_get_value:
527 * @flag_type: the GType of the flag.
528 * @obj: a Python object representing the flag value
529 * @val: a pointer to the location to store the integer representation of the flag.
531 * Converts a Python object to the integer equivalent. The conversion
532 * will depend on the type of the Python object. If the object is an
533 * integer, it is passed through directly. If it is a string, it will
534 * be treated as a full or short flag name as defined in the GType.
535 * If it is a tuple, then the items are treated as strings and ORed
538 * Returns: 0 on success or -1 on failure
541 pyg_flags_get_value(GType flag_type, PyObject *obj, gint *val)
543 GFlagsClass *fclass = NULL;
546 g_return_val_if_fail(val != NULL, -1);
550 } else if (PYGLIB_PyLong_Check(obj)) {
551 *val = PYGLIB_PyLong_AsLong(obj);
553 } else if (PyLong_Check(obj)) {
554 *val = PyLong_AsLongLong(obj);
556 } else if (PYGLIB_PyUnicode_Check(obj)) {
558 char *str = PYGLIB_PyUnicode_AsString(obj);
560 if (flag_type != G_TYPE_NONE)
561 fclass = G_FLAGS_CLASS(g_type_class_ref(flag_type));
563 PyErr_SetString(PyExc_TypeError, "could not convert string to flag because there is no GType associated to look up the value");
566 info = g_flags_get_value_by_name(fclass, str);
567 g_type_class_unref(fclass);
570 info = g_flags_get_value_by_nick(fclass, str);
575 PyErr_SetString(PyExc_TypeError, "could not convert string");
578 } else if (PyTuple_Check(obj)) {
581 len = PyTuple_Size(obj);
585 if (flag_type != G_TYPE_NONE)
586 fclass = G_FLAGS_CLASS(g_type_class_ref(flag_type));
588 PyErr_SetString(PyExc_TypeError, "could not convert string to flag because there is no GType associated to look up the value");
592 for (i = 0; i < len; i++) {
593 PyObject *item = PyTuple_GetItem(obj, i);
594 char *str = PYGLIB_PyUnicode_AsString(item);
595 GFlagsValue *info = g_flags_get_value_by_name(fclass, str);
598 info = g_flags_get_value_by_nick(fclass, str);
602 PyErr_SetString(PyExc_TypeError, "could not convert string");
607 g_type_class_unref(fclass);
609 PyErr_SetString(PyExc_TypeError,
610 "flag values must be strings, ints, longs, or tuples");
617 fromvaluefunc fromvalue;
620 static GQuark pyg_type_marshal_key = 0;
622 static PyGTypeMarshal *
623 pyg_type_lookup(GType type)
626 PyGTypeMarshal *tm = NULL;
628 /* recursively lookup types */
630 if ((tm = g_type_get_qdata(ptype, pyg_type_marshal_key)) != NULL)
632 ptype = g_type_parent(ptype);
638 * pyg_register_gtype_custom:
639 * @gtype: the GType for the new type
640 * @from_func: a function to convert GValues to Python objects
641 * @to_func: a function to convert Python objects to GValues
643 * In order to handle specific conversion of gboxed types or new
644 * fundamental types, you may use this function to register conversion
649 pyg_register_gtype_custom(GType gtype,
650 fromvaluefunc from_func,
655 if (!pyg_type_marshal_key)
656 pyg_type_marshal_key = g_quark_from_static_string("PyGType::marshal");
658 tm = g_new(PyGTypeMarshal, 1);
659 tm->fromvalue = from_func;
660 tm->tovalue = to_func;
661 g_type_set_qdata(gtype, pyg_type_marshal_key, tm);
665 pyg_value_array_from_pyobject(GValue *value,
667 const GParamSpecValueArray *pspec)
670 GValueArray *value_array;
673 len = PySequence_Length(obj);
679 if (pspec && pspec->fixed_n_elements > 0 && len != pspec->fixed_n_elements)
682 value_array = g_value_array_new(len);
684 for (i = 0; i < len; ++i) {
685 PyObject *item = PySequence_GetItem(obj, i);
687 GValue item_value = { 0, };
692 g_value_array_free(value_array);
696 if (pspec && pspec->element_spec)
697 type = G_PARAM_SPEC_VALUE_TYPE(pspec->element_spec);
698 else if (item == Py_None)
699 type = G_TYPE_POINTER; /* store None as NULL */
701 type = pyg_type_from_object((PyObject*)Py_TYPE(item));
704 g_value_array_free(value_array);
710 g_value_init(&item_value, type);
711 status = (pspec && pspec->element_spec)
712 ? pyg_param_gvalue_from_pyobject(&item_value, item, pspec->element_spec)
713 : pyg_value_from_pyobject(&item_value, item);
717 g_value_array_free(value_array);
718 g_value_unset(&item_value);
722 g_value_array_append(value_array, &item_value);
723 g_value_unset(&item_value);
726 g_value_take_boxed(value, value_array);
731 * pyg_value_from_pyobject:
732 * @value: the GValue object to store the converted value in.
733 * @obj: the Python object to convert.
735 * This function converts a Python object and stores the result in a
736 * GValue. The GValue must be initialised in advance with
737 * g_value_init(). If the Python object can't be converted to the
738 * type of the GValue, then an error is returned.
740 * Returns: 0 on success, -1 on error.
743 pyg_value_from_pyobject(GValue *value, PyObject *obj)
747 switch (G_TYPE_FUNDAMENTAL(G_VALUE_TYPE(value))) {
748 case G_TYPE_INTERFACE:
749 /* we only handle interface types that have a GObject prereq */
750 if (g_type_is_a(G_VALUE_TYPE(value), G_TYPE_OBJECT)) {
752 g_value_set_object(value, NULL);
754 if (!PyObject_TypeCheck(obj, &PyGObject_Type)) {
757 if (!G_TYPE_CHECK_INSTANCE_TYPE(pygobject_get(obj),
758 G_VALUE_TYPE(value))) {
761 g_value_set_object(value, pygobject_get(obj));
768 #if PY_VERSION_HEX < 0x03000000
769 if (PyString_Check(obj)) {
770 g_value_set_char(value, PyString_AsString(obj)[0]);
773 if (PyUnicode_Check(obj)) {
774 tmp = PyUnicode_AsUTF8String(obj);
775 g_value_set_char(value, PYGLIB_PyBytes_AsString(tmp)[0]);
784 if (PYGLIB_PyLong_Check(obj)) {
786 val = PYGLIB_PyLong_AsLong(obj);
787 if (val >= 0 && val <= 255)
788 g_value_set_uchar(value, (guchar)PYGLIB_PyLong_AsLong (obj));
791 #if PY_VERSION_HEX < 0x03000000
792 } else if (PyString_Check(obj)) {
793 g_value_set_uchar(value, PyString_AsString(obj)[0]);
795 } else if (PyUnicode_Check(obj)) {
796 tmp = PyUnicode_AsUTF8String(obj);
797 g_value_set_uchar(value, PYGLIB_PyBytes_AsString(tmp)[0]);
805 g_value_set_boolean(value, PyObject_IsTrue(obj));
808 g_value_set_int(value, PYGLIB_PyLong_AsLong(obj));
812 if (PYGLIB_PyLong_Check(obj)) {
815 val = PYGLIB_PyLong_AsLong(obj);
816 if (val >= 0 && val <= G_MAXUINT)
817 g_value_set_uint(value, (guint)val);
821 g_value_set_uint(value, PyLong_AsUnsignedLong(obj));
826 g_value_set_long(value, PYGLIB_PyLong_AsLong(obj));
829 #if PY_VERSION_HEX < 0x03000000
830 if (PyInt_Check(obj)) {
833 val = PYGLIB_PyLong_AsLong(obj);
835 PyErr_SetString(PyExc_OverflowError, "negative value not allowed for uint64 property");
838 g_value_set_ulong(value, (gulong)val);
841 if (PyLong_Check(obj))
842 g_value_set_ulong(value, PyLong_AsUnsignedLong(obj));
847 g_value_set_int64(value, PyLong_AsLongLong(obj));
850 #if PY_VERSION_HEX < 0x03000000
851 if (PyInt_Check(obj)) {
852 long v = PyInt_AsLong(obj);
854 PyErr_SetString(PyExc_OverflowError, "negative value not allowed for uint64 property");
857 g_value_set_uint64(value, v);
860 if (PyLong_Check(obj))
861 g_value_set_uint64(value, PyLong_AsUnsignedLongLong(obj));
868 if (pyg_enum_get_value(G_VALUE_TYPE(value), obj, &val) < 0) {
872 g_value_set_enum(value, val);
878 if (pyg_flags_get_value(G_VALUE_TYPE(value), obj, &val) < 0) {
882 g_value_set_flags(value, val);
886 g_value_set_float(value, PyFloat_AsDouble(obj));
889 g_value_set_double(value, PyFloat_AsDouble(obj));
892 if (obj == Py_None) {
893 g_value_set_string(value, NULL);
895 PyObject* tmp_str = PyObject_Str(obj);
896 if (tmp_str == NULL) {
898 if (PyUnicode_Check(obj)) {
899 tmp = PyUnicode_AsUTF8String(obj);
900 g_value_set_string(value, PYGLIB_PyBytes_AsString(tmp));
906 #if PY_VERSION_HEX < 0x03000000
907 g_value_set_string(value, PyString_AsString(tmp_str));
909 tmp = PyUnicode_AsUTF8String(tmp_str);
910 g_value_set_string(value, PyBytes_AsString(tmp));
919 g_value_set_pointer(value, NULL);
920 else if (PyObject_TypeCheck(obj, &PyGPointer_Type) &&
921 G_VALUE_HOLDS(value, ((PyGPointer *)obj)->gtype))
922 g_value_set_pointer(value, pyg_pointer_get(obj, gpointer));
923 else if (PYGLIB_CPointer_Check(obj))
924 g_value_set_pointer(value, PYGLIB_CPointer_GetPointer(obj, NULL));
932 g_value_set_boxed(value, NULL);
933 else if (G_VALUE_HOLDS(value, PY_TYPE_OBJECT))
934 g_value_set_boxed(value, obj);
935 else if (PyObject_TypeCheck(obj, &PyGBoxed_Type) &&
936 G_VALUE_HOLDS(value, ((PyGBoxed *)obj)->gtype))
937 g_value_set_boxed(value, pyg_boxed_get(obj, gpointer));
938 else if (G_VALUE_HOLDS(value, G_TYPE_VALUE)) {
942 type = pyg_type_from_object((PyObject*)Py_TYPE(obj));
943 if (G_UNLIKELY (! type)) {
947 n_value = g_new0 (GValue, 1);
948 g_value_init (n_value, type);
949 g_value_take_boxed (value, n_value);
950 return pyg_value_from_pyobject (n_value, obj);
952 else if (PySequence_Check(obj) &&
953 G_VALUE_HOLDS(value, G_TYPE_VALUE_ARRAY))
954 return pyg_value_array_from_pyobject(value, obj, NULL);
955 else if (PYGLIB_PyUnicode_Check(obj) &&
956 G_VALUE_HOLDS(value, G_TYPE_GSTRING)) {
960 if (PYGLIB_PyUnicode_AsStringAndSize(obj, &buffer, &len))
962 string = g_string_new_len(buffer, len);
963 g_value_set_boxed(value, string);
964 g_string_free (string, TRUE);
967 else if ((bm = pyg_type_lookup(G_VALUE_TYPE(value))) != NULL)
968 return bm->tovalue(value, obj);
969 else if (PYGLIB_CPointer_Check(obj))
970 g_value_set_boxed(value, PYGLIB_CPointer_GetPointer(obj, NULL));
976 if (PyGParamSpec_Check(obj))
977 g_value_set_param(value, PYGLIB_CPointer_GetPointer(obj, NULL));
982 if (obj == Py_None) {
983 g_value_set_object(value, NULL);
984 } else if (PyObject_TypeCheck(obj, &PyGObject_Type) &&
985 G_TYPE_CHECK_INSTANCE_TYPE(pygobject_get(obj),
986 G_VALUE_TYPE(value))) {
987 g_value_set_object(value, pygobject_get(obj));
994 if ((bm = pyg_type_lookup(G_VALUE_TYPE(value))) != NULL)
995 return bm->tovalue(value, obj);
999 if (PyErr_Occurred()) {
1000 g_value_unset(value);
1008 * pyg_value_as_pyobject:
1009 * @value: the GValue object.
1010 * @copy_boxed: true if boxed values should be copied.
1012 * This function creates/returns a Python wrapper object that
1013 * represents the GValue passed as an argument.
1015 * Returns: a PyObject representing the value.
1018 pyg_value_as_pyobject(const GValue *value, gboolean copy_boxed)
1022 switch (G_TYPE_FUNDAMENTAL(G_VALUE_TYPE(value))) {
1023 case G_TYPE_INTERFACE:
1024 if (g_type_is_a(G_VALUE_TYPE(value), G_TYPE_OBJECT))
1025 return pygobject_new_sunk(g_value_get_object(value));
1029 gint8 val = g_value_get_char(value);
1030 return PYGLIB_PyUnicode_FromStringAndSize((char *)&val, 1);
1032 case G_TYPE_UCHAR: {
1033 guint8 val = g_value_get_uchar(value);
1034 return PYGLIB_PyBytes_FromStringAndSize((char *)&val, 1);
1036 case G_TYPE_BOOLEAN: {
1037 return PyBool_FromLong(g_value_get_boolean(value));
1040 return PYGLIB_PyLong_FromLong(g_value_get_int(value));
1043 /* in Python, the Int object is backed by a long. If a
1044 long can hold the whole value of an unsigned int, use
1045 an Int. Otherwise, use a Long object to avoid overflow.
1046 This matches the ULongArg behavior in codegen/argtypes.h */
1047 #if (G_MAXUINT <= G_MAXLONG)
1048 return PYGLIB_PyLong_FromLong((glong) g_value_get_uint(value));
1050 return PyLong_FromUnsignedLong((gulong) g_value_get_uint(value));
1054 return PYGLIB_PyLong_FromLong(g_value_get_long(value));
1057 gulong val = g_value_get_ulong(value);
1059 if (val <= G_MAXLONG)
1060 return PYGLIB_PyLong_FromLong((glong) val);
1062 return PyLong_FromUnsignedLong(val);
1066 gint64 val = g_value_get_int64(value);
1068 if (G_MINLONG <= val && val <= G_MAXLONG)
1069 return PYGLIB_PyLong_FromLong((glong) val);
1071 return PyLong_FromLongLong(val);
1075 guint64 val = g_value_get_uint64(value);
1077 if (val <= G_MAXLONG)
1078 return PYGLIB_PyLong_FromLong((glong) val);
1080 return PyLong_FromUnsignedLongLong(val);
1083 return pyg_enum_from_gtype(G_VALUE_TYPE(value), g_value_get_enum(value));
1085 return pyg_flags_from_gtype(G_VALUE_TYPE(value), g_value_get_flags(value));
1087 return PyFloat_FromDouble(g_value_get_float(value));
1089 return PyFloat_FromDouble(g_value_get_double(value));
1092 const gchar *str = g_value_get_string(value);
1095 return PYGLIB_PyUnicode_FromString(str);
1099 case G_TYPE_POINTER:
1100 return pyg_pointer_new(G_VALUE_TYPE(value),
1101 g_value_get_pointer(value));
1102 case G_TYPE_BOXED: {
1105 if (G_VALUE_HOLDS(value, PY_TYPE_OBJECT)) {
1106 PyObject *ret = (PyObject *)g_value_dup_boxed(value);
1112 } else if (G_VALUE_HOLDS(value, G_TYPE_VALUE)) {
1113 GValue *n_value = g_value_get_boxed (value);
1114 return pyg_value_as_pyobject(n_value, copy_boxed);
1115 } else if (G_VALUE_HOLDS(value, G_TYPE_VALUE_ARRAY)) {
1116 GValueArray *array = (GValueArray *) g_value_get_boxed(value);
1117 PyObject *ret = PyList_New(array->n_values);
1119 for (i = 0; i < array->n_values; ++i)
1120 PyList_SET_ITEM(ret, i, pyg_value_as_pyobject
1121 (array->values + i, copy_boxed));
1123 } else if (G_VALUE_HOLDS(value, G_TYPE_GSTRING)) {
1124 GString *string = (GString *) g_value_get_boxed(value);
1125 PyObject *ret = PYGLIB_PyUnicode_FromStringAndSize(string->str, string->len);
1128 bm = pyg_type_lookup(G_VALUE_TYPE(value));
1130 return bm->fromvalue(value);
1133 return pyg_boxed_new(G_VALUE_TYPE(value),
1134 g_value_get_boxed(value), TRUE, TRUE);
1136 return pyg_boxed_new(G_VALUE_TYPE(value),
1137 g_value_get_boxed(value),FALSE,FALSE);
1141 return pyg_param_spec_new(g_value_get_param(value));
1143 return pygobject_new_sunk(g_value_get_object(value));
1147 if ((bm = pyg_type_lookup(G_VALUE_TYPE(value))))
1148 return bm->fromvalue(value);
1152 g_snprintf(buf, sizeof(buf), "unknown type %s",
1153 g_type_name(G_VALUE_TYPE(value)));
1154 PyErr_SetString(PyExc_TypeError, buf);
1158 /* -------------- PyGClosure ----------------- */
1161 pyg_closure_invalidate(gpointer data, GClosure *closure)
1163 PyGClosure *pc = (PyGClosure *)closure;
1164 PyGILState_STATE state;
1166 state = pyglib_gil_state_ensure();
1167 Py_XDECREF(pc->callback);
1168 Py_XDECREF(pc->extra_args);
1169 Py_XDECREF(pc->swap_data);
1170 pyglib_gil_state_release(state);
1172 pc->callback = NULL;
1173 pc->extra_args = NULL;
1174 pc->swap_data = NULL;
1178 pyg_closure_marshal(GClosure *closure,
1179 GValue *return_value,
1180 guint n_param_values,
1181 const GValue *param_values,
1182 gpointer invocation_hint,
1183 gpointer marshal_data)
1185 PyGILState_STATE state;
1186 PyGClosure *pc = (PyGClosure *)closure;
1187 PyObject *params, *ret;
1190 state = pyglib_gil_state_ensure();
1192 /* construct Python tuple for the parameter values */
1193 params = PyTuple_New(n_param_values);
1194 for (i = 0; i < n_param_values; i++) {
1195 /* swap in a different initial data for connect_object() */
1196 if (i == 0 && G_CCLOSURE_SWAP_DATA(closure)) {
1197 g_return_if_fail(pc->swap_data != NULL);
1198 Py_INCREF(pc->swap_data);
1199 PyTuple_SetItem(params, 0, pc->swap_data);
1201 PyObject *item = pyg_value_as_pyobject(¶m_values[i], FALSE);
1203 /* error condition */
1207 PyTuple_SetItem(params, i, item);
1210 /* params passed to function may have extra arguments */
1211 if (pc->extra_args) {
1212 PyObject *tuple = params;
1213 params = PySequence_Concat(tuple, pc->extra_args);
1216 ret = PyObject_CallObject(pc->callback, params);
1218 if (pc->exception_handler)
1219 pc->exception_handler(return_value, n_param_values, param_values);
1225 if (return_value && pyg_value_from_pyobject(return_value, ret) != 0) {
1226 PyErr_SetString(PyExc_TypeError,
1227 "can't convert return value to desired type");
1229 if (pc->exception_handler)
1230 pc->exception_handler(return_value, n_param_values, param_values);
1238 pyglib_gil_state_release(state);
1243 * callback: a Python callable object
1244 * extra_args: a tuple of extra arguments, or None/NULL.
1245 * swap_data: an alternative python object to pass first.
1247 * Creates a GClosure wrapping a Python callable and optionally a set
1248 * of additional function arguments. This is needed to attach python
1249 * handlers to signals, for instance.
1251 * Returns: the new closure.
1254 pyg_closure_new(PyObject *callback, PyObject *extra_args, PyObject *swap_data)
1258 g_return_val_if_fail(callback != NULL, NULL);
1259 closure = g_closure_new_simple(sizeof(PyGClosure), NULL);
1260 g_closure_add_invalidate_notifier(closure, NULL, pyg_closure_invalidate);
1261 g_closure_set_marshal(closure, pyg_closure_marshal);
1262 Py_INCREF(callback);
1263 ((PyGClosure *)closure)->callback = callback;
1264 if (extra_args && extra_args != Py_None) {
1265 Py_INCREF(extra_args);
1266 if (!PyTuple_Check(extra_args)) {
1267 PyObject *tmp = PyTuple_New(1);
1268 PyTuple_SetItem(tmp, 0, extra_args);
1271 ((PyGClosure *)closure)->extra_args = extra_args;
1274 Py_INCREF(swap_data);
1275 ((PyGClosure *)closure)->swap_data = swap_data;
1276 closure->derivative_flag = TRUE;
1282 * pyg_closure_set_exception_handler:
1283 * @closure: a closure created with pyg_closure_new()
1284 * @handler: the handler to call when an exception occurs or NULL for none
1286 * Sets the handler to call when an exception occurs during closure invocation.
1287 * The handler is responsible for providing a proper return value to the
1288 * closure invocation. If @handler is %NULL, the default handler will be used.
1289 * The default handler prints the exception to stderr and doesn't touch the
1290 * closure's return value.
1293 pyg_closure_set_exception_handler(GClosure *closure,
1294 PyClosureExceptionHandler handler)
1296 PyGClosure *pygclosure;
1298 g_return_if_fail(closure != NULL);
1300 pygclosure = (PyGClosure *)closure;
1301 pygclosure->exception_handler = handler;
1303 /* -------------- PySignalClassClosure ----------------- */
1304 /* a closure used for the `class closure' of a signal. As this gets
1305 * all the info from the first argument to the closure and the
1306 * invocation hint, we can have a single closure that handles all
1307 * class closure cases. We call a method by the name of the signal
1308 * with "do_" prepended.
1310 * We also remove the first argument from the * param list, as it is
1311 * the instance object, which is passed * implicitly to the method
1315 pyg_signal_class_closure_marshal(GClosure *closure,
1316 GValue *return_value,
1317 guint n_param_values,
1318 const GValue *param_values,
1319 gpointer invocation_hint,
1320 gpointer marshal_data)
1322 PyGILState_STATE state;
1324 PyObject *object_wrapper;
1325 GSignalInvocationHint *hint = (GSignalInvocationHint *)invocation_hint;
1326 gchar *method_name, *tmp;
1328 PyObject *params, *ret;
1331 state = pyglib_gil_state_ensure();
1333 g_return_if_fail(invocation_hint != NULL);
1334 /* get the object passed as the first argument to the closure */
1335 object = g_value_get_object(¶m_values[0]);
1336 g_return_if_fail(object != NULL && G_IS_OBJECT(object));
1338 /* get the wrapper for this object */
1339 object_wrapper = pygobject_new_sunk(object);
1340 g_return_if_fail(object_wrapper != NULL);
1342 /* construct method name for this class closure */
1343 method_name = g_strconcat("do_", g_signal_name(hint->signal_id), NULL);
1345 /* convert dashes to underscores. For some reason, g_signal_name
1346 * seems to convert all the underscores in the signal name to
1348 for (tmp = method_name; *tmp != '\0'; tmp++)
1349 if (*tmp == '-') *tmp = '_';
1351 method = PyObject_GetAttrString(object_wrapper, method_name);
1352 g_free(method_name);
1356 Py_DECREF(object_wrapper);
1357 pyglib_gil_state_release(state);
1360 Py_DECREF(object_wrapper);
1362 /* construct Python tuple for the parameter values; don't copy boxed values
1363 initially because we'll check after the call to see if a copy is needed. */
1364 params = PyTuple_New(n_param_values - 1);
1365 for (i = 1; i < n_param_values; i++) {
1366 PyObject *item = pyg_value_as_pyobject(¶m_values[i], FALSE);
1368 /* error condition */
1371 pyglib_gil_state_release(state);
1374 PyTuple_SetItem(params, i - 1, item);
1377 ret = PyObject_CallObject(method, params);
1379 /* Copy boxed values if others ref them, this needs to be done regardless of
1380 exception status. */
1381 len = PyTuple_Size(params);
1382 for (i = 0; i < len; i++) {
1383 PyObject *item = PyTuple_GetItem(params, i);
1384 if (item != NULL && PyObject_TypeCheck(item, &PyGBoxed_Type)
1385 && item->ob_refcnt != 1) {
1386 PyGBoxed* boxed_item = (PyGBoxed*)item;
1387 if (!boxed_item->free_on_dealloc) {
1388 boxed_item->boxed = g_boxed_copy(boxed_item->gtype, boxed_item->boxed);
1389 boxed_item->free_on_dealloc = TRUE;
1398 pyglib_gil_state_release(state);
1404 pyg_value_from_pyobject(return_value, ret);
1406 pyglib_gil_state_release(state);
1410 * pyg_signal_class_closure_get:
1412 * Returns the GClosure used for the class closure of signals. When
1413 * called, it will invoke the method do_signalname (for the signal
1416 * Returns: the closure.
1419 pyg_signal_class_closure_get(void)
1421 static GClosure *closure;
1423 if (closure == NULL) {
1424 closure = g_closure_new_simple(sizeof(GClosure), NULL);
1425 g_closure_set_marshal(closure, pyg_signal_class_closure_marshal);
1427 g_closure_ref(closure);
1428 g_closure_sink(closure);
1434 gclosure_from_pyfunc(PyGObject *object, PyObject *func)
1437 PyGObjectData *inst_data;
1438 inst_data = pyg_object_peek_inst_data(object->obj);
1440 for (l = inst_data->closures; l; l = l->next) {
1441 PyGClosure *pyclosure = l->data;
1442 int res = PyObject_RichCompareBool(pyclosure->callback, func, Py_EQ);
1444 PyErr_Clear(); // Is there anything else to do?
1446 return (GClosure*)pyclosure;
1453 /* ----- __doc__ descriptor for GObject and GInterface ----- */
1456 object_doc_dealloc(PyObject *self)
1458 PyObject_FREE(self);
1461 /* append information about signals of a particular gtype */
1463 add_signal_docs(GType gtype, GString *string)
1465 GTypeClass *class = NULL;
1466 guint *signal_ids, n_ids = 0, i;
1468 if (G_TYPE_IS_CLASSED(gtype))
1469 class = g_type_class_ref(gtype);
1470 signal_ids = g_signal_list_ids(gtype, &n_ids);
1473 g_string_append_printf(string, "Signals from %s:\n",
1474 g_type_name(gtype));
1476 for (i = 0; i < n_ids; i++) {
1480 g_signal_query(signal_ids[i], &query);
1482 g_string_append(string, " ");
1483 g_string_append(string, query.signal_name);
1484 g_string_append(string, " (");
1485 for (j = 0; j < query.n_params; j++) {
1486 g_string_append(string, g_type_name(query.param_types[j]));
1487 if (j != query.n_params - 1)
1488 g_string_append(string, ", ");
1490 g_string_append(string, ")");
1491 if (query.return_type && query.return_type != G_TYPE_NONE) {
1492 g_string_append(string, " -> ");
1493 g_string_append(string, g_type_name(query.return_type));
1495 g_string_append(string, "\n");
1498 g_string_append(string, "\n");
1501 g_type_class_unref(class);
1505 add_property_docs(GType gtype, GString *string)
1507 GObjectClass *class;
1509 guint n_props = 0, i;
1510 gboolean has_prop = FALSE;
1511 G_CONST_RETURN gchar *blurb=NULL;
1513 class = g_type_class_ref(gtype);
1514 props = g_object_class_list_properties(class, &n_props);
1516 for (i = 0; i < n_props; i++) {
1517 if (props[i]->owner_type != gtype)
1518 continue; /* these are from a parent type */
1520 /* print out the heading first */
1522 g_string_append_printf(string, "Properties from %s:\n",
1523 g_type_name(gtype));
1526 g_string_append_printf(string, " %s -> %s: %s\n",
1527 g_param_spec_get_name(props[i]),
1528 g_type_name(props[i]->value_type),
1529 g_param_spec_get_nick(props[i]));
1531 /* g_string_append_printf crashes on win32 if the third
1532 argument is NULL. */
1533 blurb=g_param_spec_get_blurb(props[i]);
1535 g_string_append_printf(string, " %s\n",blurb);
1539 g_string_append(string, "\n");
1540 g_type_class_unref(class);
1544 object_doc_descr_get(PyObject *self, PyObject *obj, PyObject *type)
1550 if (obj && pygobject_check(obj, &PyGObject_Type)) {
1551 gtype = G_OBJECT_TYPE(pygobject_get(obj));
1553 PyErr_SetString(PyExc_RuntimeError, "could not get object type");
1555 gtype = pyg_type_from_object(type);
1560 string = g_string_new_len(NULL, 512);
1562 if (g_type_is_a(gtype, G_TYPE_INTERFACE))
1563 g_string_append_printf(string, "Interface %s\n\n", g_type_name(gtype));
1564 else if (g_type_is_a(gtype, G_TYPE_OBJECT))
1565 g_string_append_printf(string, "Object %s\n\n", g_type_name(gtype));
1567 g_string_append_printf(string, "%s\n\n", g_type_name(gtype));
1569 if (((PyTypeObject *) type)->tp_doc)
1570 g_string_append_printf(string, "%s\n\n", ((PyTypeObject *) type)->tp_doc);
1572 if (g_type_is_a(gtype, G_TYPE_OBJECT)) {
1573 GType parent = G_TYPE_OBJECT;
1574 GArray *parents = g_array_new(FALSE, FALSE, sizeof(GType));
1578 g_array_append_val(parents, parent);
1579 parent = g_type_next_base(gtype, parent);
1582 for (iparent = parents->len - 1; iparent >= 0; --iparent) {
1584 guint n_interfaces, i;
1586 parent = g_array_index(parents, GType, iparent);
1587 add_signal_docs(parent, string);
1588 add_property_docs(parent, string);
1590 /* add docs for implemented interfaces */
1591 interfaces = g_type_interfaces(parent, &n_interfaces);
1592 for (i = 0; i < n_interfaces; i++)
1593 add_signal_docs(interfaces[i], string);
1596 g_array_free(parents, TRUE);
1599 pystring = PYGLIB_PyUnicode_FromStringAndSize(string->str, string->len);
1600 g_string_free(string, TRUE);
1604 PYGLIB_DEFINE_TYPE("gobject.GObject.__doc__", PyGObjectDoc_Type, PyObject);
1607 * pyg_object_descr_doc_get:
1609 * Returns an object intended to be the __doc__ attribute of GObject
1610 * wrappers. When read in the context of the object it will return
1611 * some documentation about the signals and properties of the object.
1613 * Returns: the descriptor.
1616 pyg_object_descr_doc_get(void)
1618 static PyObject *doc_descr = NULL;
1621 Py_TYPE(&PyGObjectDoc_Type) = &PyType_Type;
1622 if (PyType_Ready(&PyGObjectDoc_Type))
1625 doc_descr = PyObject_NEW(PyObject, &PyGObjectDoc_Type);
1626 if (doc_descr == NULL)
1634 * pyg_pyobj_to_unichar_conv:
1636 * Converts PyObject value to a unichar and write result to memory
1637 * pointed to by ptr. Follows the calling convention of a ParseArgs
1638 * converter (O& format specifier) so it may be used to convert function
1641 * Returns: 1 if the conversion succeeds and 0 otherwise. If the conversion
1642 * did not succeesd, a Python exception is raised
1644 int pyg_pyobj_to_unichar_conv(PyObject* py_obj, void* ptr)
1647 const Py_UNICODE* uni_buffer;
1648 PyObject* tmp_uni = NULL;
1650 if (PyUnicode_Check(py_obj)) {
1655 tmp_uni = PyUnicode_FromObject(py_obj);
1656 if (tmp_uni == NULL)
1660 if ( PyUnicode_GetSize(tmp_uni) != 1) {
1661 PyErr_SetString(PyExc_ValueError, "unicode character value must be 1 character uniode string");
1664 uni_buffer = PyUnicode_AsUnicode(tmp_uni);
1665 if ( uni_buffer == NULL)
1673 Py_XDECREF(tmp_uni);
1679 pyg_param_gvalue_from_pyobject(GValue* value,
1681 const GParamSpec* pspec)
1683 if (G_IS_PARAM_SPEC_UNICHAR(pspec)) {
1686 if (!pyg_pyobj_to_unichar_conv(py_obj, &u)) {
1690 g_value_set_uint(value, u);
1693 else if (G_IS_PARAM_SPEC_VALUE_ARRAY(pspec))
1694 return pyg_value_array_from_pyobject(value, py_obj,
1695 G_PARAM_SPEC_VALUE_ARRAY(pspec));
1697 return pyg_value_from_pyobject(value, py_obj);
1702 pyg_param_gvalue_as_pyobject(const GValue* gvalue,
1703 gboolean copy_boxed,
1704 const GParamSpec* pspec)
1706 if (G_IS_PARAM_SPEC_UNICHAR(pspec)) {
1708 Py_UNICODE uni_buffer[2] = { 0, 0 };
1710 u = g_value_get_uint(gvalue);
1712 return PyUnicode_FromUnicode(uni_buffer, 1);
1715 return pyg_value_as_pyobject(gvalue, copy_boxed);
1720 * pyg_type_registration_callback
1721 * @gtypename: type name
1722 * @callback: function to run
1726 PyGTypeRegistrationFunction callback;
1731 pyg_type_register_custom_callback(const gchar *typename,
1732 PyGTypeRegistrationFunction callback,
1735 CustomTypeData *data;
1737 if (!custom_type_registration)
1738 custom_type_registration = g_hash_table_new_full (g_str_hash, g_str_equal,
1741 data = g_new (CustomTypeData, 1);
1742 data->callback = callback;
1743 data->data = user_data;
1745 g_hash_table_insert(custom_type_registration,
1751 pyg_type_get_custom(const gchar *name)
1753 CustomTypeData *data;
1754 PyTypeObject *retval;
1756 if (!custom_type_registration)
1759 data = g_hash_table_lookup(custom_type_registration, name);
1763 retval = data->callback(name, data->data);
1765 g_hash_table_remove(custom_type_registration, name);
1771 _pyg_type_from_name(const gchar *name)
1775 type = g_type_from_name(name);
1776 if (type == G_TYPE_INVALID) {
1777 pyg_type_get_custom(name);
1778 type = g_type_from_name(name);
1785 _pyg_strv_from_gvalue(const GValue *value)
1787 gchar **argv = (gchar **) g_value_get_boxed(value);
1795 py_argv = PyList_New(argc);
1796 for (i = 0; i < argc; ++i)
1797 PyList_SET_ITEM(py_argv, i, PYGLIB_PyUnicode_FromString(argv[i]));
1802 _pyg_strv_to_gvalue(GValue *value, PyObject *obj)
1807 if (!(PyTuple_Check(obj) || PyList_Check(obj)))
1810 argc = PySequence_Length(obj);
1811 for (i = 0; i < argc; ++i)
1812 if (!PYGLIB_PyUnicode_Check(PySequence_Fast_GET_ITEM(obj, i)))
1814 argv = g_new(gchar *, argc + 1);
1815 for (i = 0; i < argc; ++i)
1816 argv[i] = g_strdup(PYGLIB_PyUnicode_AsString(PySequence_Fast_GET_ITEM(obj, i)));
1818 g_value_take_boxed(value, argv);
1823 pygobject_type_register_types(PyObject *d)
1825 PyGTypeWrapper_Type.tp_dealloc = (destructor)pyg_type_wrapper_dealloc;
1826 PyGTypeWrapper_Type.tp_richcompare = pyg_type_wrapper_richcompare;
1827 PyGTypeWrapper_Type.tp_repr = (reprfunc)pyg_type_wrapper_repr;
1828 PyGTypeWrapper_Type.tp_hash = (hashfunc)pyg_type_wrapper_hash;
1829 PyGTypeWrapper_Type.tp_flags = Py_TPFLAGS_DEFAULT;
1830 PyGTypeWrapper_Type.tp_methods = _PyGTypeWrapper_methods;
1831 PyGTypeWrapper_Type.tp_getset = _PyGTypeWrapper_getsets;
1832 PyGTypeWrapper_Type.tp_init = (initproc)pyg_type_wrapper_init;
1833 PYGLIB_REGISTER_TYPE(d, PyGTypeWrapper_Type, "GType");
1835 /* This type lazily registered in pyg_object_descr_doc_get */
1836 PyGObjectDoc_Type.tp_dealloc = (destructor)object_doc_dealloc;
1837 PyGObjectDoc_Type.tp_flags = Py_TPFLAGS_DEFAULT;
1838 PyGObjectDoc_Type.tp_descr_get = (descrgetfunc)object_doc_descr_get;
1840 pyg_register_gtype_custom(G_TYPE_STRV,
1841 _pyg_strv_from_gvalue,
1842 _pyg_strv_to_gvalue);