[vala] codegen: Retain array length for cast from/to generic array
- From: JÃrg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Retain array length for cast from/to generic array
- Date: Sat, 10 Nov 2012 16:47:53 +0000 (UTC)
commit 44bf74194e4a694a2c026ecadd78b3c7dfecfa93
Author: JÃrg Billeter <j bitron ch>
Date: Sat Nov 10 17:46:25 2012 +0100
codegen: Retain array length for cast from/to generic array
Fixes bug 687728.
codegen/valaccodebasemodule.vala | 19 +++++++++++++------
1 files changed, 13 insertions(+), 6 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 62d1d8a..03f801a 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5025,14 +5025,21 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
// 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)));
+ if (array_type.element_type is GenericType || ((ArrayType) expr.inner.value_type).element_type is GenericType) {
+ // element size unknown for generic arrays, retain array length as is
+ for (int dim = 1; dim <= array_type.rank; dim++) {
+ append_array_length (expr, get_array_length_cexpression (expr.inner, dim));
+ }
+ } else {
+ 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)));
+ 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, new CCodeBinaryExpression (CCodeBinaryOperator.DIV, new CCodeBinaryExpression (CCodeBinaryOperator.MUL, get_array_length_cexpression (expr.inner, dim), sizeof_from), sizeof_to));
+ for (int dim = 1; dim <= array_type.rank; 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]