[pygobject] Fix handling of by-reference structs as out parameters



commit 853e6a71234ebd66af5a64dfb296e323c2c905a6
Author: Carlos Garnacho <carlos lanedo com>
Date:   Thu May 17 17:09:15 2012 +0200

    Fix handling of by-reference structs as out parameters
    
    When marshalling back from python, copy the result of by-reference
    structs into the memory expected by the native caller, instead of
    attempting to handle it as a pointer.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=653151
    
    Signed-off-by: Martin Pitt <martinpitt gnome org>

 gi/pygi-closure.c |   17 +++++++++++++++++
 tests/test_gi.py  |    5 +++++
 2 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/gi/pygi-closure.c b/gi/pygi-closure.c
index c89be64..241d91a 100644
--- a/gi/pygi-closure.c
+++ b/gi/pygi-closure.c
@@ -72,6 +72,23 @@ _pygi_closure_assign_pyobj_to_out_argument (gpointer out_arg, PyObject *object,
         case GI_TYPE_TAG_DOUBLE:
            *((gdouble *) out_arg) = arg.v_double;
            break;
+        case GI_TYPE_TAG_INTERFACE:
+        {
+           GIBaseInfo *interface;
+           GIInfoType interface_type;
+
+           interface = g_type_info_get_interface (type_info);
+           interface_type = g_base_info_get_type (interface);
+
+           if (!g_type_info_is_pointer (type_info) &&
+	       interface_type == GI_INFO_TYPE_STRUCT) {
+               gsize item_size = _pygi_g_type_info_size (type_info);
+               memcpy (out_arg, arg.v_pointer, item_size);
+               break;
+           }
+        }
+
+        /* Fall through */
         default:
            *((GIArgument *) out_arg) = arg;
            break;
diff --git a/tests/test_gi.py b/tests/test_gi.py
index b718815..c0e1a4c 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -1629,6 +1629,9 @@ class TestPythonGObject(unittest.TestCase):
         def do_vfunc_return_value_and_multiple_out_parameters(self):
             return (5, 42, 99)
 
+        def do_vfunc_caller_allocated_out_parameter(self):
+            return 'hello'
+
     class SubObject(GIMarshallingTests.SubObject):
         def __init__(self, int):
             GIMarshallingTests.SubObject.__init__(self)
@@ -1665,6 +1668,8 @@ class TestPythonGObject(unittest.TestCase):
         self.assertEqual(object_.vfunc_return_value_and_one_out_parameter(), (5, 42))
         self.assertEqual(object_.vfunc_return_value_and_multiple_out_parameters(), (5, 42, 99))
 
+        self.assertEqual(object_.vfunc_caller_allocated_out_parameter(), 'hello')
+
         class ObjectWithoutVFunc(GIMarshallingTests.Object):
             def __init__(self, int):
                 GIMarshallingTests.Object.__init__(self)



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