]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Use append_array_size for null literals
authorJürg Billeter <j@bitron.ch>
Sat, 9 Oct 2010 15:45:10 +0000 (17:45 +0200)
committerJürg Billeter <j@bitron.ch>
Sat, 9 Oct 2010 16:12:17 +0000 (18:12 +0200)
codegen/valaccodearraymodule.vala
codegen/valaccodebasemodule.vala

index 96b9696b42c8cb56dc5eaff9040dd037163e7848..40c4e9b9db57ecce6e56e391a20ab9955a17d7dc 100644 (file)
@@ -175,23 +175,14 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                        array_expr = reftransfer_expr.inner;
                }
                
-               if (array_expr is ArrayCreationExpression || array_expr is MethodCall || array_expr is CastExpression || array_expr is SliceExpression) {
-                       List<CCodeExpression> size = get_array_sizes (array_expr);
-                       if (size != null && size.size >= dim) {
+               List<CCodeExpression> size = get_array_sizes (array_expr);
+               if (size != null && size.size >= dim) {
+                       if (is_out) {
+                               // passing array as out/ref
+                               return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, size[dim - 1]);
+                       } else {
                                return size[dim - 1];
                        }
-               } else if (array_expr.symbol_reference != null) {
-                       List<CCodeExpression> size = get_array_sizes (array_expr);
-                       if (size != null && size.size >= dim) {
-                               if (is_out) {
-                                       // passing array as out/ref
-                                       return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, size[dim - 1]);
-                               } else {
-                                       return size[dim - 1];
-                               }
-                       }
-               } else if (array_expr is NullLiteral) {
-                       return new CCodeConstant ("0");
                }
 
                if (!is_out) {
index 0c735e364c80bc49246b81e55c61a3991f47f1f7..9e41f31367f959bc505190155e4ac857046903f7 100644 (file)
@@ -3545,6 +3545,13 @@ public class Vala.CCodeBaseModule : CodeGenerator {
                        cfile.add_include ("stddef.h");
                }
                set_cvalue (expr, new CCodeConstant ("NULL"));
+
+               var array_type = expr.target_type as ArrayType;
+               if (array_type != null) {
+                       for (int dim = 1; dim <= array_type.rank; dim++) {
+                               append_array_size (expr, new CCodeConstant ("0"));
+                       }
+               }
        }
 
        public virtual string get_delegate_target_cname (string delegate_cname) {