Commit 640fded4 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

initialize new array elements after resizing an array, patch by Mathias

2007-04-03  Jürg Billeter  <j@bitron.ch>

	* vala/valacodegenerator.vala: initialize new array elements after
	  resizing an array, patch by Mathias Hasselmann
	* vala/valaproperty.vala: fix for interface properties

svn path=/trunk/; revision=275
parent e07c1164
2007-04-03 Jürg Billeter <j@bitron.ch>
* vala/valacodegenerator.vala: initialize new array elements after
resizing an array, patch by Mathias Hasselmann
* vala/valaproperty.vala: fix for interface properties
2007-04-03 Jürg Billeter <j@bitron.ch>
* doc/valac.1, doc/Makefile.am: add manual page for valac written by
......
......@@ -3281,11 +3281,34 @@ public class Vala.CodeGenerator : CodeVisitor {
}
if (m is ArrayResizeMethod) {
var ccomma = new CCodeCommaExpression ();
ccomma.append_expression ((CCodeExpression) expr.ccodenode);
// FIXME: size expression must not be evaluated twice at runtime (potential side effects)
var new_size = (CCodeExpression) ((CodeNode) expr.get_argument_list ().data).ccodenode;
ccomma.append_expression (new CCodeAssignment (get_array_length_cexpression (ma.inner, 1), new_size));
var temp_decl = get_temp_variable_declarator (int_type);
var temp_ref = new CCodeIdentifier (temp_decl.name);
temp_vars.prepend (temp_decl);
/* memset needs string.h */
string_h_needed = true;
var clen = get_array_length_cexpression (ma.inner, 1);
var celems = (CCodeExpression)ma.inner.ccodenode;
var csizeof = new CCodeIdentifier ("sizeof (%s)".printf (ma.inner.static_type.data_type.get_cname ()));
var cdelta = new CCodeParenthesizedExpression (new CCodeBinaryExpression (CCodeBinaryOperator.MINUS, temp_ref, clen));
var ccheck = new CCodeBinaryExpression (CCodeBinaryOperator.GREATER_THAN, temp_ref, clen);
var czero = new CCodeFunctionCall (new CCodeIdentifier ("memset"));
czero.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, celems, clen));
czero.add_argument (new CCodeConstant ("0"));
czero.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.MUL, csizeof, cdelta));
var ccomma = new CCodeCommaExpression ();
ccomma.append_expression (new CCodeAssignment (temp_ref, new_size));
ccomma.append_expression ((CCodeExpression) expr.ccodenode);
ccomma.append_expression (new CCodeConditionalExpression (ccheck, czero, new CCodeConstant ("NULL")));
ccomma.append_expression (new CCodeAssignment (get_array_length_cexpression (ma.inner, 1), temp_ref));
expr.ccodenode = ccomma;
}
}
......
/* valaproperty.vala
*
* Copyright (C) 2006 Jürg Billeter
* Copyright (C) 2006-2007 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -146,7 +146,7 @@ public class Vala.Property : Member, Lockable {
* @return the upper case name to be used in C code
*/
public ref string! get_upper_case_cname () {
return "%s_%s".printf (((Class) symbol.parent_symbol.node).get_lower_case_cname (null), Namespace.camel_case_to_lower_case (name)).up ();
return "%s_%s".printf (((DataType) symbol.parent_symbol.node).get_lower_case_cname (null), Namespace.camel_case_to_lower_case (name)).up ();
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment