[vala] Recompute length when casting between array types
- From: JÃrg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Recompute length when casting between array types
- Date: Wed, 1 Aug 2012 10:14:55 +0000 (UTC)
commit d5f417c12f02d56bc377aaacc5e7b299525586cb
Author: Simon Werbeck <simon werbeck gmail com>
Date: Wed Jul 18 22:11:20 2012 +0200
Recompute length when casting between array types
This patch makes casting, e.g., from int[] to uchar[] work as expected
by adjusting the array length field.
Fixes bug 515408.
codegen/valaccodebasemodule.vala | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index ba30e4f..a20f783 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4917,11 +4917,17 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return;
}
- // retain array length
+ // recompute array length when casting to other array type
var array_type = expr.type_reference as ArrayType;
if (array_type != null && expr.inner.value_type is ArrayType) {
+ var sizeof_to = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
+ sizeof_to.add_argument (new CCodeConstant (get_ccode_name (array_type.element_type)));
+
+ var sizeof_from = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
+ sizeof_from.add_argument (new CCodeConstant (get_ccode_name (((ArrayType) expr.inner.value_type).element_type)));
+
for (int dim = 1; dim <= array_type.rank; dim++) {
- append_array_length (expr, get_array_length_cexpression (expr.inner, dim));
+ append_array_length (expr, new CCodeBinaryExpression (CCodeBinaryOperator.DIV, new CCodeBinaryExpression (CCodeBinaryOperator.MUL, get_array_length_cexpression (expr.inner, dim), sizeof_from), sizeof_to));
}
} else if (array_type != null) {
// cast from non-array to array, set invalid length
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]