[pygobject/gsoc2009: 78/160] Improve support for objects as input/output argument
- From: Simon van der Linden <svdlinden src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pygobject/gsoc2009: 78/160] Improve support for objects as input/output argument
- Date: Fri, 14 Aug 2009 21:28:38 +0000 (UTC)
commit 8e91f921d75c36f7314eb2a8cbdafd029649ba28
Author: Simon van der Linden <svdlinden src gnome org>
Date: Wed Jul 29 16:37:38 2009 +0200
Improve support for objects as input/output argument
Modify pygi_py_type_find_by_name not to fail on GObject.object.
Add release support for objects.
Add tests for objects as input and output arguments.
gi/gimodule.c | 10 +++++++++-
gi/pygargument.c | 30 +++++++++++++++++++++++++++++-
tests/test_girepository.py | 11 +++++++++++
3 files changed, 49 insertions(+), 2 deletions(-)
---
diff --git a/gi/gimodule.c b/gi/gimodule.c
index 86e369e..63f8e9f 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -44,7 +44,15 @@ pygi_py_type_find_by_name(const char *namespace_, const char *name)
return NULL;
}
- py_object = PyObject_GetAttrString(py_module, name);
+ if (strcmp(namespace_, "GObject") == 0 &&
+ (strcmp(name, "Object") == 0 || strcmp(name, "InitiallyUnowned") == 0)) {
+ /* Special case for GObject.(Object|InitiallyUnowned) which actually is
+ * gobject.GObject. */
+ py_object = (PyObject *)&PyGObject_Type;
+ Py_INCREF(py_object);
+ } else {
+ py_object = PyObject_GetAttrString(py_module, name);
+ }
Py_DECREF(py_module);
diff --git a/gi/pygargument.c b/gi/pygargument.c
index 1f374eb..330d1a2 100644
--- a/gi/pygargument.c
+++ b/gi/pygargument.c
@@ -867,6 +867,9 @@ array_item_error:
}
case GI_INFO_TYPE_OBJECT:
arg.v_pointer = pygobject_get(object);
+ if (transfer == GI_TRANSFER_EVERYTHING) {
+ g_object_ref(arg.v_pointer);
+ }
break;
default:
/* TODO */
@@ -1467,8 +1470,33 @@ pygi_g_argument_release(GArgument *arg, GITypeInfo *type_info, GITransfer transf
break;
}
case GI_TYPE_TAG_INTERFACE:
- /* TODO */
+ {
+ GIBaseInfo *info;
+ GIInfoType info_type;
+
+ info = g_type_info_get_interface(type_info);
+ g_assert(info != NULL);
+
+ info_type = g_base_info_get_type(info);
+
+ switch (info_type) {
+ case GI_INFO_TYPE_OBJECT:
+ {
+ GObject *object;
+ object = arg->v_pointer;
+ if (direction == GI_DIRECTION_OUT && transfer == GI_TRANSFER_EVERYTHING) {
+ g_object_unref(object);
+ }
+ break;
+ }
+ default:
+ /* TODO */
+ break;
+ }
+
+ g_base_info_unref(info);
break;
+ }
case GI_TYPE_TAG_GLIST:
case GI_TYPE_TAG_GSLIST:
{
diff --git a/tests/test_girepository.py b/tests/test_girepository.py
index f3bf688..1693b89 100644
--- a/tests/test_girepository.py
+++ b/tests/test_girepository.py
@@ -678,6 +678,17 @@ class TestGIEverything(unittest.TestCase):
self.assertRaises(TypeError, Everything.TestObj.static_method)
self.assertRaises(TypeError, Everything.TestObj.static_method, 'foo', 'bar')
+ def testObjIn(self):
+ obj = Everything.TestObj('foo')
+ bare = Everything.TestObj('bar')
+ obj.set_bare(bare)
+
+ def testObjOut(self):
+ obj = Everything.TestObj('foo')
+ bare = Everything.TestObj('bar')
+ obj.set_bare(bare)
+ self.assertTrue(bare is obj.get_bare())
+
# Inheritance
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]