Commit 524b8341 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter
Browse files

cleanup and fix GList and GSList destruction

2007-08-06  Juerg Billeter  <j@bitron.ch>

	* gobject/valacodegenerator.vala: cleanup and fix GList and GSList
	  destruction

svn path=/trunk/; revision=423
parent fd7682a1
2007-08-06 Jürg Billeter <j@bitron.ch>
* gobject/valacodegenerator.vala: cleanup and fix GList and GSList
destruction
2007-08-06 Jürg Billeter <j@bitron.ch> 2007-08-06 Jürg Billeter <j@bitron.ch>
* vala/parser.y: support multiple namespaces in a using directive, * vala/parser.y: support multiple namespaces in a using directive,
......
...@@ -961,25 +961,26 @@ public class Vala.CodeGenerator : CodeVisitor { ...@@ -961,25 +961,26 @@ public class Vala.CodeGenerator : CodeVisitor {
/* set freed references to NULL to prevent further use */ /* set freed references to NULL to prevent further use */
var ccomma = new CCodeCommaExpression (); var ccomma = new CCodeCommaExpression ();
if (type.data_type == glist_type) { if (type.data_type == glist_type || type.data_type == gslist_type) {
bool is_ref = false; bool takes_ownership = false;
bool is_class = false; CCodeExpression destroy_func_expression = null;
bool is_interface = false;
foreach (TypeReference type_arg in type.get_type_arguments ()) { foreach (TypeReference type_arg in type.get_type_arguments ()) {
is_ref |= type_arg.takes_ownership; takes_ownership = type_arg.takes_ownership;
is_class |= type_arg.data_type is Class; if (takes_ownership) {
is_interface |= type_arg.data_type is Interface; destroy_func_expression = get_destroy_func_expression (type_arg);
}
} }
if (is_ref) { if (takes_ownership) {
var cunrefcall = new CCodeFunctionCall (new CCodeIdentifier ("g_list_foreach")); CCodeFunctionCall cunrefcall;
cunrefcall.add_argument (cvar); if (type.data_type == glist_type) {
if (is_class || is_interface) { cunrefcall = new CCodeFunctionCall (new CCodeIdentifier ("g_list_foreach"));
cunrefcall.add_argument (new CCodeIdentifier ("(GFunc) g_object_unref"));
} else { } else {
cunrefcall.add_argument (new CCodeIdentifier ("(GFunc) g_free")); cunrefcall = new CCodeFunctionCall (new CCodeIdentifier ("g_slist_foreach"));
} }
cunrefcall.add_argument (cvar);
cunrefcall.add_argument (new CCodeCastExpression (destroy_func_expression, "GFunc"));
cunrefcall.add_argument (new CCodeConstant ("NULL")); cunrefcall.add_argument (new CCodeConstant ("NULL"));
ccomma.append_expression (cunrefcall); ccomma.append_expression (cunrefcall);
} }
......
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