Skip to content

Commit ccfae72

Browse files
committed
-Add std::mem::forget.
-Add tests that would trigger #138 before this fix.
1 parent 460c5ea commit ccfae72

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

godot-core/src/builtin/meta/signature.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,9 @@ macro_rules! impl_signature_for_tuple {
162162
unsafe { <$R as sys::GodotFuncMarshal>::try_write_sys(&ret_val, ret) }
163163
.unwrap_or_else(|e| return_error::<$R>(method_name, &e));
164164

165-
// FIXME is inc_ref needed here?
166-
// std::mem::forget(ret_val);
165+
//Note: we want to prevent the destructor from being run, since we pass ownership to the caller.
166+
// For details look at https://github.com/godot-rust/gdext/pull/165
167+
std::mem::forget(ret_val);
167168
}
168169
}
169170
};

itest/godot/InheritTests.gd

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
extends ArrayTest
2+
3+
var _assertion_failed: bool = false
4+
5+
## Asserts that `what` is `true`, but does not abort the test. Returns `what` so you can return
6+
## early from the test function if the assertion failed.
7+
func assert_that(what: bool, message: String = "") -> bool:
8+
if what:
9+
return true
10+
11+
_assertion_failed = true
12+
if message:
13+
print("assertion failed: %s" % message)
14+
else:
15+
print("assertion failed")
16+
return false
17+
18+
func assert_eq(left, right, message: String = "") -> bool:
19+
if left == right:
20+
return true
21+
22+
_assertion_failed = true
23+
if message:
24+
print("assertion failed: %s\n left: %s\n right: %s" % [message, left, right])
25+
else:
26+
print("assertion failed: `(left == right)`\n left: %s\n right: %s" % [left, right])
27+
return false
28+
29+
30+
31+
# Called when the node enters the scene tree for the first time.
32+
func _ready():
33+
pass
34+
35+
func test_vector_array_return_from_user_func():
36+
var array: Array = return_typed_array(2)
37+
assert_eq(array, [1,2])
38+
39+
# Called every frame. 'delta' is the elapsed time since the previous frame.
40+
func _process(delta):
41+
pass

itest/godot/TestRunner.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ func _ready():
99

1010
var gdscript_suites: Array = [
1111
preload("res://ManualFfiTests.gd").new(),
12+
preload("res://InheritTests.gd").new(),
1213
preload("res://gen/GenFfiTests.gd").new(),
1314
]
1415

0 commit comments

Comments
 (0)