[pygobject] Fix len_arg_index for array arguments



commit 9c48a561c5ee010410df7d6e430353b41d5fbd88
Author: Bastian Winkler <buz netbuz org>
Date:   Thu Apr 12 20:30:05 2012 +0200

    Fix len_arg_index for array arguments
    
    Don't set len_arg_index for arrays without the length annotation given.
    This fixes methods like Clutter.Texture.set_from_rgb_data() and
    Clutter.Image.set_data()
    
    https://bugzilla.gnome.org/show_bug.cgi?id=674271
    
    Signed-off-by: Martin Pitt <martinpitt gnome org>

 gi/pygi-cache.c           |    4 +++-
 gi/pygi-marshal-cleanup.c |    4 ++--
 tests/test_gi.py          |    3 +++
 3 files changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c
index 5a653c2..610e35b 100644
--- a/gi/pygi-cache.c
+++ b/gi/pygi-cache.c
@@ -161,7 +161,9 @@ _sequence_cache_new (GITypeInfo *type_info,
     if (!sc->is_zero_terminated) {
         sc->fixed_size = g_type_info_get_array_fixed_size (type_info);
         if (sc->fixed_size < 0)
-            sc->len_arg_index = g_type_info_get_array_length (type_info) + child_offset;
+            sc->len_arg_index = g_type_info_get_array_length (type_info);
+            if (sc->len_arg_index >= 0)
+                sc->len_arg_index += child_offset;
     }
 
     item_type_info = g_type_info_get_param_type (type_info, 0);
diff --git a/gi/pygi-marshal-cleanup.c b/gi/pygi-marshal-cleanup.c
index d580161..0f27ba7 100644
--- a/gi/pygi-marshal-cleanup.c
+++ b/gi/pygi-marshal-cleanup.c
@@ -279,13 +279,13 @@ _wrap_c_array (PyGIInvokeState   *state,
                gpointer           data)
 {
     GArray *array_;
-    gsize   len;
+    gsize   len = 0;
   
     if (sequence_cache->fixed_size >= 0) {
         len = sequence_cache->fixed_size;
     } else if (sequence_cache->is_zero_terminated) {
         len = g_strv_length ((gchar **)data);
-    } else {
+    } else if (sequence_cache->len_arg_index >= 0) {
         GIArgument *len_arg = state->args[sequence_cache->len_arg_index];
         len = len_arg->v_long;
     }
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 2c591b9..985eb5d 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -744,6 +744,9 @@ class TestArray(unittest.TestCase):
         GIMarshallingTests.multi_array_key_value_in(["one", "two", "three"],
                                                     [1, 2, 3])
 
+    def test_array_in_nonzero_nonlen(self):
+        GIMarshallingTests.array_in_nonzero_nonlen(1, 'abcd')
+
     def test_array_fixed_out_struct(self):
         struct1, struct2 = GIMarshallingTests.array_fixed_out_struct()
 



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