]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
fix variable initialization for array types
authorJuerg Billeter <j@bitron.ch>
Sun, 16 Mar 2008 22:14:20 +0000 (22:14 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sun, 16 Mar 2008 22:14:20 +0000 (22:14 +0000)
2008-03-16  Juerg Billeter  <j@bitron.ch>

* gobject/valaccodegenerator.vala,
  gobject/valaccodegeneratormethod.vala: fix variable
  initialization for array types

svn path=/trunk/; revision=1132

ChangeLog
gobject/valaccodegenerator.vala
gobject/valaccodegeneratormethod.vala

index ca949723988fe83436bf9e4b975aad84746488c2..794b58c2d33bfd56e16d3cf43ee489efad64ae8f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-03-16  Jürg Billeter  <j@bitron.ch>
+
+       * gobject/valaccodegenerator.vala,
+         gobject/valaccodegeneratormethod.vala: fix variable
+         initialization for array types
+
 2008-03-16  Jürg Billeter  <j@bitron.ch>
 
        * vapigen/valagidlparser.vala: support hidden="0" for parameters
index eab12d2c04cd92b4b3b526a8dda85c630dd063a7..2bbdb7de1526ed27b351f682ac0d52a08e3fd931 100644 (file)
@@ -959,16 +959,8 @@ public class Vala.CCodeGenerator : CodeGenerator {
                        }
 
                        /* try to initialize uninitialized variables */
-                       if (decl.initializer == null && decl.type_reference.data_type is Struct) {
-                               if (decl.type_reference.data_type.get_default_value () != null) {
-                                       ((CCodeVariableDeclarator) decl.ccodenode).initializer = new CCodeConstant (decl.type_reference.data_type.get_default_value ());
-                               } else {
-                                       // 0-initialize struct with struct initializer { 0 }
-                                       var clist = new CCodeInitializerList ();
-                                       clist.append (new CCodeConstant ("0"));
-
-                                       ((CCodeVariableDeclarator) decl.ccodenode).initializer = clist;
-                               }
+                       if (decl.initializer == null) {
+                               ((CCodeVariableDeclarator) decl.ccodenode).initializer = default_value_for_type (decl.type_reference);
                        }
                }
                
index ab8b860c80c208f937c54b59f3f87fe4c5c8b9e3..24e48d080533541e338c973b2b72a992449d0ec9 100644 (file)
@@ -724,6 +724,11 @@ public class Vala.CCodeGenerator {
                        return new CCodeConstant ("NULL");
                } else if (type.data_type != null && type.data_type.get_default_value () != null) {
                        return new CCodeConstant (type.data_type.get_default_value ());
+               } else if (type.data_type is Struct) {
+                       // 0-initialize struct with struct initializer { 0 }
+                       var clist = new CCodeInitializerList ();
+                       clist.append (new CCodeConstant ("0"));
+                       return clist;
                } else if (type.type_parameter != null) {
                        return new CCodeConstant ("NULL");
                } else if (type is ErrorType) {