Skip to content

Commit 1c94e10

Browse files
committed
Variant, String: rename forget() -> leak()
Consistent with standard Vec::leak(), Box::leak() etc.
1 parent 35f4ad2 commit 1c94e10

File tree

6 files changed

+21
-23
lines changed

6 files changed

+21
-23
lines changed

gdnative-core/src/core_types/string.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,14 @@ impl GodotString {
237237
Self(unsafe { (get_api().godot_string_format)(&self.0, &values.0) })
238238
}
239239

240-
/// Returns the internal ffi representation of the string and consumes
241-
/// the rust object without running the destructor.
240+
/// Returns the internal FFI representation of the string and consumes
241+
/// the Rust object without running the destructor.
242242
///
243-
/// This should be only used when certain that the receiving side is
244-
/// responsible for running the destructor for the object, otherwise
245-
/// it is leaked.
243+
/// The returned object has no `Drop` implementation. The caller is
244+
/// responsible of manually ensuring destruction.
246245
#[doc(hidden)]
247246
#[inline]
248-
pub fn forget(self) -> sys::godot_string {
247+
pub fn leak(self) -> sys::godot_string {
249248
let v = self.0;
250249
forget(self);
251250
v
@@ -285,7 +284,7 @@ impl GodotString {
285284
pub fn clone_from_sys(sys: sys::godot_string) -> Self {
286285
let sys_string = GodotString(sys);
287286
let this = sys_string.clone();
288-
sys_string.forget();
287+
sys_string.leak();
289288
this
290289
}
291290

gdnative-core/src/core_types/variant.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -524,15 +524,14 @@ impl Variant {
524524
unsafe { &mut *(ptr as *mut variant::Variant) }
525525
}
526526

527-
/// Returns the internal ffi representation of the variant and consumes
528-
/// the rust object without running the destructor.
527+
/// Returns the internal FFI representation of the variant and consumes
528+
/// the Rust object without running the destructor.
529529
///
530-
/// This should be only used when certain that the receiving side is
531-
/// responsible for running the destructor for the object, otherwise
532-
/// it is leaked.
530+
/// The returned object has no `Drop` implementation. The caller is
531+
/// responsible of manually ensuring destruction.
533532
#[inline]
534533
#[doc(hidden)]
535-
pub fn forget(self) -> sys::godot_variant {
534+
pub fn leak(self) -> sys::godot_variant {
536535
let v = self.0;
537536
forget(self);
538537
v

gdnative-core/src/export/method.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ unsafe extern "C" fn method_wrapper<C: NativeClass, F: Method<C>>(
549549
C::class_name(),
550550
),
551551
);
552-
return Variant::nil().forget();
552+
return Variant::nil().leak();
553553
}
554554

555555
let this = match std::ptr::NonNull::new(this) {
@@ -562,7 +562,7 @@ unsafe extern "C" fn method_wrapper<C: NativeClass, F: Method<C>>(
562562
C::class_name(),
563563
),
564564
);
565-
return Variant::nil().forget();
565+
return Variant::nil().leak();
566566
}
567567
};
568568

@@ -586,7 +586,7 @@ unsafe extern "C" fn method_wrapper<C: NativeClass, F: Method<C>>(
586586
);
587587
Variant::nil()
588588
})
589-
.forget()
589+
.leak()
590590
}
591591

592592
unsafe extern "C" fn free_func<F>(method_data: *mut libc::c_void) {

gdnative-core/src/export/property/accessor.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ where
296296
"gdnative-core: user data pointer for {} is null (did the constructor fail?)",
297297
C::class_name(),
298298
);
299-
return Variant::nil().forget();
299+
return Variant::nil().leak();
300300
}
301301

302302
let this = match NonNull::new(this) {
@@ -306,7 +306,7 @@ where
306306
"gdnative-core: owner pointer for {} is null",
307307
C::class_name(),
308308
);
309-
return Variant::nil().forget();
309+
return Variant::nil().leak();
310310
}
311311
};
312312

@@ -316,17 +316,17 @@ where
316316
let func = &*(method as *const F);
317317

318318
match <(SelfArg, RetKind)>::map_get(&user_data, func, owner) {
319-
Ok(variant) => variant.forget(),
319+
Ok(variant) => variant.leak(),
320320
Err(err) => {
321321
godot_error!("gdnative-core: cannot call property getter: {:?}", err);
322-
Variant::nil().forget()
322+
Variant::nil().leak()
323323
}
324324
}
325325
});
326326

327327
result.unwrap_or_else(|_| {
328328
godot_error!("gdnative-core: property getter panicked (check stderr for output)");
329-
Variant::nil().forget()
329+
Variant::nil().leak()
330330
})
331331
}
332332
get.get_func = Some(invoke::<SelfArg, RetKind, C, F, T>);

gdnative-core/src/export/property/invalid_accessor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ extern "C" fn invalid_getter(
7070
property_name,
7171
class_name
7272
);
73-
Variant::nil().forget()
73+
Variant::nil().leak()
7474
}
7575

7676
extern "C" fn invalid_free_func(data: *mut libc::c_void) {

test/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub extern "C" fn run_tests(
7575
status &= test_variant_ops::run_tests();
7676
status &= test_vararray_return::run_tests();
7777

78-
gdnative::core_types::Variant::new(status).forget()
78+
gdnative::core_types::Variant::new(status).leak()
7979
}
8080

8181
fn test_underscore_method_binding() -> bool {

0 commit comments

Comments
 (0)