File tree Expand file tree Collapse file tree 3 files changed +40
-1
lines changed
rust/src/builtin_tests/containers Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -252,6 +252,10 @@ impl Callable {
252
252
pub fn as_inner ( & self ) -> inner:: InnerCallable {
253
253
inner:: InnerCallable :: from_outer ( self )
254
254
}
255
+
256
+ fn inc_ref ( & self ) {
257
+ std:: mem:: forget ( self . clone ( ) )
258
+ }
255
259
}
256
260
257
261
impl_builtin_traits ! {
@@ -276,7 +280,18 @@ unsafe impl GodotFfi for Callable {
276
280
sys:: VariantType :: Callable
277
281
}
278
282
279
- ffi_methods ! { type sys:: GDExtensionTypePtr = * mut Opaque ; .. }
283
+ ffi_methods ! { type sys:: GDExtensionTypePtr = * mut Opaque ;
284
+ fn from_sys;
285
+ fn sys;
286
+ fn from_sys_init;
287
+ fn move_return_ptr;
288
+ }
289
+
290
+ unsafe fn from_arg_ptr ( ptr : sys:: GDExtensionTypePtr , _call_type : sys:: PtrcallType ) -> Self {
291
+ let callable = Self :: from_sys ( ptr) ;
292
+ callable. inc_ref ( ) ;
293
+ callable
294
+ }
280
295
281
296
unsafe fn from_sys_init_default ( init_fn : impl FnOnce ( sys:: GDExtensionTypePtr ) ) -> Self {
282
297
let mut result = Self :: invalid ( ) ;
Original file line number Diff line number Diff line change @@ -326,3 +326,15 @@ func test_gd_self_reference_succeeds():
326
326
gd_self_reference .update_internal_signal .connect (update_self_reference )
327
327
328
328
assert_eq (gd_self_reference .succeed_at_updating_internal_value (10 ), 10 )
329
+
330
+ func sample_func ():
331
+ pass
332
+
333
+ func test_callable_refcount ():
334
+ var test_obj : CallableRefcountTest = CallableRefcountTest .new ()
335
+ for i in range (10 ):
336
+ var method := Callable (self , "sample_func" )
337
+ test_obj .accept_callable (method )
338
+ var method := Callable (self , "sample_func" )
339
+ assert (method .is_valid ())
340
+ test_obj .free ()
Original file line number Diff line number Diff line change @@ -127,6 +127,18 @@ fn callable_call_engine() {
127
127
obj. free ( ) ;
128
128
}
129
129
130
+ // Testing https://github.com/godot-rust/gdext/issues/410
131
+
132
+ #[ derive( GodotClass ) ]
133
+ #[ class( init, base = Node ) ]
134
+ pub struct CallableRefcountTest { }
135
+
136
+ #[ godot_api]
137
+ impl CallableRefcountTest {
138
+ #[ func]
139
+ fn accept_callable ( & self , _call : Callable ) { }
140
+ }
141
+
130
142
// ----------------------------------------------------------------------------------------------------------------------------------------------
131
143
// Tests and infrastructure for custom callables
132
144
You can’t perform that action at this time.
0 commit comments