summaryrefslogtreecommitdiff
path: root/tests/testhelpermodule.c
diff options
context:
space:
mode:
authorStian Selnes <stian@pexip.com>2017-04-11 11:17:31 +0200
committerChristoph Reiter <reiter.christoph@gmail.com>2018-05-04 18:56:04 +0200
commitb5eab39ebcae061a46c186beac47f7e936ce57c2 (patch)
tree88fb47c789cc6a3c1596e568e29d9ec5ecb2209a /tests/testhelpermodule.c
parent9c671606cc93a06e6db3ee5ee5f0862a7bfc21f9 (diff)
downloadpygobject-b5eab39ebcae061a46c186beac47f7e936ce57c2.tar.gz
gi/pygi-value: Don't wrap GValue in GValue when creating GValueArray
If a GValueArray is created from a list of GValues, it should not wrap these GValues in a second layer of GValues before appending to the array. The end result should be a GValueArray of GValues, not a GValueArray of GValues holding another GValue (unless the user explicitly creates such a value). With this patch the behavior is now consistent when creating a GValueArray and appending GValues directly, and creating a GValueArray within a GValue based on a list of GValues. For instance, to create a GValueArray of G_TYPE_UINT the user must create GValues manually and create a GValueArray from these. The result should be a GValueArray of GValues that hold G_TYPE_UINT, not a GValueArray that contain GValues that hold a GValue that holds G_TYPE_UINT. See !66
Diffstat (limited to 'tests/testhelpermodule.c')
-rw-r--r--tests/testhelpermodule.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/testhelpermodule.c b/tests/testhelpermodule.c
index 3973a503..e26a004b 100644
--- a/tests/testhelpermodule.c
+++ b/tests/testhelpermodule.c
@@ -534,6 +534,43 @@ _wrap_test_value_array(PyObject *self, PyObject *args)
return pyg_value_as_pyobject(value, FALSE);
}
+
+static PyObject *
+_wrap_value_array_get_nth_type(PyObject *self, PyObject *args)
+{
+ guint n;
+ GType type;
+ GValue *nth;
+ GValueArray *arr;
+ PyObject *obj;
+
+ if (!PyArg_ParseTuple(args, "OI", &obj, &n))
+ return NULL;
+
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+
+ if (pyg_boxed_check(obj, G_TYPE_VALUE) &&
+ G_VALUE_HOLDS(pyg_boxed_get(obj, GValue), G_TYPE_VALUE_ARRAY)) {
+ arr = g_value_get_boxed(pyg_boxed_get(obj, GValue));
+ } else if (pyg_boxed_check(obj, G_TYPE_VALUE_ARRAY)) {
+ arr = pyg_boxed_get(obj, GValueArray);
+ } else {
+ PyErr_SetString(PyExc_TypeError, "First argument is not GValueArray");
+ return NULL;
+ }
+
+ if (n >= arr->n_values) {
+ PyErr_SetString(PyExc_TypeError, "Index is out of bounds");
+ return NULL;
+ }
+ nth = g_value_array_get_nth(arr, n);
+ type = G_VALUE_TYPE(nth);
+
+ G_GNUC_END_IGNORE_DEPRECATIONS
+
+ return pyg_type_wrapper_new(type);
+}
+
static PyObject *
_wrap_constant_strip_prefix(PyObject *self, PyObject *args)
{
@@ -665,6 +702,7 @@ static PyMethodDef testhelper_functions[] = {
{ "connectcallbacks", (PyCFunction)_wrap_connectcallbacks, METH_VARARGS },
{ "test_value", (PyCFunction)_wrap_test_value, METH_VARARGS },
{ "test_value_array", (PyCFunction)_wrap_test_value_array, METH_VARARGS },
+ { "value_array_get_nth_type", (PyCFunction)_wrap_value_array_get_nth_type, METH_VARARGS },
{ "constant_strip_prefix", (PyCFunction)_wrap_constant_strip_prefix, METH_VARARGS },
{ "test_gerror_exception", (PyCFunction)_wrap_test_gerror_exception, METH_VARARGS },
{ "owned_by_library_get_instance_list", (PyCFunction)_wrap_test_owned_by_library_get_instance_list, METH_NOARGS },