[pygobject] gi: Support zero-terminated arrays with length arguments



commit 274d60a7c08d74a299f4b83d8054c00eadb4bdbd
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Wed May 30 16:45:53 2012 -0400

    gi: Support zero-terminated arrays with length arguments
    
    Sometimes, you may see (array zero-terminated=1 length=length) annotations.
    Don't expose the length argument to the user in this case.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=677124

 gi/pygi-cache.c  |   13 ++++---------
 tests/test_gi.py |    3 +++
 2 files changed, 7 insertions(+), 9 deletions(-)
---
diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c
index 610e35b..5083417 100644
--- a/gi/pygi-cache.c
+++ b/gi/pygi-cache.c
@@ -155,16 +155,11 @@ _sequence_cache_new (GITypeInfo *type_info,
     sc = g_slice_new0 (PyGISequenceCache);
     ( (PyGIArgCache *)sc)->destroy_notify = (GDestroyNotify)_sequence_cache_free_func;
 
-    sc->fixed_size = -1;
-    sc->len_arg_index = -1;
     sc->is_zero_terminated = g_type_info_is_zero_terminated (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);
-            if (sc->len_arg_index >= 0)
-                sc->len_arg_index += child_offset;
-    }
+    sc->fixed_size = g_type_info_get_array_fixed_size (type_info);
+    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/tests/test_gi.py b/tests/test_gi.py
index 572d438..e948c9d 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -689,6 +689,9 @@ class TestArray(unittest.TestCase):
     def test_array_in(self):
         GIMarshallingTests.array_in(Sequence([-1, 0, 1, 2]))
 
+    def test_array_in_len_zero_terminated(self):
+        GIMarshallingTests.array_in_len_zero_terminated(Sequence([-1, 0, 1, 2]))
+
     def test_array_uint8_in(self):
         GIMarshallingTests.array_uint8_in(Sequence([97, 98, 99, 100]))
         GIMarshallingTests.array_uint8_in(_bytes("abcd"))



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