summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo J. A. M. Carneiro <gjc@src.gnome.org>2007-07-07 12:09:52 +0000
committerGustavo J. A. M. Carneiro <gjc@src.gnome.org>2007-07-07 12:09:52 +0000
commitfe3966c22cbf5e198164b088b4f46f280bc33126 (patch)
tree28011f1aa7ac20608923459f40edec802d11318a
parent73b8042c42ede774597b5bc235a70f8f13643b91 (diff)
downloadpygobject-fe3966c22cbf5e198164b088b4f46f280bc33126.tar.gz
Bug 351072 – Cannot handle signals with parameter type G_TYPE_VALUE (marshal/unmarshal for GValue-wrapped GValue)
svn path=/trunk/; revision=680
-rw-r--r--ChangeLog12
-rw-r--r--gobject/pygtype.c21
-rw-r--r--tests/test_gtype.py5
-rw-r--r--tests/testhelpermodule.c19
4 files changed, 55 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 07ab347d..1a0518be 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2007-07-06 Ed Catmur <ed@catmur.co.uk>
+
+ * gobject/pygtype.c (pyg_param_gvalue_from_pyobject),
+ (pyg_param_gvalue_as_pyobject): Applied patch from Ed Catmur to
+ support G_TYPE_VALUE boxed args/signals, and add a test, Fixes
+ #351072
+
+2007-07-06 Carlos Martin <inean@users.sf.net>
+
+ * tests/test_gtype.py:
+ * tests/testhelpermodule.c: add test for #351072
+
2007-07-04 Murray Cumming <murrayc@murrayc.com>
* gobject/pygobject.c: (pygobject_switch_to_toggle_ref):
diff --git a/gobject/pygtype.c b/gobject/pygtype.c
index 59ba5800..a95fd54a 100644
--- a/gobject/pygtype.c
+++ b/gobject/pygtype.c
@@ -854,7 +854,21 @@ pyg_value_from_pyobject(GValue *value, PyObject *obj)
else if (PyObject_TypeCheck(obj, &PyGBoxed_Type) &&
G_VALUE_HOLDS(value, ((PyGBoxed *)obj)->gtype))
g_value_set_boxed(value, pyg_boxed_get(obj, gpointer));
- else if (PySequence_Check(obj) &&
+ else if (G_VALUE_HOLDS(value, G_TYPE_VALUE)) {
+ GType type;
+ GValue *n_value;
+
+ type = pyg_type_from_object((PyObject *)obj->ob_type);
+ if (G_UNLIKELY (! type)) {
+ PyErr_Clear();
+ return -1;
+ }
+ n_value = g_new0 (GValue, 1);
+ g_value_init (n_value, type);
+ g_value_take_boxed (value, n_value);
+ return pyg_value_from_pyobject (n_value, obj);
+ }
+ else if (PySequence_Check(obj) &&
G_VALUE_HOLDS(value, G_TYPE_VALUE_ARRAY))
return pyg_value_array_from_pyobject(value, obj, NULL);
else if (PyString_Check(obj) &&
@@ -1008,7 +1022,10 @@ pyg_value_as_pyobject(const GValue *value, gboolean copy_boxed)
return Py_None;
}
return ret;
- } else if (G_VALUE_HOLDS(value, G_TYPE_VALUE_ARRAY)) {
+ } else if (G_VALUE_HOLDS(value, G_TYPE_VALUE)) {
+ GValue *n_value = g_value_get_boxed (value);
+ return pyg_value_as_pyobject(n_value, copy_boxed);
+ } else if (G_VALUE_HOLDS(value, G_TYPE_VALUE_ARRAY)) {
GValueArray *array = (GValueArray *) g_value_get_boxed(value);
PyObject *ret = PyList_New(array->n_values);
int i;
diff --git a/tests/test_gtype.py b/tests/test_gtype.py
index df75ccf5..ad54dc62 100644
--- a/tests/test_gtype.py
+++ b/tests/test_gtype.py
@@ -64,6 +64,11 @@ class GTypeTest(unittest.TestCase):
def testObject(self):
self.checkType(gobject.TYPE_OBJECT, 'PyObject')
+ def testValue(self):
+ array = [1, "foo", True]
+ for i in array:
+ self.assertEqual(i, testhelper.test_value(i))
+
def testValueArray(self):
array = [1, 2, 3, "foo", True]
self.assertEqual(array, testhelper.test_value_array(array))
diff --git a/tests/testhelpermodule.c b/tests/testhelpermodule.c
index 8d9419e2..d78cf558 100644
--- a/tests/testhelpermodule.c
+++ b/tests/testhelpermodule.c
@@ -451,6 +451,24 @@ _wrap_connectcallbacks(PyObject * self, PyObject *args)
}
static PyObject *
+_wrap_test_value(PyObject *self, PyObject *args)
+{
+ GValue tvalue = {0,}, *value = &tvalue;
+ PyObject *obj;
+
+ if (!PyArg_ParseTuple(args, "O", &obj))
+ return NULL;
+
+ g_value_init(value, G_TYPE_VALUE);
+ if (pyg_value_from_pyobject(value, obj)) {
+ PyErr_SetString(PyExc_TypeError, "Could not convert to GValue");
+ return NULL;
+ }
+
+ return pyg_value_as_pyobject(value, FALSE);
+}
+
+static PyObject *
_wrap_test_value_array(PyObject *self, PyObject *args)
{
GValue tvalue = {0,}, *value = &tvalue;
@@ -500,6 +518,7 @@ static PyMethodDef testhelper_functions[] = {
{ "create_test_type", (PyCFunction)_wrap_create_test_type, METH_NOARGS },
{ "test_g_object_new", (PyCFunction)_wrap_test_g_object_new, METH_NOARGS },
{ "connectcallbacks", (PyCFunction)_wrap_connectcallbacks, METH_VARARGS },
+ { "test_value", (PyCFunction)_wrap_test_value, METH_VARARGS },
{ "test_value_array", (PyCFunction)_wrap_test_value_array, METH_VARARGS },
{ "test_gerror_exception", (PyCFunction)_wrap_test_gerror_exception, METH_VARARGS },
{ NULL, NULL }