]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Use a zero-initializer also for SimpleType structs
authorLuca Bruno <lucabru@src.gnome.org>
Sat, 27 Aug 2011 18:30:17 +0000 (20:30 +0200)
committerLuca Bruno <lucabru@src.gnome.org>
Sat, 27 Aug 2011 19:04:29 +0000 (21:04 +0200)
codegen/valaccodebasemodule.vala

index e9c9a7a44e8940cd6cc8310ebd91ffa649994a1f..3e5c125ca985249e710ce07b70dcb8865e0e84f7 100644 (file)
@@ -5425,9 +5425,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
        public CCodeExpression? default_value_for_type (DataType type, bool initializer_expression) {
                var st = type.data_type as Struct;
                var array_type = type as ArrayType;
-               if (initializer_expression && !type.nullable &&
-                   ((st != null && !st.is_simple_type ()) ||
-                    (array_type != null && array_type.fixed_length))) {
+               if (type.data_type != null && get_ccode_default_value (type.data_type) != "") {
+                       return new CCodeConstant (get_ccode_default_value (type.data_type));
+               } else if (initializer_expression && !type.nullable &&
+                                  (st != null || (array_type != null && array_type.fixed_length))) {
                        // 0-initialize struct with struct initializer { 0 }
                        // only allowed as initializer expression in C
                        var clist = new CCodeInitializerList ();
@@ -5438,8 +5439,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                           || type is PointerType || type is DelegateType
                           || (array_type != null && !array_type.fixed_length)) {
                        return new CCodeConstant ("NULL");
-               } else if (type.data_type != null && get_ccode_default_value (type.data_type) != "") {
-                       return new CCodeConstant (get_ccode_default_value (type.data_type));
                } else if (type.type_parameter != null) {
                        return new CCodeConstant ("NULL");
                } else if (type is ErrorType) {