[vala/wip/682_array_methods_refactor: 10/18] Handle unowned arrays
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/682_array_methods_refactor: 10/18] Handle unowned arrays
- Date: Mon, 12 Sep 2022 07:26:22 +0000 (UTC)
commit 28ff4e88405df6bdb6e87c74cb5c4f7386f945a2
Author: Vladyslav Stovmanenko <flaviusglamfenix gmail com>
Date: Sat May 7 19:31:36 2022 +0000
Handle unowned arrays
codegen/valaccodemethodcallmodule.vala | 7 ++++++-
tests/basic-types/arrays-move-with-class.vala | 22 ++++++++++++++++++++--
2 files changed, 26 insertions(+), 3 deletions(-)
---
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<arr_size; i++)
{
- arr[i] = new TestDestructorCalls (i);
+ arr[i] = new TestDestructorCalls (i);
}
arr.move (src, dest, count);
assert (TestDestructorCalls.destructor_calls == expected_destructor_calls);
}
+void test_unowned_array_move (int src, int dest, int count)
+{
+ const int arr_size = 5;
+ TestDestructorCalls.destructor_calls = 0;
+ (unowned TestDestructorCalls)[] arr = new TestDestructorCalls[arr_size];
+ TestDestructorCalls[] owner = new TestDestructorCalls[arr_size];
+
+ for(int i=0; i<arr_size; i++)
+ {
+ var obj = new TestDestructorCalls (i);
+ owner[i] = obj;
+ arr[i] = obj;
+ }
+
+ arr.move (src, dest, count);
+ assert (TestDestructorCalls.destructor_calls == 0);
+}
+
void main()
{
test_array_with_classes_move(0, 2, 3, 1);
test_array_with_classes_move(2, 0, 3, 2);
test_array_with_classes_move(0, 3, 1, 1);
-
+ test_unowned_array_move(3, 0, 1);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]