From: Vladyslav Stovmanenko Date: Sat, 7 May 2022 19:31:36 +0000 (+0000) Subject: Handle unowned arrays X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=28ff4e88405df6bdb6e87c74cb5c4f7386f945a2;p=thirdparty%2Fvala.git Handle unowned arrays --- diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala index 4c6ecf069..2b4a6d66f 100644 --- a/codegen/valaccodemethodcallmodule.vala +++ b/codegen/valaccodemethodcallmodule.vala @@ -338,7 +338,12 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { csizeof.add_argument (new CCodeIdentifier (get_ccode_name (array_type.element_type))); in_arg_map.set (get_param_pos (0.1), csizeof); - in_arg_map.set (get_param_pos (0.2), get_destroy_func_expression(array_type.element_type)); + CCodeExpression? free_func_expr = new CCodeIdentifier("NULL"); + if (array_type.element_type.value_owned) { + free_func_expr = get_destroy_func_expression(array_type.element_type); + } + + in_arg_map.set (get_param_pos (0.2), free_func_expr); } else if (m is DynamicMethod) { emit_context.push_symbol (m); m.clear_parameters (); diff --git a/tests/basic-types/arrays-move-with-class.vala b/tests/basic-types/arrays-move-with-class.vala index 4a6525703..c01d10623 100644 --- a/tests/basic-types/arrays-move-with-class.vala +++ b/tests/basic-types/arrays-move-with-class.vala @@ -14,17 +14,35 @@ void test_array_with_classes_move (int src, int dest, int count, int expected_de TestDestructorCalls[] arr = new TestDestructorCalls[arr_size]; for(int i=0; i