]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Initialize temp-var for property array length before calling getter
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 18 Mar 2020 17:11:13 +0000 (18:11 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 18 Mar 2020 18:56:44 +0000 (19:56 +0100)
Regression of d33e9fbca63674b7dfa339c25a9d5e27cce187f3

codegen/valaccodememberaccessmodule.vala
tests/Makefile.am
tests/objects/property-array-length.vala [new file with mode: 0644]

index 0a14420af4b45d68d3bfcfc7c6fd4fc843ed8742..ed838cb20f974ce42f882ad1434aa5d46bc779c2 100644 (file)
@@ -277,8 +277,6 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                                        ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, ctemp));
                                        ccode.add_expression (ccall);
                                } else {
-                                       ccode.add_assignment (ctemp, ccall);
-
                                        array_type = prop.property_type as ArrayType;
                                        if (array_type != null) {
                                                if (get_ccode_array_null_terminated (prop)) {
@@ -286,18 +284,29 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                                                        var len_call = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_length"));
                                                        len_call.add_argument (ctemp);
 
+                                                       ccode.add_assignment (ctemp, ccall);
                                                        ccode.add_assignment (temp_value.array_length_cvalues[0], len_call);
                                                } else if (get_ccode_array_length (prop)) {
+                                                       var temp_refs = new ArrayList<CCodeExpression> ();
                                                        for (int dim = 1; dim <= array_type.rank; dim++) {
                                                                var length_ctype = get_ccode_array_length_type (prop);
                                                                var temp_var = get_temp_variable (new CType (length_ctype, "0"), true, null, true);
                                                                var temp_ref = get_variable_cexpression (temp_var.name);
                                                                emit_temp_var (temp_var);
                                                                ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
-                                                               ccode.add_assignment (temp_value.array_length_cvalues[dim - 1], temp_ref);
+                                                               temp_refs.add (temp_ref);
+                                                       }
+
+                                                       ccode.add_assignment (ctemp, ccall);
+                                                       for (int dim = 1; dim <= array_type.rank; dim++) {
+                                                               ccode.add_assignment (temp_value.array_length_cvalues[dim - 1], temp_refs.get (dim - 1));
                                                        }
+                                               } else {
+                                                       ccode.add_assignment (ctemp, ccall);
                                                }
                                        } else {
+                                               ccode.add_assignment (ctemp, ccall);
+
                                                delegate_type = prop.property_type as DelegateType;
                                                if (delegate_type != null && get_ccode_delegate_target (prop) && delegate_type.delegate_symbol.has_target) {
                                                        ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_delegate_target_cvalue (temp_value)));
index 464e61647a48d9e5ce95f29ba4dc9f5565b1d180..7f7b6f6d331e9be9cd1481717ce396922f15ecaa 100644 (file)
@@ -380,6 +380,7 @@ TESTS = \
        objects/plugin-module-init.vala \
        objects/properties.vala \
        objects/property-array.vala \
+       objects/property-array-length.vala \
        objects/property-notify.vala \
        objects/property-ownership.vala \
        objects/property-read-only-auto.vala \
diff --git a/tests/objects/property-array-length.vala b/tests/objects/property-array-length.vala
new file mode 100644 (file)
index 0000000..b3d52ee
--- /dev/null
@@ -0,0 +1,21 @@
+[Compact]
+class Foo {
+       public uint8[] data {
+               owned get {
+                       return new uint8[42];
+               }
+       }
+}
+
+async void foo (uint8[] data) {
+       assert (data.length == 42);
+}
+
+async void bar () {
+       var f = new Foo ();
+       foo.begin (f.data);
+}
+
+void main() {
+       bar.begin ();
+}