summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Dufresne <nicolas.dufresne@collabora.com>2017-03-27 14:59:24 -0400
committerNicolas Dufresne <nicolas.dufresne@collabora.com>2017-03-27 15:02:41 -0400
commitd44975a1fe624e39f9ef480ae0694a77311247c1 (patch)
treed005f1b08f64dc20ff78772efeafeaaff9850a62
parentc6dee2c26b2c87857941c026dc50cce51e25251d (diff)
array/list: Make gvalue conversion symmetric
This is needed to support matrix. Otherwise, getting a matrix would remove the rows envelopess, which would make the "cast" fails, since it would not know if the internal rows are ValueArray or ValueList. I think reading, modifying and setting back the matrix is an important use case.
-rw-r--r--gi/overrides/gstmodule.c18
-rw-r--r--testsuite/test_valuearray.py12
-rw-r--r--testsuite/test_valuelist.py8
3 files changed, 34 insertions, 4 deletions
diff --git a/gi/overrides/gstmodule.c b/gi/overrides/gstmodule.c
index a286ba3f86..a9f4cd1e6b 100644
--- a/gi/overrides/gstmodule.c
+++ b/gi/overrides/gstmodule.c
@@ -323,7 +323,7 @@ fail:
static PyObject *
gi_gst_array_from_value (const GValue * value)
{
- PyObject *list;
+ PyObject *list, *array_type, *array;
gint i;
list = PyList_New (gst_value_array_get_size (value));
@@ -333,7 +333,12 @@ gi_gst_array_from_value (const GValue * value)
PyList_SET_ITEM (list, i, pyg_value_as_pyobject (v, TRUE));
}
- return list;
+ array_type = gi_gst_get_type ("ValueArray");
+ array = PyObject_CallFunction (array_type, "N", list);
+
+ Py_DECREF (array_type);
+
+ return array;
}
static int
@@ -382,7 +387,7 @@ fail:
static PyObject *
gi_gst_list_from_value (const GValue * value)
{
- PyObject *list;
+ PyObject *list, *value_list_type, *value_list;
gint i;
list = PyList_New (gst_value_list_get_size (value));
@@ -392,7 +397,12 @@ gi_gst_list_from_value (const GValue * value)
PyList_SET_ITEM (list, i, pyg_value_as_pyobject (v, TRUE));
}
- return list;
+ value_list_type = gi_gst_get_type ("ValueList");
+ value_list = PyObject_CallFunction (value_list_type, "N", list);
+
+ Py_DECREF (value_list_type);
+
+ return value_list;
}
static int
diff --git a/testsuite/test_valuearray.py b/testsuite/test_valuearray.py
index 9a7771512b..99ddc99576 100644
--- a/testsuite/test_valuearray.py
+++ b/testsuite/test_valuearray.py
@@ -82,6 +82,18 @@ class TestFraction(TestCase):
st = Gst.Structure.new_empty("video/x-raw")
st["array"] = A([Gst.Fraction(1, 30), Gst.Fraction(1, 2)])
value = st["array"]
+ st["array"] = A(value)
self.failUnlessEqual(value[0], Gst.Fraction(1, 30))
self.failUnlessEqual(value[1], Gst.Fraction(1, 2))
+
+ st["matrix"] = A([A([0, 1]), A([-1, 0])])
+ value = st["matrix"]
+
+ self.failUnlessEqual(value[0][0], 0)
+ self.failUnlessEqual(value[0][1], 1)
+ self.failUnlessEqual(value[1][0], -1)
+ self.failUnlessEqual(value[1][1], 0)
+
+
+
diff --git a/testsuite/test_valuelist.py b/testsuite/test_valuelist.py
index b9fa129cb7..fcada681da 100644
--- a/testsuite/test_valuelist.py
+++ b/testsuite/test_valuelist.py
@@ -54,3 +54,11 @@ class TestFraction(TestCase):
self.failUnlessEqual(value[0], Gst.Fraction(1, 30))
self.failUnlessEqual(value[1], Gst.Fraction(1, 2))
+
+ st["matrix"] = L([L([0, 1]), L([-1 ,0])])
+ value = st["matrix"]
+
+ self.failUnlessEqual(value[0][0], 0)
+ self.failUnlessEqual(value[0][1], 1)
+ self.failUnlessEqual(value[1][0], -1)
+ self.failUnlessEqual(value[1][1], 0)