GNOME Bugzilla – Bug 620247
sigsegv when reading a C array from a struct
Last modified: 2010-06-02 17:52:54 UTC
Created attachment 162453 [details] [review] proposed fix Because _pygi_argument_to_object expects it to be a GArray.
This fix the issue I observed too.
*** Bug 620230 has been marked as a duplicate of this bug. ***
Comment on attachment 162453 [details] [review] proposed fix >From ab25d3e86f7062c73bd6277c458683d702870964 Mon Sep 17 00:00:00 2001 >From: Tomeu Vizoso <tomeu.vizoso@collabora.co.uk> >Date: Tue, 1 Jun 2010 14:28:57 +0200 >Subject: [PATCH] Wrap C arrays in structs as GArrays before converting to Python > >--- > 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 > >-- >1.6.6.1 >