From f1a871b357d539145af4584467fedbe0df54fbd0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrg=20Billeter?= Date: Sun, 27 Jun 2010 08:03:07 +0200 Subject: [PATCH] dova: Fix struct variable initialization --- ccode/valaccodevariabledeclarator.vala | 2 +- codegen/valadovabasemodule.vala | 4 ++-- codegen/valadovaobjectmodule.vala | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) 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"))); -- 2.47.3