[pygobject] Fix C to Python marshalling of struct pointer arrays



commit d8e241e24a816691acbd592775b73defd9aa4f44
Author: Martin Pitt <martinpitt gnome org>
Date:   Thu Jan 10 15:14:05 2013 +0100

    Fix C to Python marshalling of struct pointer arrays
    
    Do not treat an array of pointers to values like an array of values on
    marshalling from C. This makes the test_array_boxed_struct_return() test case
    work.

 gi/pygi-marshal-to-py.c |    5 +++--
 tests/test_gi.py        |    2 --
 2 files changed, 3 insertions(+), 4 deletions(-)
---
diff --git a/gi/pygi-marshal-to-py.c b/gi/pygi-marshal-to-py.c
index 950895d..d486d28 100644
--- a/gi/pygi-marshal-to-py.c
+++ b/gi/pygi-marshal-to-py.c
@@ -434,13 +434,14 @@ _pygi_marshal_to_py_array (PyGIInvokeState   *state,
                                 item_arg.v_pointer = g_variant_ref_sink (g_array_index (array_, gpointer, i));
                               else
                                 item_arg.v_pointer = g_array_index (array_, gpointer, i);
-                            } else if (arg_cache->transfer == GI_TRANSFER_EVERYTHING) {
+                            } else if (arg_cache->transfer == GI_TRANSFER_EVERYTHING && !item_arg_cache->is_pointer) {
+                                /* array elements are structs */
                                 gpointer *_struct = g_malloc (item_size);
                                 memcpy (_struct, array_->data + i * item_size,
                                         item_size);
                                 item_arg.v_pointer = _struct;
                             } else if (item_arg_cache->is_pointer)
-                                /* this is the case for GAtom* arrays */
+                                /* array elements are pointers to values */
                                 item_arg.v_pointer = g_array_index (array_, gpointer, i);
                             else
                                 item_arg.v_pointer = array_->data + i * item_size;
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 7a0fd80..144fd91 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -836,13 +836,11 @@ class TestArray(unittest.TestCase):
 
         self.assertEqual(1, struct1.long_)
 
-    @unittest.expectedFailure
     def test_array_boxed_struct_return(self):
         (struct1, struct2, struct3) = GIMarshallingTests.array_zero_terminated_return_struct()
         self.assertEqual(GIMarshallingTests.BoxedStruct, type(struct1))
         self.assertEqual(GIMarshallingTests.BoxedStruct, type(struct2))
         self.assertEqual(GIMarshallingTests.BoxedStruct, type(struct3))
-        # FIXME: gets bogus values
         self.assertEqual(42, struct1.long_)
         self.assertEqual(43, struct2.long_)
         self.assertEqual(44, struct3.long_)



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