[pybank] Implement structs in return values
- From: Johan Dahlin <johan src gnome org>
- To: svn-commits-list gnome org
- Subject: [pybank] Implement structs in return values
- Date: Tue, 2 Jun 2009 10:44:27 -0400 (EDT)
commit b1b94ddce907d65bd8ca079ef545a0f423e95e13
Author: Tomeu Vizoso <tomeu sugarlabs org>
Date: Fri May 8 17:27:50 2009 +0200
Implement structs in return values
---
bank/bank-argument.c | 9 +++++----
everything_unittest.py | 6 +++---
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/bank/bank-argument.c b/bank/bank-argument.c
index 97ac87d..babb023 100644
--- a/bank/bank-argument.c
+++ b/bank/bank-argument.c
@@ -120,13 +120,14 @@ pyg_argument_to_pyobject(GArgument *arg, GITypeInfo *type_info)
const gchar *module_name = g_base_info_get_namespace(interface_info);
const gchar *type_name = g_base_info_get_name(interface_info);
PyObject *module = PyImport_ImportModule(module_name);
- PyTypeObject *tp = (PyTypeObject *)PyObject_GetAttrString(module, type_name);
+ PyObject *tp = PyObject_GetAttrString(module, type_name);
+ gsize size = g_struct_info_get_size ((GIStructInfo*)type_info);
+ PyObject *buffer = PyBuffer_FromReadWriteMemory(arg->v_pointer, size);
+ PyObject *args = Py_BuildValue("(O)", buffer);
- // TODO: Pass a reference to the arg->v_pointer
- obj = PyObject_GC_New(PyObject, tp);
+ obj = PyObject_Call(tp, args, NULL);
if (obj == NULL)
return NULL;
- PyObject_GC_Track(obj);
Py_INCREF(obj);
return obj;
} else if (interface_type == GI_INFO_TYPE_ENUM) {
diff --git a/everything_unittest.py b/everything_unittest.py
index 5e39871..e083c62 100644
--- a/everything_unittest.py
+++ b/everything_unittest.py
@@ -207,9 +207,9 @@ class TestGIEverything(unittest.TestCase):
# i = Everything.test_int_value_arg(42)
# self.assertEquals(42, i)
-# def testValueReturn(self):
-# i = Everything.test_value_return(42)
-# self.assertEquals(42, i)
+ def testValueReturn(self):
+ i = Everything.test_value_return(42)
+ self.assertEquals(42, i)
def testEnum(self):
self.assertEqual('value1', Everything.test_enum_param(Everything.TestEnum.VALUE1))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]