[vala] codegen: Destroy the elements of GQueue



commit d03557e88ce4338f174942f7376517aa57034d0f
Author: Luca Bruno <lucabru src gnome org>
Date:   Tue Nov 22 15:44:07 2011 +0100

    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.

 codegen/valaccodebasemodule.vala |    8 ++++++--
 tests/Makefile.am                |    1 +
 tests/objects/bug664529.vala     |    7 +++++++
 3 files changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 0fd4c71..4c840d0 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -302,6 +302,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;
@@ -442,6 +443,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");
@@ -2835,7 +2837,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;
@@ -2963,8 +2965,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 444dcd4..92b1ef0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -118,6 +118,7 @@ TESTS = \
 	objects/bug653138.vala \
 	objects/bug654702.vala \
 	objects/bug663134.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 0000000..1daa493
--- /dev/null
+++ b/tests/objects/bug664529.vala
@@ -0,0 +1,7 @@
+void main() {
+	var foo = new Object ();
+	var bar = new Queue<Object> ();
+	bar.push_head (foo);
+	bar = null;
+	assert (foo.ref_count == 1);
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]