diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2020-10-22 21:22:15 +0200 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-01-03 12:52:23 +0100 |
commit | 0a0b7a4672a290289ad575a2020e7ec80ddfb808 (patch) | |
tree | 28262d61e9bd50a4d8e5cc1f6acc33368666f12a | |
parent | 465cef64805afcc87d98df349a4bb6167bc9914f (diff) | |
download | vala-0a0b7a4672a290289ad575a2020e7ec80ddfb808.tar.gz |
codegen: Update outdated array _size_ variable of captured local-variable
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1090
-rw-r--r-- | codegen/valaccodemethodcallmodule.vala | 6 | ||||
-rw-r--r-- | tests/Makefile.am | 3 | ||||
-rw-r--r-- | tests/arrays/resize-local-size-captured.vala | 14 | ||||
-rw-r--r-- | tests/arrays/resize-local-size.vala | 9 | ||||
-rw-r--r-- | tests/methods/parameter-ref-array-resize-captured.vala | 18 |
5 files changed, 46 insertions, 4 deletions
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala index 40829730c..b3edf9308 100644 --- a/codegen/valaccodemethodcallmodule.vala +++ b/codegen/valaccodemethodcallmodule.vala @@ -815,9 +815,8 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { ccode.add_assignment (get_array_length_cexpression (ma.inner, 1), temp_ref); var array_var = ma.inner.symbol_reference; - var array_local = array_var as LocalVariable; if (array_var != null && array_var.is_internal_symbol () - && ((array_var is LocalVariable && !array_local.captured) || array_var is Field)) { + && (array_var is LocalVariable || array_var is Field)) { ccode.add_assignment (get_array_size_cvalue (ma.inner.target_value), temp_ref); } @@ -881,9 +880,8 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { if (param != null && get_ccode_array_length (param) && param.variable_type is ArrayType && !((ArrayType) param.variable_type).fixed_length && ((ArrayType) param.variable_type).rank == 1) { unowned Symbol? array_var = unary.inner.symbol_reference; - unowned LocalVariable? array_local = array_var as LocalVariable; if (array_var != null && array_var.is_internal_symbol () - && ((array_local != null && !array_local.captured) || array_var is Field)) { + && (array_var is LocalVariable || array_var is Field)) { ccode.add_assignment (get_array_size_cvalue (unary.inner.target_value), get_array_length_cvalue (unary.inner.target_value, 1)); } } diff --git a/tests/Makefile.am b/tests/Makefile.am index a2f375716..18560b63b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -94,6 +94,8 @@ TESTS = \ arrays/struct-field-initializer.vala \ arrays/struct-namespaced-initializer.vala \ arrays/resize.vala \ + arrays/resize-local-size.vala \ + arrays/resize-local-size-captured.vala \ arrays/resize-unowned-invalid.test \ arrays/resize-unowned-invalid-2.test \ arrays/resize-unowned-invalid-3.test \ @@ -127,6 +129,7 @@ TESTS = \ methods/iterator.vala \ methods/parameter-fixed-array-initializer.vala \ methods/parameter-ref-array-resize.vala \ + methods/parameter-ref-array-resize-captured.vala \ methods/prepostconditions.vala \ methods/prepostconditions-captured.vala \ methods/postconditions.vala \ diff --git a/tests/arrays/resize-local-size-captured.vala b/tests/arrays/resize-local-size-captured.vala new file mode 100644 index 000000000..6e23d71a0 --- /dev/null +++ b/tests/arrays/resize-local-size-captured.vala @@ -0,0 +1,14 @@ +delegate void FooFunc (); + +void main () { + int[] a = new int[10 * 1024 * 1024]; + + FooFunc func = () => { + a.resize (1); + }; + func (); + + for (int i = 1; i < 10 * 1024 * 1024; i++) { + a += 4711; + } +} diff --git a/tests/arrays/resize-local-size.vala b/tests/arrays/resize-local-size.vala new file mode 100644 index 000000000..05522012b --- /dev/null +++ b/tests/arrays/resize-local-size.vala @@ -0,0 +1,9 @@ +void main() { + int[] a = new int[10 * 1024 * 1024]; + + a.resize (1); + + for (int i = 1; i < 10 * 1024 * 1024; i++) { + a += 4711; + } +} diff --git a/tests/methods/parameter-ref-array-resize-captured.vala b/tests/methods/parameter-ref-array-resize-captured.vala new file mode 100644 index 000000000..19fd6390b --- /dev/null +++ b/tests/methods/parameter-ref-array-resize-captured.vala @@ -0,0 +1,18 @@ +delegate void FooFunc (); + +void foo (ref int[] a) { + a = new int[1]; +} + +void main() { + int[] a = new int[10 * 1024 * 1024]; + + FooFunc func = () => { + foo (ref a); + }; + func (); + + for (int i = 1; i < 10 * 1024 * 1024; i++) { + a += 4711; + } +} |