}
var function = new CCodeFunction (destroy_func, "void");
- function.modifiers = CCodeModifiers.STATIC;
-
function.add_parameter (new CCodeParameter ("self", get_ccode_name (collection_type)));
push_function (function);
- CCodeFunctionCall element_free_call;
if (collection_type.data_type == gnode_type) {
+ CCodeFunctionCall element_free_call;
/* A wrapper which converts GNodeTraverseFunc into GDestroyNotify */
string destroy_node_func = "%s_node".printf (destroy_func);
var wrapper = new CCodeFunction (destroy_node_func, "gboolean");
element_free_call.add_argument (new CCodeConstant ("-1"));
element_free_call.add_argument (new CCodeIdentifier (destroy_node_func));
element_free_call.add_argument (new CCodeConstant ("NULL"));
+ ccode.add_expression (element_free_call);
+
+ var cfreecall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_free_function (gnode_type)));
+ cfreecall.add_argument (new CCodeIdentifier ("self"));
+ ccode.add_expression (cfreecall);
+
+ function.modifiers = CCodeModifiers.STATIC;
} else {
+ CCodeFunctionCall collection_free_call;
if (collection_type.data_type == glist_type) {
- element_free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_list_foreach"));
+ collection_free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_list_free_full"));
} else if (collection_type.data_type == gslist_type) {
- element_free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_slist_foreach"));
+ collection_free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_slist_free_full"));
} else {
- element_free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_queue_foreach"));
+ collection_free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_queue_free_full"));
}
- element_free_call.add_argument (new CCodeIdentifier ("self"));
- element_free_call.add_argument (new CCodeCastExpression (element_destroy_func_expression, "GFunc"));
- element_free_call.add_argument (new CCodeConstant ("NULL"));
- }
+ collection_free_call.add_argument (new CCodeIdentifier ("self"));
+ collection_free_call.add_argument (new CCodeCastExpression (element_destroy_func_expression, "GDestroyNotify"));
+ ccode.add_expression (collection_free_call);
- ccode.add_expression (element_free_call);
-
- var cfreecall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_free_function (collection_type.data_type)));
- cfreecall.add_argument (new CCodeIdentifier ("self"));
- ccode.add_expression (cfreecall);
+ function.modifiers = CCodeModifiers.STATIC | CCodeModifiers.INLINE;
+ }
pop_function ();
--- /dev/null
+void test_glist () {
+ var list = new GLib.List<string> ();
+ list.prepend ("foo");
+ list.prepend ("bar");
+ assert (list.nth_data (1) == "foo");
+ list = null;
+
+ var list2 = new GLib.List<unowned string> ();
+ list2.prepend ("foo");
+ list2.prepend ("bar");
+ assert (list2.nth_data (1) == "foo");
+ list2 = null;
+}
+
+void test_gslist () {
+ var list = new GLib.SList<string> ();
+ list.prepend ("foo");
+ list.prepend ("bar");
+ assert (list.nth_data (1) == "foo");
+ list = null;
+
+ var list2 = new GLib.SList<unowned string> ();
+ list2.prepend ("foo");
+ list2.prepend ("bar");
+ assert (list2.nth_data (1) == "foo");
+ list2 = null;
+}
+
+void test_gqueue () {
+ var queue = new GLib.Queue<string> ();
+ queue.push_head ("foo");
+ queue.push_head ("bar");
+ assert (queue.peek_nth (1) == "foo");
+ queue = null;
+
+ var queue2 = new GLib.Queue<unowned string> ();
+ queue2.push_head ("foo");
+ queue2.push_head ("bar");
+ assert (queue2.peek_nth (1) == "foo");
+ queue2 = null;
+}
+
+void main () {
+ test_glist ();
+ test_gslist ();
+ test_gqueue ();
+}