+2007-03-20 Jürg Billeter <j@bitron.ch>
+
+ * vala/valaparser.vala, vala/valasemanticanalyzer.vala,
+ vala/valamemorymanager.vala, vala/valacodegenerator.vala,
+ vala/valacallback.vala, vala/valainvocationexpression.vala,
+ vala/valamethod.vala, vala/valaobjectcreationexpression.vala: use weak
+ local variables where appropriate
+ * vala/parser.y, vala/valasemanticanalyzer.vala: default local variables
+ to strong reference
+ * vala/valasemanticanalyzer.vala: don't promote local variables from
+ weak to strong reference
+ * vala/valacodegenerator.vala: warn when duplicating non-reference
+ counted structs implicitly
+
2007-03-20 Jürg Billeter <j@bitron.ch>
* tests/testrunner.sh: run with /bin/bash due to bashism, patch by
$$ = vala_type_reference_new_from_expression ($1);
g_object_unref ($1);
g_object_unref (src);
+ vala_type_reference_set_takes_ownership ($$, TRUE);
if ($2) {
vala_type_reference_set_non_null ($$, TRUE);
}
}
var method_params = m.get_parameters ();
- var method_params_it = method_params;
+ weak List<weak FormalParameter> method_params_it = method_params;
bool first = true;
foreach (FormalParameter param in parameters) {
/* use first callback parameter as instance parameter if
bool ellipsis = false;
var i = 1;
+ weak List<weak FormalParameter> params_it = params;
foreach (Expression arg in expr.get_argument_list ()) {
/* explicitly use strong reference as ccall gets
* unrefed at end of inner block
*/
ref CCodeExpression cexpr = (CCodeExpression) arg.ccodenode;
- if (params != null) {
- var param = (FormalParameter) params.data;
+ if (params_it != null) {
+ var param = (FormalParameter) params_it.data;
ellipsis = param.ellipsis;
if (!ellipsis) {
if (param.type_reference.data_type != null
ccall.add_argument (cexpr);
i++;
- if (params != null) {
- params = params.next;
+ if (params_it != null) {
+ params_it = params_it.next;
}
}
- while (params != null) {
- var param = (FormalParameter) params.data;
+ while (params_it != null) {
+ var param = (FormalParameter) params_it.data;
if (param.ellipsis) {
ellipsis = true;
ccall.add_argument ((CCodeExpression) param.default_expression.ccodenode);
i++;
- params = params.next;
+ params_it = params_it.next;
}
if (m != null && m.instance && m.instance_last) {
if (expr.static_type.data_type.is_reference_counting ()) {
ref_function = expr.static_type.data_type.get_ref_function ();
} else {
+ if (expr.static_type.data_type != string_type.data_type) {
+ // duplicating non-reference counted structs may cause side-effects (and performance issues)
+ Report.warning (expr.source_reference, "duplicating %s instance, use weak variable or explicitly invoke copy method".printf (expr.static_type.data_type.name));
+ }
ref_function = expr.static_type.data_type.get_dup_function ();
}
public override void visit_end_object_creation_expression (ObjectCreationExpression! expr) {
if (expr.symbol_reference == null) {
- // no construction method
+ // no creation method
if (expr.type_reference.data_type is Class) {
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_object_new"));
expr.ccodenode = ccall;
}
} else {
- // use construction method
+ // use creation method
var m = (Method) expr.symbol_reference.node;
var params = m.get_parameters ();
-
+
var ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_cname ()));
-
+
bool ellipsis = false;
int i = 1;
+ weak List<weak FormalParameter> params_it = params;
foreach (Expression arg in expr.get_argument_list ()) {
/* explicitly use strong reference as ccall gets
* unrefed at end of inner block
*/
ref CCodeExpression cexpr = (CCodeExpression) arg.ccodenode;
- if (params != null) {
- var param = (FormalParameter) params.data;
+ if (params_it != null) {
+ var param = (FormalParameter) params_it.data;
ellipsis = param.ellipsis;
if (!param.ellipsis
&& param.type_reference.data_type != null
ccall.add_argument (cexpr);
i++;
- if (params != null) {
- params = params.next;
+ if (params_it != null) {
+ params_it = params_it.next;
}
}
- while (params != null) {
- var param = (FormalParameter) params.data;
+ while (params_it != null) {
+ var param = (FormalParameter) params_it.data;
if (param.ellipsis) {
ellipsis = true;
ccall.add_argument ((CCodeExpression) param.default_expression.ccodenode);
i++;
- params = params.next;
+ params_it = params_it.next;
}
if (ellipsis) {
call = (Expression) new_node;
}
- List l = argument_list.find (old_node);
+ weak List<Expression> l = argument_list.find (old_node);
if (l != null) {
if (new_node.parent_node != null) {
return;
var sig = (Signal) msym.node;
params = sig.get_parameters ();
}
+ weak List<weak FormalParameter> params_it = params;
foreach (Expression arg in expr.get_argument_list ()) {
- if (params != null) {
- var param = (FormalParameter) params.data;
+ if (params_it != null) {
+ var param = (FormalParameter) params_it.data;
if (!param.ellipsis
&& ((param.type_reference.data_type != null
&& param.type_reference.data_type.is_reference_type ())
visit_possibly_leaked_expression (arg);
}
- params = params.next;
+ params_it = params_it.next;
} else {
visit_possibly_leaked_expression (arg);
}
}
var method_params = m2.get_parameters ();
- var method_params_it = method_params;
+ weak List<weak FormalParameter> method_params_it = method_params;
foreach (FormalParameter param in parameters) {
/* method may not expect less arguments */
if (method_params_it == null) {
}
public override void replace (CodeNode! old_node, CodeNode! new_node) {
- List l = argument_list.find (old_node);
+ weak List<Expression> l = argument_list.find (old_node);
if (l != null) {
if (new_node.parent_node != null) {
return;
String result = new String (comment);
comment = null;
- string index;
+ weak string index;
while ((index = result.str.chr (-1, '\t')) != null) {
result.erase (result.str.pointer_to_offset (index), 1);
}
}
private ref List<DataType> get_all_prerequisites (Interface! iface) {
- List<DataType> ret = null;
+ weak List<DataType> ret = null;
foreach (TypeReference prereq in iface.get_prerequisites ()) {
DataType type = prereq.data_type;
}
decl.type_reference = decl.initializer.static_type.copy ();
- decl.type_reference.takes_ownership = decl.type_reference.transfers_ownership;
+ decl.type_reference.takes_ownership = (decl.type_reference.data_type == null || decl.type_reference.data_type.is_reference_type ());
decl.type_reference.transfers_ownership = false;
}
}
var args = expr.get_argument_list ();
- List arg_it = args;
+ weak List<weak Expression> arg_it = args;
foreach (FormalParameter param in params) {
if (param.ellipsis) {
break;
}
private bool check_arguments (Expression! expr, Symbol! msym, List<FormalParameter> params, List<Expression> args) {
- List prev_arg_it = null;
- List arg_it = args;
+ weak List<weak Expression> prev_arg_it = null;
+ weak List<weak Expression> arg_it = args;
bool diag = (msym.node.get_attribute ("Diagnostics") != null);
l.method.symbol.parent_symbol = current_symbol;
var lambda_params = l.get_parameters ();
- var lambda_param_it = lambda_params;
+ weak List<weak FormalParameter> lambda_param_it = lambda_params;
foreach (FormalParameter cb_param in cb.get_parameters ()) {
if (lambda_param_it == null) {
/* lambda expressions are allowed to have less parameters */
if (a.right.static_type.transfers_ownership) {
/* rhs transfers ownership of the expression */
if (!a.left.static_type.takes_ownership) {
- /* lhs doesn't own the value
- * promote lhs type if it is a local variable
- * error if it's not a local variable */
- if (!(ma.symbol_reference.node is VariableDeclarator)) {
- Report.error (a.source_reference, "Invalid assignment from owned expression to unowned variable");
- }
-
- a.left.static_type.takes_ownership = true;
+ /* lhs doesn't own the value */
+ a.error = true;
+ Report.error (a.source_reference, "Invalid assignment from owned expression to unowned variable");
}
} else if (a.left.static_type.takes_ownership) {
/* lhs wants to own the value