[pygi] Initialize struct fields to 0 when allocating



commit b11cf2595987c1f0fc4ffd834f07c98b92aa2355
Author: Simon van der Linden <svdlinden src gnome org>
Date:   Fri Jan 8 21:10:28 2010 +0100

    Initialize struct fields to 0 when allocating

 gi/pygi-struct.c |    2 +-
 tests/test_gi.py |    5 +++++
 2 files changed, 6 insertions(+), 1 deletions(-)
---
diff --git a/gi/pygi-struct.c b/gi/pygi-struct.c
index 8b672c7..b1e81bf 100644
--- a/gi/pygi-struct.c
+++ b/gi/pygi-struct.c
@@ -72,7 +72,7 @@ _struct_new (PyTypeObject *type,
     }
 
     size = g_struct_info_get_size((GIStructInfo *)info);
-    pointer = g_try_malloc(size);
+    pointer = g_try_malloc0(size);
     if (pointer == NULL) {
         PyErr_NoMemory();
         goto out;
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 8de9114..2cbb2eb 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -1120,6 +1120,9 @@ class TestStructure(unittest.TestCase):
         struct = TestGI.SimpleStruct()
         self.assertTrue(isinstance(struct, TestGI.SimpleStruct))
 
+        self.assertEquals(0, struct.long_)
+        self.assertEquals(0, struct.int8)
+
         struct.long_ = 6
         struct.int8 = 7
 
@@ -1252,6 +1255,8 @@ class TestStructure(unittest.TestCase):
         struct = TestGI.BoxedStruct()
         self.assertTrue(isinstance(struct, TestGI.BoxedStruct))
 
+        self.assertEquals(0, struct.long_)
+
         del struct
 
     def test_boxed_struct_new(self):



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