]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Destroy the elements of GQueue
authorLuca Bruno <lucabru@src.gnome.org>
Tue, 22 Nov 2011 14:44:07 +0000 (15:44 +0100)
committerJürg Billeter <j@bitron.ch>
Wed, 30 Nov 2011 14:05:03 +0000 (15:05 +0100)
When destroying a GQueue also destroy its elements like we do with GList,
GSList and GNode.

Fixes bug 664529.

codegen/valaccodebasemodule.vala
tests/Makefile.am
tests/objects/bug664529.vala [new file with mode: 0644]

index d18b269fc2d247a1c353e38a02d2c4926acd113b..dd934f65e4950ed763ca119a630af8ff32123d5b 100644 (file)
@@ -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"));
index a2075018cefc194c4db28c6857e0c2ca7a222bf6..d4e1af194ddc523c76574fff2b19cadf7c993a44 100644 (file)
@@ -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 (file)
index 0000000..1daa493
--- /dev/null
@@ -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);
+}