[vala/0.40] codegen: Correct field declaration for captured inline-allocated array
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.40] codegen: Correct field declaration for captured inline-allocated array
- Date: Tue, 21 Apr 2020 07:48:43 +0000 (UTC)
commit 84fbdbd76df12ee9567bf1b0ada9ff3acf63304f
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Tue Mar 31 14:55:59 2020 +0200
codegen: Correct field declaration for captured inline-allocated array
Also pass proper size to memset for local temp variables of
inline-allocated arrays in asynchronous context.
Fixes https://gitlab.gnome.org/GNOME/vala/issues/954
codegen/valaccodebasemodule.vala | 17 +++++++++++------
codegen/valagasyncmodule.vala | 4 ++--
tests/Makefile.am | 1 +
tests/asynchronous/captured-fixed-array.vala | 14 ++++++++++++++
4 files changed, 28 insertions(+), 8 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index b77f7e63e..5f0b2ddd9 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1954,7 +1954,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (!param.variable_type.value_owned) {
param_type.value_owned = !no_implicit_copy (param.variable_type);
}
- data.add_field (get_ccode_name (param_type), get_variable_cname (param.name));
+ data.add_field (get_ccode_name (param_type), get_variable_cname (param.name), 0,
get_ccode_declarator_suffix (param_type));
// create copy if necessary as captured variables may need to be kept alive
param.captured = false;
@@ -1963,7 +1963,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
var array_type = param.variable_type as ArrayType;
var deleg_type = param.variable_type as DelegateType;
- if (array_type != null && get_ccode_array_length (param)) {
+ if (array_type != null && get_ccode_array_length (param) && !((ArrayType)
array_type).fixed_length) {
for (int dim = 1; dim <= array_type.rank; dim++) {
data.add_field ("gint", get_parameter_array_length_cname (param, dim));
}
@@ -3663,7 +3663,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
public void emit_temp_var (LocalVariable local, bool on_error = false) {
var init = (!local.name.has_prefix ("*") && local.init);
if (is_in_coroutine ()) {
- closure_struct.add_field (get_ccode_name (local.variable_type), local.name);
+ closure_struct.add_field (get_ccode_name (local.variable_type), local.name, 0,
get_ccode_declarator_suffix (local.variable_type));
// even though closure struct is zerod, we need to initialize temporary variables
// as they might be used multiple times when declared in a loop
@@ -3675,7 +3675,12 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
var memset_call = new CCodeFunctionCall (new CCodeIdentifier
("memset"));
memset_call.add_argument (new CCodeUnaryExpression
(CCodeUnaryOperator.ADDRESS_OF, get_variable_cexpression (local.name)));
memset_call.add_argument (new CCodeConstant ("0"));
- memset_call.add_argument (new CCodeIdentifier ("sizeof (%s)".printf
(get_ccode_name (local.variable_type))));
+ CCodeExpression? size = null;
+ requires_memset_init (local, out size);
+ if (size == null) {
+ size = new CCodeIdentifier ("sizeof (%s)".printf
(get_ccode_name (local.variable_type)));
+ }
+ memset_call.add_argument (size);
ccode.add_expression (memset_call);
} else {
ccode.add_assignment (get_variable_cexpression (local.name),
initializer);
@@ -6333,11 +6338,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
public bool requires_memset_init (Variable variable, out CCodeExpression? size) {
unowned ArrayType? array_type = variable.variable_type as ArrayType;
- if (array_type != null && array_type.fixed_length && !is_constant_ccode (array_type.length)) {
+ if (array_type != null && array_type.fixed_length) {
var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
sizeof_call.add_argument (new CCodeIdentifier (get_ccode_name
(array_type.element_type)));
size = new CCodeBinaryExpression (CCodeBinaryOperator.MUL, get_ccodenode
(array_type.length), sizeof_call);
- return true;
+ return !is_constant_ccode (array_type.length);
}
size = null;
return false;
diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index 1d66e665f..36fff60af 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -53,11 +53,11 @@ public class Vala.GAsyncModule : GtkModule {
foreach (Parameter param in m.get_parameters ()) {
var param_type = param.variable_type.copy ();
param_type.value_owned = true;
- data.add_field (get_ccode_name (param_type), get_variable_cname (param.name));
+ data.add_field (get_ccode_name (param_type), get_variable_cname (param.name), 0,
get_ccode_declarator_suffix (param_type));
if (param.variable_type is ArrayType) {
var array_type = (ArrayType) param.variable_type;
- if (get_ccode_array_length (param)) {
+ if (get_ccode_array_length (param) && !((ArrayType) array_type).fixed_length)
{
for (int dim = 1; dim <= array_type.rank; dim++) {
data.add_field ("gint", get_parameter_array_length_cname
(param, dim));
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 80a276df7..b4fe335f0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -463,6 +463,7 @@ TESTS = \
asynchronous/bug792660.vala \
asynchronous/bug792942.vala \
asynchronous/bug793158.vala \
+ asynchronous/captured-fixed-array.vala \
asynchronous/catch-in-finally.vala \
asynchronous/creation-missing-yield.test \
asynchronous/closures.vala \
diff --git a/tests/asynchronous/captured-fixed-array.vala b/tests/asynchronous/captured-fixed-array.vala
new file mode 100644
index 000000000..30a9c38be
--- /dev/null
+++ b/tests/asynchronous/captured-fixed-array.vala
@@ -0,0 +1,14 @@
+async void foo (int array_param[3]) {
+ int array[] = { 23, 42 };
+
+ assert (array.length == 2);
+ assert (array[1] == 42);
+
+ assert (array_param.length == 3);
+ assert (array_param[2] == 4711);
+}
+
+void main() {
+ int array[3] = { 42, 23, 4711 };
+ foo.begin (array);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]