]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
dova: Fix struct variable initialization
authorJürg Billeter <j@bitron.ch>
Sun, 27 Jun 2010 06:03:07 +0000 (08:03 +0200)
committerJürg Billeter <j@bitron.ch>
Sun, 27 Jun 2010 09:44:56 +0000 (11:44 +0200)
ccode/valaccodevariabledeclarator.vala
codegen/valadovabasemodule.vala
codegen/valadovaobjectmodule.vala

index 8203d574c39f4a041a6426c5d1f8ef7c6504ab23..863ec83a310204d125324d71bcae0dbac51b6f59 100644 (file)
@@ -53,7 +53,7 @@ public class Vala.CCodeVariableDeclarator : CCodeDeclarator {
                this.declarator_suffix = declarator_suffix;
        }
 
-       public CCodeVariableDeclarator.zero (string name, CCodeExpression initializer, string? declarator_suffix = null) {
+       public CCodeVariableDeclarator.zero (string name, CCodeExpression? initializer, string? declarator_suffix = null) {
                this.name = name;
                this.initializer = initializer;
                this.declarator_suffix = declarator_suffix;
index 59b5fbaea4ffda989834d1cb772cb677bf8c2a9e..2d4542820dee2c68fe7216c15ac51e5cac6a5565 100644 (file)
@@ -1294,7 +1294,7 @@ internal class Vala.DovaBaseModule : CCodeModule {
                                vardecl.initializer = memset_call;
                                vardecl.init0 = true;
                        } else if (!local.variable_type.nullable &&
-                                  (st != null && !st.is_simple_type ()) ||
+                                  (st != null && st.get_fields ().size > 0) ||
                                   (array_type != null && array_type.fixed_length)) {
                                // 0-initialize struct with struct initializer { 0 }
                                // necessary as they will be passed by reference
@@ -2359,7 +2359,7 @@ internal class Vala.DovaBaseModule : CCodeModule {
 
                        return memset_call;
                } else if (initializer_expression && !type.nullable &&
-                   ((st != null && !st.is_simple_type ()) ||
+                   ((st != null && st.get_fields ().size > 0) ||
                     (array_type != null && array_type.fixed_length))) {
                        // 0-initialize struct with struct initializer { 0 }
                        // only allowed as initializer expression in C
index 8c8edfe5b9d46e719dc8745dc64d270f362b593b..263f9a2b5b65d732c588770a6b587bc77f92b87f 100644 (file)
@@ -979,7 +979,7 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
 
                        if (acc.readable) {
                                var cdecl = new CCodeDeclaration (acc.value_type.get_cname ());
-                               cdecl.add_declarator (new CCodeVariableDeclarator ("result", default_value_for_type (acc.value_type, true)));
+                               cdecl.add_declarator (new CCodeVariableDeclarator.zero ("result", default_value_for_type (acc.value_type, true)));
                                function.block.prepend_statement (cdecl);
 
                                function.block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("result")));
@@ -1207,7 +1207,7 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
 
                                if (!(m.return_type is VoidType) && !(m.return_type is GenericType)) {
                                        var cdecl = new CCodeDeclaration (m.return_type.get_cname ());
-                                       cdecl.add_declarator (new CCodeVariableDeclarator ("result", default_value_for_type (m.return_type, true)));
+                                       cdecl.add_declarator (new CCodeVariableDeclarator.zero ("result", default_value_for_type (m.return_type, true)));
                                        cinit.append (cdecl);
 
                                        function.block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("result")));