[pygobject] fix inline struct array handling



commit f38511f251602e18551c04617cc2e2d42e812e1e
Author: John (J5) Palmieri <johnp redhat com>
Date:   Tue Aug 23 14:18:43 2011 -0400

    fix inline struct array handling
    
    * we now assume any non-boxed structs are inline in an array since there is
       no way to check in GI and this is the most common use for an array of
       non-boxed structs
    
    https://bugzilla.gnome.org/show_bug.cgi?id=657120

 gi/pygi-marshal-out.c |   23 +++++++++--------------
 tests/test_gi.py      |    8 ++++++++
 2 files changed, 17 insertions(+), 14 deletions(-)
---
diff --git a/gi/pygi-marshal-out.c b/gi/pygi-marshal-out.c
index 8adf9ae..ecf8974 100644
--- a/gi/pygi-marshal-out.c
+++ b/gi/pygi-marshal-out.c
@@ -331,20 +331,15 @@ _pygi_marshal_out_array (PyGIInvokeState   *state,
                 if (seq_cache->array_type == GI_ARRAY_TYPE_PTR_ARRAY) {
                     item_arg.v_pointer = g_ptr_array_index ( ( GPtrArray *)array_, i);
                 } else if (item_arg_cache->type_tag == GI_TYPE_TAG_INTERFACE) {
-                    item_arg.v_pointer = g_array_index (array_, gpointer, i);
-                    if (arg_cache->transfer == GI_TRANSFER_EVERYTHING) {
-                       PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *) item_arg_cache;
-                       switch (g_base_info_get_type (iface_cache->interface_info)) {
-                           case GI_INFO_TYPE_STRUCT:
-                           {
-                               gpointer *_struct = g_malloc (item_size);
-                               memcpy (_struct, item_arg.v_pointer, item_size);
-                               item_arg.v_pointer = _struct;
-                               break;
-                           }
-                           default:
-                               break;
-                       }
+                    PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *) item_arg_cache;
+
+                    switch (g_base_info_get_type (iface_cache->interface_info)) {
+                        case GI_INFO_TYPE_STRUCT:
+                            item_arg.v_pointer = array_->data + i * item_size;
+                            break;
+                        default:
+                            item_arg.v_pointer = g_array_index (array_, gpointer, i);
+                            break;
                     }
                 } else {
                     memcpy (&item_arg, array_->data + i * item_size, item_size);
diff --git a/tests/test_gi.py b/tests/test_gi.py
index dddc6fb..c84ca23 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -703,6 +703,14 @@ class TestArray(unittest.TestCase):
         object_ = GIMarshallingTests.Object()
         self.assertEquals([-1, 0, 1, 2], object_.method_array_return())
 
+    def test_array_fixed_out_struct(self):
+        struct1, struct2 = GIMarshallingTests.array_fixed_out_struct()
+
+        self.assertEquals(7, struct1.long_)
+        self.assertEquals(6, struct1.int8)
+        self.assertEquals(6, struct2.long_)
+        self.assertEquals(7, struct2.int8)
+
     def test_array_zero_terminated_return(self):
         self.assertEquals(['0', '1', '2'], GIMarshallingTests.array_zero_terminated_return())
 



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