[vala] dova: Fix struct variable initialization



commit f1a871b357d539145af4584467fedbe0df54fbd0
Author: Jürg Billeter <j bitron ch>
Date:   Sun Jun 27 08:03:07 2010 +0200

    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 8203d57..863ec83 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 59b5fba..2d45428 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 8c8edfe..263f9a2 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")));



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