[pygi] Wrap C arrays in structs as GArrays before converting to Python



commit 46b5133fea4cd5db57a360b3cbe9ee923e27560c
Author: Tomeu Vizoso <tomeu vizoso collabora co uk>
Date:   Tue Jun 1 14:28:57 2010 +0200

    Wrap C arrays in structs as GArrays before converting to Python
    
    https://bugzilla.gnome.org/show_bug.cgi?id=620247

 gi/pygi-info.c   |   11 +++++++++++
 tests/test_gi.py |   17 +++++++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/gi/pygi-info.c b/gi/pygi-info.c
index c6b7bab..b7819ca 100644
--- a/gi/pygi-info.c
+++ b/gi/pygi-info.c
@@ -1201,9 +1201,20 @@ _wrap_g_field_info_get_value (PyGIBaseInfo *self,
         goto out;
     }
 
+    if ( (g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_ARRAY) &&
+            (g_type_info_get_array_type (field_type_info) == GI_ARRAY_TYPE_C)) {
+        value.v_pointer = _pygi_argument_to_array (&value, NULL,
+                                                   field_type_info, FALSE);
+    }
+
 argument_to_object:
     py_value = _pygi_argument_to_object (&value, field_type_info, GI_TRANSFER_NOTHING);
 
+    if ( (g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_ARRAY) &&
+            (g_type_info_get_array_type (field_type_info) == GI_ARRAY_TYPE_C)) {
+        g_array_free (value.v_pointer, FALSE);
+    }
+
 out:
     g_base_info_unref ( (GIBaseInfo *) field_type_info);
 
diff --git a/tests/test_gi.py b/tests/test_gi.py
index eab9c8d..2541c2d 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -734,6 +734,21 @@ class TestArray(unittest.TestCase):
     def test_array_zero_terminated_inout(self):
         self.assertEquals(('-1', '0', '1', '2'), GIMarshallingTests.array_zero_terminated_inout(('0', '1', '2')))
 
+    def test_gstrv_return(self):
+        self.assertEquals(('0', '1', '2'), GIMarshallingTests.gstrv_return())
+
+    def test_gstrv_in(self):
+        GIMarshallingTests.gstrv_in(Sequence(('0', '1', '2')))
+
+    def test_gstrv_out(self):
+        self.assertEquals(('0', '1', '2'), GIMarshallingTests.gstrv_out())
+
+    def test_gstrv_out(self):
+        self.assertEquals(('0', '1', '2'), GIMarshallingTests.gstrv_out())
+
+    def test_gstrv_inout(self):
+        self.assertEquals(('-1', '0', '1', '2'), GIMarshallingTests.gstrv_inout(('0', '1', '2')))
+
 
 class TestGArray(unittest.TestCase):
 
@@ -1193,6 +1208,7 @@ class TestStructure(unittest.TestCase):
         self.assertTrue(isinstance(struct, GIMarshallingTests.BoxedStruct))
 
         self.assertEquals(0, struct.long_)
+        self.assertEquals(None, struct.g_strv)
 
         del struct
 
@@ -1216,6 +1232,7 @@ class TestStructure(unittest.TestCase):
 
         self.assertTrue(isinstance(struct, GIMarshallingTests.BoxedStruct))
         self.assertEquals(42, struct.long_)
+        self.assertEquals(('0', '1', '2'), struct.g_strv)
 
         del struct
 



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