[vala/staging] codegen: Initialize temp-var for property array length before calling getter



commit f4e55ee6116703d52e6647fbea73b036e4714cbe
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Mar 18 18:11:13 2020 +0100

    codegen: Initialize temp-var for property array length before calling getter
    
    Regression of d33e9fbca63674b7dfa339c25a9d5e27cce187f3

 codegen/valaccodememberaccessmodule.vala | 15 ++++++++++++---
 tests/Makefile.am                        |  1 +
 tests/objects/property-array-length.vala | 21 +++++++++++++++++++++
 3 files changed, 34 insertions(+), 3 deletions(-)
---
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 0a14420af..ed838cb20 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -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)));
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 464e61647..7f7b6f6d3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
index 000000000..b3d52eeef
--- /dev/null
+++ b/tests/objects/property-array-length.vala
@@ -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 ();
+}


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