summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2016-10-11 11:05:23 +0200
committerRico Tzschichholz <ricotz@ubuntu.com>2016-12-02 12:58:34 +0100
commitf8a82080dfbc97f23709aa7d76c0e851fe9746b8 (patch)
treee35df93517ef167f8f3077478b51abe54d65abd9
parent7ca4803c2d1d0e036be9686f55df01b0e2ca4ec6 (diff)
downloadvala-wip/fixed-arrays.tar.gz
codegen: Generate correct ccode for fixed-length array parameterswip/fixed-arrays
https://bugzilla.gnome.org/show_bug.cgi?id=641308
-rw-r--r--codegen/valaccodearraymodule.vala14
-rw-r--r--codegen/valaccodemethodcallmodule.vala4
-rw-r--r--codegen/valaccodemethodmodule.vala2
-rw-r--r--tests/basic-types/arrays.vala18
4 files changed, 32 insertions, 6 deletions
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 2b78bbc7d..ea227f285 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -704,14 +704,22 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
}
string ctypename = get_ccode_name (param.variable_type);
+ string name = get_variable_cname (param.name);
+ var array_type = (ArrayType) param.variable_type;
if (param.direction != ParameterDirection.IN) {
ctypename += "*";
}
- var main_cparam = new CCodeParameter (get_variable_cname (param.name), ctypename);
+ if (array_type.inline_allocated) {
+ if (param.direction != ParameterDirection.IN) {
+ ctypename += "*";
+ } else {
+ name += "[]";
+ }
+ }
- var array_type = (ArrayType) param.variable_type;
+ var main_cparam = new CCodeParameter (name, ctypename);
generate_type_declaration (array_type.element_type, decl_space);
@@ -720,7 +728,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
carg_map.set (get_param_pos (get_ccode_pos (param)), get_variable_cexpression (param.name));
}
- if (get_ccode_array_length (param)) {
+ if (!array_type.fixed_length && get_ccode_array_length (param)) {
string length_ctype = "int";
if (get_ccode_array_length_type (param) != null) {
length_ctype = get_ccode_array_length_type (param);
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 31e1839e6..f5b7f2d49 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -346,7 +346,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
var unary = arg as UnaryExpression;
if (unary == null || unary.operator != UnaryOperator.OUT) {
- if (get_ccode_array_length (param) && param.variable_type is ArrayType) {
+ if (get_ccode_array_length (param) && param.variable_type is ArrayType && !((ArrayType) param.variable_type).fixed_length) {
var array_type = (ArrayType) param.variable_type;
for (int dim = 1; dim <= array_type.rank; dim++) {
CCodeExpression? array_length_expr = null;
@@ -409,7 +409,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
cexpr = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_cvalue (arg));
- if (get_ccode_array_length (param) && param.variable_type is ArrayType) {
+ if (get_ccode_array_length (param) && param.variable_type is ArrayType && !((ArrayType) param.variable_type).fixed_length) {
var array_type = (ArrayType) param.variable_type;
var array_length_type = int_type;
if (get_ccode_array_length_type (param) != null) {
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 3a89c7e41..0086db509 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -592,7 +592,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
}
} else if (!m.coroutine) {
// declare local variable for out parameter to allow assignment even when caller passes NULL
- var vardecl = new CCodeVariableDeclarator.zero (get_variable_cname ("_vala_%s".printf (param.name)), default_value_for_type (param.variable_type, true));
+ var vardecl = new CCodeVariableDeclarator.zero (get_variable_cname ("_vala_%s".printf (param.name)), default_value_for_type (param.variable_type, true), get_ccode_declarator_suffix (param.variable_type));
ccode.add_declaration (get_ccode_name (param.variable_type), vardecl);
if (param.variable_type is ArrayType) {
diff --git a/tests/basic-types/arrays.vala b/tests/basic-types/arrays.vala
index 7685304a6..9b8e70b1b 100644
--- a/tests/basic-types/arrays.vala
+++ b/tests/basic-types/arrays.vala
@@ -198,6 +198,23 @@ void test_explicit_copying () {
assert (a0[1] == a1[1]);
}
+void give_fixed_array (out int i[3]) {
+ i = { 3, 4, 5 };
+}
+
+void take_fixed_array (int i[3]) {
+ assert (i.length == 3);
+ assert (i[1] == 2);
+}
+
+void test_fixed_array () {
+ int i[3] = { 1, 2, 3 };
+ take_fixed_array (i);
+ int j[3];
+ give_fixed_array (out j);
+ assert (j[1] == 4);
+}
+
void main () {
test_integer_array ();
test_string_array ();
@@ -210,4 +227,5 @@ void main () {
test_generics_array ();
test_void_array ();
test_explicit_copying ();
+ test_fixed_array ();
}