[pygi] Add support for Any arguments



commit fad89e12a744b57e6348968f351d25d167de8248
Author: Tomeu Vizoso <tomeu sugarlabs org>
Date:   Sun Nov 22 17:56:20 2009 +0100

    Add support for Any arguments
    
    https://bugzilla.gnome.org/show_bug.cgi?id=601253

 gi/pygi-argument.c |   20 ++++++++++++--------
 tests/libtestgi.c  |    5 +++++
 tests/libtestgi.h  |    5 +++++
 tests/test_gi.py   |    5 +++++
 4 files changed, 27 insertions(+), 8 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index deaa72a..3a9e207 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -197,11 +197,7 @@ _pygi_g_type_info_check_object (GITypeInfo *type_info,
 
     switch (type_tag) {
         case GI_TYPE_TAG_VOID:
-            if (object != Py_None) {
-                PyErr_Format(PyExc_TypeError, "Must be %s, not %s",
-                        Py_None->ob_type->tp_name, object->ob_type->tp_name);
-                retval = 0;
-            }
+            /* No check; VOID means undefined type */
             break;
         case GI_TYPE_TAG_BOOLEAN:
             /* No check; every Python object has a truth value. */
@@ -624,7 +620,8 @@ _pygi_argument_from_object (PyObject   *object,
 
     switch (type_tag) {
         case GI_TYPE_TAG_VOID:
-            arg.v_pointer = NULL;
+            g_warn_if_fail(transfer == GI_TRANSFER_NOTHING);
+            arg.v_pointer = object;
             break;
         case GI_TYPE_TAG_BOOLEAN:
         {
@@ -1274,8 +1271,13 @@ _pygi_argument_to_object (GArgument  *arg,
 
     switch (type_tag) {
         case GI_TYPE_TAG_VOID:
-            Py_INCREF(Py_None);
-            object = Py_None;
+            if (is_pointer) {
+                /* Raw Python objects are passed to void* args */
+                g_warn_if_fail(transfer == GI_TRANSFER_NOTHING);
+                object = arg->v_pointer;
+            } else
+                object = Py_None;
+            Py_INCREF(object);
             break;
         case GI_TYPE_TAG_BOOLEAN:
         {
@@ -1711,6 +1713,8 @@ _pygi_argument_release (GArgument   *arg,
 
     switch(type_tag) {
         case GI_TYPE_TAG_VOID:
+            /* Don't do anything, it's transparent to the C side */
+            break;
         case GI_TYPE_TAG_BOOLEAN:
         case GI_TYPE_TAG_INT8:
         case GI_TYPE_TAG_UINT8:
diff --git a/tests/libtestgi.c b/tests/libtestgi.c
index ddc99b1..9b278b8 100644
--- a/tests/libtestgi.c
+++ b/tests/libtestgi.c
@@ -2726,6 +2726,11 @@ test_gi_gclosure_in (GClosure *closure)
     g_value_unset(&return_value);
 }
 
+gpointer
+test_gi_pointer_in_return (gpointer pointer)
+{
+    return pointer;
+}
 
 GType
 test_gi_enum_get_type (void)
diff --git a/tests/libtestgi.h b/tests/libtestgi.h
index 9fbdbbd..538f139 100644
--- a/tests/libtestgi.h
+++ b/tests/libtestgi.h
@@ -447,6 +447,11 @@ void test_gi_gvalue_inout (GValue **value);
 void test_gi_gclosure_in (GClosure *closure);
 
 
+/* Pointer */
+
+gpointer test_gi_pointer_in_return (gpointer pointer);
+
+
 /* GEnum */
 
 typedef enum
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 3c72d28..6c63bfc 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -1018,6 +1018,11 @@ class TestGClosure(unittest.TestCase):
         self.assertRaises(TypeError, TestGI.gclosure_in, None)
 
 
+class TestPointer(unittest.TestCase):
+    def test_pointer_in_return(self):
+        self.assertEquals(TestGI.pointer_in_return(42), 42)
+
+
 class TestGEnum(unittest.TestCase):
 
     def test_enum(self):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]