From: Jürg Billeter Date: Sun, 27 Jun 2010 06:03:07 +0000 (+0200) Subject: dova: Fix struct variable initialization X-Git-Tag: 0.9.3~92 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f1a871b357d539145af4584467fedbe0df54fbd0;p=thirdparty%2Fvala.git dova: Fix struct variable initialization --- diff --git a/ccode/valaccodevariabledeclarator.vala b/ccode/valaccodevariabledeclarator.vala index 8203d574c..863ec83a3 100644 --- a/ccode/valaccodevariabledeclarator.vala +++ b/ccode/valaccodevariabledeclarator.vala @@ -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; diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala index 59b5fbaea..2d4542820 100644 --- a/codegen/valadovabasemodule.vala +++ b/codegen/valadovabasemodule.vala @@ -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 diff --git a/codegen/valadovaobjectmodule.vala b/codegen/valadovaobjectmodule.vala index 8c8edfe5b..263f9a2b5 100644 --- a/codegen/valadovaobjectmodule.vala +++ b/codegen/valadovaobjectmodule.vala @@ -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")));