From: Luca Bruno Date: Tue, 22 Nov 2011 14:44:07 +0000 (+0100) Subject: codegen: Destroy the elements of GQueue X-Git-Tag: 0.14.1~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e1deabc03564e17f8f2e4e2d21e6903b679057c;p=thirdparty%2Fvala.git codegen: Destroy the elements of GQueue When destroying a GQueue also destroy its elements like we do with GList, GSList and GNode. Fixes bug 664529. --- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index d18b269fc..dd934f65e 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -300,6 +300,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { public Class glist_type; public Class gslist_type; public Class gnode_type; + public Class gqueue_type; public Class gvaluearray_type; public TypeSymbol gstringbuilder_type; public TypeSymbol garray_type; @@ -440,6 +441,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { glist_type = (Class) glib_ns.scope.lookup ("List"); gslist_type = (Class) glib_ns.scope.lookup ("SList"); gnode_type = (Class) glib_ns.scope.lookup ("Node"); + gqueue_type = (Class) glib_ns.scope.lookup ("Queue"); gvaluearray_type = (Class) glib_ns.scope.lookup ("ValueArray"); gstringbuilder_type = (TypeSymbol) glib_ns.scope.lookup ("StringBuilder"); garray_type = (TypeSymbol) glib_ns.scope.lookup ("Array"); @@ -2768,7 +2770,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } public CCodeExpression? get_destroy_func_expression (DataType type, bool is_chainup = false) { - if (context.profile == Profile.GOBJECT && (type.data_type == glist_type || type.data_type == gslist_type || type.data_type == gnode_type)) { + if (context.profile == Profile.GOBJECT && (type.data_type == glist_type || type.data_type == gslist_type || type.data_type == gnode_type || type.data_type == gqueue_type)) { // create wrapper function to free list elements if necessary bool elements_require_free = false; @@ -2896,8 +2898,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } else { if (collection_type.data_type == glist_type) { element_free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_list_foreach")); - } else { + } else if (collection_type.data_type == gslist_type) { element_free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_slist_foreach")); + } else { + element_free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_queue_foreach")); } element_free_call.add_argument (new CCodeIdentifier ("self")); diff --git a/tests/Makefile.am b/tests/Makefile.am index a2075018c..d4e1af194 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -113,6 +113,7 @@ TESTS = \ objects/bug646792.vala \ objects/bug653138.vala \ objects/bug654702.vala \ + objects/bug664529.vala \ errors/errors.vala \ errors/bug567181.vala \ errors/bug579101.vala \ diff --git a/tests/objects/bug664529.vala b/tests/objects/bug664529.vala new file mode 100644 index 000000000..1daa493be --- /dev/null +++ b/tests/objects/bug664529.vala @@ -0,0 +1,7 @@ +void main() { + var foo = new Object (); + var bar = new Queue (); + bar.push_head (foo); + bar = null; + assert (foo.ref_count == 1); +}