[vala/0.50] codegen: Update outdated array _size_ variable of captured local-variable
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.50] codegen: Update outdated array _size_ variable of captured local-variable
- Date: Fri, 23 Oct 2020 14:19:33 +0000 (UTC)
commit 239f002c492ac9aaa1e09e618d058b97e8ae7857
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Thu Oct 22 21:22:15 2020 +0200
codegen: Update outdated array _size_ variable of captured local-variable
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1090
codegen/valaccodemethodcallmodule.vala | 6 ++----
tests/Makefile.am | 3 +++
tests/arrays/resize-local-size-captured.vala | 14 ++++++++++++++
tests/arrays/resize-local-size.vala | 9 +++++++++
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 2c5be10c3..09c1ccb17 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -826,9 +826,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);
}
@@ -905,9 +904,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 3be19f407..168a3fe6e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -103,6 +103,8 @@ TESTS = \
arrays/struct-namespaced-initializer.vala \
arrays/incompatible-integer-elements.test \
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 \
@@ -138,6 +140,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;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]