diff options
Diffstat (limited to 'gi/gimodule.c')
-rw-r--r-- | gi/gimodule.c | 93 |
1 files changed, 76 insertions, 17 deletions
diff --git a/gi/gimodule.c b/gi/gimodule.c index df0db7a..89caf4e 100644 --- a/gi/gimodule.c +++ b/gi/gimodule.c @@ -25,6 +25,7 @@ #include "pygi.h" #include <pygobject.h> +#include <pyglib-python-compat.h> static PyObject * _wrap_pyg_enum_add (PyObject *self, @@ -195,12 +196,17 @@ _wrap_pyg_hook_up_vfunc_implementation (PyObject *self, PyObject *args) field_info = g_struct_info_get_field (struct_info, i); if (strcmp (g_base_info_get_name ( (GIBaseInfo*) field_info), - g_base_info_get_name ( (GIBaseInfo*) vfunc_info)) != 0) + g_base_info_get_name ( (GIBaseInfo*) vfunc_info)) != 0) { + g_base_info_unref (field_info); continue; + } type_info = g_field_info_get_type (field_info); - if (g_type_info_get_tag (type_info) != GI_TYPE_TAG_INTERFACE) + if (g_type_info_get_tag (type_info) != GI_TYPE_TAG_INTERFACE) { + g_base_info_unref (type_info); + g_base_info_unref (field_info); continue; + } interface_info = g_type_info_get_interface (type_info); g_assert (g_base_info_get_type (interface_info) == GI_INFO_TYPE_CALLBACK); @@ -229,32 +235,85 @@ _wrap_pyg_hook_up_vfunc_implementation (PyObject *self, PyObject *args) Py_RETURN_NONE; } -static PyMethodDef _pygi_functions[] = { +static PyObject * +_wrap_pyg_variant_new_tuple (PyObject *self, PyObject *args) +{ + PyObject *py_values; + GVariant **values = NULL; + GVariant *variant = NULL; + PyObject *py_variant = NULL; + PyObject *py_type; + gssize i; + + if (!PyArg_ParseTuple (args, "O!:variant_new_tuple", + &PyTuple_Type, &py_values)) { + return NULL; + } + + py_type = _pygi_type_import_by_name ("GLib", "Variant"); + + values = g_newa (GVariant*, PyTuple_Size (py_values)); + + for (i = 0; i < PyTuple_Size (py_values); i++) { + PyObject *value = PyTuple_GET_ITEM (py_values, i); + + if (!PyObject_IsInstance (value, py_type)) { + PyErr_Format (PyExc_TypeError, "argument %d is not a GLib.Variant", i); + return NULL; + } + + values[i] = (GVariant *) ( (PyGPointer *) value)->pointer; + } + + variant = g_variant_new_tuple (values, PyTuple_Size (py_values)); + + py_variant = _pygi_struct_new ( (PyTypeObject *) py_type, variant, FALSE); + + return py_variant; +} + +static PyObject * +_wrap_pyg_variant_type_from_string (PyObject *self, PyObject *args) +{ + char *type_string; + PyObject *py_type; + PyObject *py_variant = NULL; + + if (!PyArg_ParseTuple (args, "s:variant_type_from_string", + &type_string)) { + return NULL; + } + + py_type = _pygi_type_import_by_name ("GLib", "VariantType"); + + py_variant = _pygi_struct_new ( (PyTypeObject *) py_type, type_string, FALSE); + + return py_variant; +} + +static PyMethodDef _gi_functions[] = { { "enum_add", (PyCFunction) _wrap_pyg_enum_add, METH_VARARGS | METH_KEYWORDS }, { "flags_add", (PyCFunction) _wrap_pyg_flags_add, METH_VARARGS | METH_KEYWORDS }, { "set_object_has_new_constructor", (PyCFunction) _wrap_pyg_set_object_has_new_constructor, METH_VARARGS | METH_KEYWORDS }, { "register_interface_info", (PyCFunction) _wrap_pyg_register_interface_info, METH_VARARGS }, { "hook_up_vfunc_implementation", (PyCFunction) _wrap_pyg_hook_up_vfunc_implementation, METH_VARARGS }, + { "variant_new_tuple", (PyCFunction) _wrap_pyg_variant_new_tuple, METH_VARARGS }, + { "variant_type_from_string", (PyCFunction) _wrap_pyg_variant_type_from_string, METH_VARARGS }, { NULL, NULL, 0 } }; static struct PyGI_API CAPI = { pygi_type_import_by_g_type_real, + pygi_get_property_value_real, + pygi_set_property_value_real, pygi_register_foreign_struct_real, }; -PyMODINIT_FUNC -init_gi (void) +PYGLIB_MODULE_START(_gi, "_gi") { - PyObject *m; PyObject *api; - m = Py_InitModule ("_gi", _pygi_functions); - if (m == NULL) { - return; - } - if (pygobject_init (-1, -1, -1) == NULL) { return; } @@ -263,16 +322,16 @@ init_gi (void) return; } - _pygi_repository_register_types (m); - _pygi_info_register_types (m); - _pygi_struct_register_types (m); - _pygi_boxed_register_types (m); + _pygi_repository_register_types (module); + _pygi_info_register_types (module); + _pygi_struct_register_types (module); + _pygi_boxed_register_types (module); _pygi_argument_init(); api = PyCObject_FromVoidPtr ( (void *) &CAPI, NULL); if (api == NULL) { return; } - PyModule_AddObject (m, "_API", api); + PyModule_AddObject (module, "_API", api); } - +PYGLIB_MODULE_END |