[vala] codegen: Fix assignment to fixed-length array variable
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Fix assignment to fixed-length array variable
- Date: Thu, 10 Mar 2011 19:29:44 +0000 (UTC)
commit 5be17d4f1c03c55a5634b5f3e5afababa5f09992
Author: Jürg Billeter <j bitron ch>
Date: Thu Mar 10 20:27:02 2011 +0100
codegen: Fix assignment to fixed-length array variable
Fixes bug 644413.
codegen/valaccodeassignmentmodule.vala | 37 ++++++++++++++++++-------------
1 files changed, 21 insertions(+), 16 deletions(-)
---
diff --git a/codegen/valaccodeassignmentmodule.vala b/codegen/valaccodeassignmentmodule.vala
index b22cbaf..3f6dd65 100644
--- a/codegen/valaccodeassignmentmodule.vala
+++ b/codegen/valaccodeassignmentmodule.vala
@@ -170,25 +170,30 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
}
void store_variable (Variable variable, TargetValue lvalue, TargetValue value, bool initializer) {
+ var array_type = variable.variable_type as ArrayType;
+
+ if (array_type != null && array_type.fixed_length) {
+ cfile.add_include ("string.h");
+
+ // it is necessary to use memcpy for fixed-length (stack-allocated) arrays
+ // simple assignments do not work in C
+ var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
+ sizeof_call.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
+ var size = new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeConstant ("%d".printf (array_type.length)), sizeof_call);
+
+ var ccopy = new CCodeFunctionCall (new CCodeIdentifier ("memcpy"));
+ ccopy.add_argument (get_cvalue_ (lvalue));
+ ccopy.add_argument (get_cvalue_ (value));
+ ccopy.add_argument (size);
+ ccode.add_expression (ccopy);
+
+ return;
+ }
+
ccode.add_assignment (get_cvalue_ (lvalue), get_cvalue_ (value));
- var array_type = variable.variable_type as ArrayType;
if (array_type != null) {
- if (array_type.fixed_length) {
- cfile.add_include ("string.h");
-
- // it is necessary to use memcpy for fixed-length (stack-allocated) arrays
- // simple assignments do not work in C
- var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
- sizeof_call.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
- var size = new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeConstant ("%d".printf (array_type.length)), sizeof_call);
-
- var ccopy = new CCodeFunctionCall (new CCodeIdentifier ("memcpy"));
- ccopy.add_argument (get_cvalue_ (lvalue));
- ccopy.add_argument (get_cvalue_ (value));
- ccopy.add_argument (size);
- ccode.add_expression (ccopy);
- } else if (!variable.no_array_length && !variable.array_null_terminated) {
+ if (!variable.no_array_length && !variable.array_null_terminated) {
for (int dim = 1; dim <= array_type.rank; dim++) {
ccode.add_assignment (get_array_length_cvalue (lvalue, dim), get_array_length_cvalue (value, dim));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]