Skip to content

Commit 8206697

Browse files
committed
Fix return virtual method type
Add another virtual method return test Make test that causes memory leak use `#[itest(skip)]` Move the logic for determining whether to use `Ref` or not entirely into `Mem` Remove some unnecessary manual ffi tests Rename CallType
1 parent b5e74b3 commit 8206697

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+339
-251
lines changed

godot-codegen/src/central_generator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ fn make_sys_code(central_items: &CentralItems) -> String {
177177
}
178178

179179
// SAFETY:
180-
// This type is transparently represented as `Self` in Godot, so `*mut Self` is sound.
180+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
181181
unsafe impl GodotFfi for VariantType {
182182
ffi_methods! { type GDExtensionTypePtr = *mut Self; .. }
183183
}
@@ -208,7 +208,7 @@ fn make_sys_code(central_items: &CentralItems) -> String {
208208
}
209209

210210
// SAFETY:
211-
// This type is transparently represented as `Self` in Godot, so `*mut Self` is sound.
211+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
212212
unsafe impl GodotFfi for VariantOperator {
213213
ffi_methods! { type GDExtensionTypePtr = *mut Self; .. }
214214
}

godot-codegen/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ const SELECTED_CLASSES: &[&str] = &[
258258
"AudioStreamPlayer",
259259
"BaseButton",
260260
"Button",
261+
"BoxMesh",
261262
"Camera2D",
262263
"Camera3D",
263264
"CanvasItem",
@@ -276,6 +277,7 @@ const SELECTED_CLASSES: &[&str] = &[
276277
"Label",
277278
"MainLoop",
278279
"Marker2D",
280+
"Mesh",
279281
"Node",
280282
"Node2D",
281283
"Node3D",
@@ -285,9 +287,11 @@ const SELECTED_CLASSES: &[&str] = &[
285287
"PackedScene",
286288
"PathFollow2D",
287289
"PhysicsBody2D",
290+
"PrimitiveMesh",
288291
"RefCounted",
289292
"RenderingServer",
290293
"Resource",
294+
"ResourceFormatLoader",
291295
"ResourceLoader",
292296
"RigidBody2D",
293297
"SceneTree",

godot-codegen/src/util.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ pub fn make_enum_definition(enum_: &Enum) -> TokenStream {
9999
self.ord
100100
}
101101
}
102+
// SAFETY:
103+
// The enums are transparently represented as an `i32`, so `*mut Self` is sound.
102104
unsafe impl sys::GodotFfi for #enum_name {
103105
sys::ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
104106
}

godot-core/src/builtin/aabb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl Aabb {
8383
}
8484

8585
// SAFETY:
86-
// This type is transparently represented as `Self` in Godot, so `*mut Self` is sound.
86+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
8787
unsafe impl GodotFfi for Aabb {
8888
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
8989
}

godot-core/src/builtin/array.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -566,22 +566,23 @@ impl<T: VariantMetadata + ToVariant> Array<T> {
566566
// ...
567567
// }
568568

569+
// SAFETY:
570+
// - `move_return_ptr`
571+
// Nothing special needs to be done beyond a `std::mem::swap` when returning an Array.
572+
// So we can just use `ffi_methods`.
573+
//
574+
// - `from_arg_ptr`
575+
// Arrays are properly initialized through a `from_sys` call, but the ref-count should be incremented
576+
// as that is the callee's responsibility. Which we do by calling `std::mem::forget(array.share())`.
569577
unsafe impl<T: VariantMetadata> GodotFfi for Array<T> {
570578
ffi_methods! { type sys::GDExtensionTypePtr = *mut Opaque;
571579
fn from_sys;
572580
fn sys;
573581
fn from_sys_init;
574-
// SAFETY:
575-
// Nothing special needs to be done beyond a `std::mem::swap` when returning an Array.
576582
fn move_return_ptr;
577583
}
578584

579-
// SAFETY:
580-
// Arrays are properly initialized through a `from_sys` call, but the ref-count should be
581-
// incremented as that is the callee's responsibility.
582-
//
583-
// Using `std::mem::forget(array.share())` increments the ref count.
584-
unsafe fn from_arg_ptr(ptr: sys::GDExtensionTypePtr, _call_type: sys::CallType) -> Self {
585+
unsafe fn from_arg_ptr(ptr: sys::GDExtensionTypePtr, _call_type: sys::PtrcallType) -> Self {
585586
let array = Self::from_sys(ptr);
586587
std::mem::forget(array.share());
587588
array

godot-core/src/builtin/basis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ impl Mul<Vector3> for Basis {
571571
}
572572

573573
// SAFETY:
574-
// This type is transparently represented as `Self` in Godot, so `*mut Self` is sound.
574+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
575575
unsafe impl GodotFfi for Basis {
576576
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
577577
}

godot-core/src/builtin/color.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ impl Color {
312312
}
313313

314314
// SAFETY:
315-
// This type is transparently represented as `Self` in Godot, so `*mut Self` is sound.
315+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
316316
unsafe impl GodotFfi for Color {
317317
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
318318
}

godot-core/src/builtin/dictionary.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,22 +239,24 @@ impl Dictionary {
239239
// ----------------------------------------------------------------------------------------------------------------------------------------------
240240
// Traits
241241

242+
// SAFETY:
243+
// - `move_return_ptr`
244+
// Nothing special needs to be done beyond a `std::mem::swap` when returning an Dictionary.
245+
// So we can just use `ffi_methods`.
246+
//
247+
// - `from_arg_ptr`
248+
// Dictionaries are properly initialized through a `from_sys` call, but the ref-count should be
249+
// incremented as that is the callee's responsibility. Which we do by calling
250+
// `std::mem::forget(dictionary.share())`.
242251
unsafe impl GodotFfi for Dictionary {
243252
ffi_methods! { type sys::GDExtensionTypePtr = *mut Opaque;
244253
fn from_sys;
245254
fn from_sys_init;
246255
fn sys;
247-
// SAFETY:
248-
// Nothing special needs to be done beyond a `std::mem::swap` when returning a dictionary.
249256
fn move_return_ptr;
250257
}
251258

252-
// SAFETY:
253-
// Dictionaries are properly initialized through a `from_sys` call, but the ref-count should be
254-
// incremented as that is the callee's responsibility.
255-
//
256-
// Using `std::mem::forget(dictionary.share())` increments the ref count.
257-
unsafe fn from_arg_ptr(ptr: sys::GDExtensionTypePtr, _call_type: sys::CallType) -> Self {
259+
unsafe fn from_arg_ptr(ptr: sys::GDExtensionTypePtr, _call_type: sys::PtrcallType) -> Self {
258260
let dictionary = Self::from_sys(ptr);
259261
std::mem::forget(dictionary.share());
260262
dictionary

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub trait SignatureTuple {
3434
ret: sys::GDExtensionTypePtr,
3535
func: fn(&mut C, Self::Params) -> Self::Ret,
3636
method_name: &str,
37-
call_type: sys::CallType,
37+
call_type: sys::PtrcallType,
3838
);
3939
}
4040

@@ -144,7 +144,7 @@ macro_rules! impl_signature_for_tuple {
144144
ret: sys::GDExtensionTypePtr,
145145
func: fn(&mut C, Self::Params) -> Self::Ret,
146146
method_name: &str,
147-
call_type: sys::CallType,
147+
call_type: sys::PtrcallType,
148148
) {
149149
$crate::out!("ptrcall: {}", method_name);
150150

godot-core/src/builtin/node_path.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,24 @@ impl NodePath {
2222
}
2323
}
2424

25+
// SAFETY:
26+
// - `move_return_ptr`
27+
// Nothing special needs to be done beyond a `std::mem::swap` when returning a NodePath.
28+
// So we can just use `ffi_methods`.
29+
//
30+
// - `from_arg_ptr`
31+
// NodePaths are properly initialized through a `from_sys` call, but the ref-count should be
32+
// incremented as that is the callee's responsibility. Which we do by calling
33+
// `std::mem::forget(node_path.share())`.
2534
unsafe impl GodotFfi for NodePath {
2635
ffi_methods! { type sys::GDExtensionTypePtr = *mut Opaque;
2736
fn from_sys;
2837
fn sys;
2938
fn from_sys_init;
30-
// SAFETY:
31-
// Nothing special needs to be done beyond a `std::mem::swap` when returning a NodePath.
3239
fn move_return_ptr;
3340
}
3441

35-
// SAFETY:
36-
// NodePaths are properly initialized through a `from_sys` call, but the ref-count should be
37-
// incremented as that is the callee's responsibility.
38-
//
39-
// Using `std::mem::forget(node_path.share())` increments the ref count.
40-
unsafe fn from_arg_ptr(ptr: sys::GDExtensionTypePtr, _call_type: sys::CallType) -> Self {
42+
unsafe fn from_arg_ptr(ptr: sys::GDExtensionTypePtr, _call_type: sys::PtrcallType) -> Self {
4143
let node_path = Self::from_sys(ptr);
4244
std::mem::forget(node_path.clone());
4345
node_path

godot-core/src/builtin/packed_array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ macro_rules! impl_packed_array {
405405
// incremented as that is the callee's responsibility.
406406
//
407407
// Using `std::mem::forget(array.clone())` increments the ref count.
408-
unsafe fn from_arg_ptr(ptr: sys::GDExtensionTypePtr, _call_type: sys::CallType) -> Self {
408+
unsafe fn from_arg_ptr(ptr: sys::GDExtensionTypePtr, _call_type: sys::PtrcallType) -> Self {
409409
let array = Self::from_sys(ptr);
410410
std::mem::forget(array.clone());
411411
array

godot-core/src/builtin/plane.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl Neg for Plane {
135135
}
136136

137137
// SAFETY:
138-
// This type is transparently represented as `Self` in Godot, so `*mut Self` is sound.
138+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
139139
unsafe impl GodotFfi for Plane {
140140
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
141141
}

godot-core/src/builtin/projection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ impl GlamConv for Projection {
487487
}
488488

489489
// SAFETY:
490-
// This type is transparently represented as `Self` in Godot, so `*mut Self` is sound.
490+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
491491
unsafe impl GodotFfi for Projection {
492492
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
493493
}

godot-core/src/builtin/quaternion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ impl Mul<Quaternion> for Quaternion {
255255
}
256256

257257
// SAFETY:
258-
// This type is transparently represented as `Self` in Godot, so `*mut Self` is sound.
258+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
259259
unsafe impl GodotFfi for Quaternion {
260260
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
261261
}

godot-core/src/builtin/rect2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl Rect2 {
105105
}
106106

107107
// SAFETY:
108-
// This type is transparently represented as `Self` in Godot, so `*mut Self` is sound.
108+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
109109
unsafe impl GodotFfi for Rect2 {
110110
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
111111
}

godot-core/src/builtin/rect2i.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl Rect2i {
9494
}
9595

9696
// SAFETY:
97-
// This type is transparently represented as `Self` in Godot, so `*mut Self` is sound.
97+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
9898
unsafe impl GodotFfi for Rect2i {
9999
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
100100
}

godot-core/src/builtin/rid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl Rid {
8282
}
8383

8484
// SAFETY:
85-
// This type is transparently represented as `Self` in Godot, so `*mut Self` is sound.
85+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
8686
unsafe impl GodotFfi for Rid {
8787
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
8888
}

godot-core/src/builtin/string.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ impl GodotString {
3737
fn string_sys = sys;
3838
}
3939

40-
/// Move `self` into a system pointer.
40+
/// Move `self` into a system pointer. This transfers ownership and thus does not call the destructor.
4141
///
4242
/// # Safety
4343
/// `dst` must be a pointer to a `GodotString` which is suitable for ffi with Godot.
4444
pub unsafe fn move_string_ptr(self, dst: sys::GDExtensionStringPtr) {
45-
self.move_return_ptr(dst as *mut _, sys::CallType::Standard);
45+
self.move_return_ptr(dst as *mut _, sys::PtrcallType::Standard);
4646
}
4747

4848
/// Gets the internal chars slice from a [`GodotString`].
@@ -75,22 +75,24 @@ impl GodotString {
7575
}
7676
}
7777

78+
// SAFETY:
79+
// - `move_return_ptr`
80+
// Nothing special needs to be done beyond a `std::mem::swap` when returning a String.
81+
// So we can just use `ffi_methods`.
82+
//
83+
// - `from_arg_ptr`
84+
// Strings are properly initialized through a `from_sys` call, but the ref-count should be
85+
// incremented as that is the callee's responsibility. Which we do by calling
86+
// `std::mem::forget(string.share())`.
7887
unsafe impl GodotFfi for GodotString {
7988
ffi_methods! { type sys::GDExtensionTypePtr = *mut Opaque;
8089
fn from_sys;
8190
fn sys;
8291
fn from_sys_init;
83-
// SAFETY:
84-
// Nothing special needs to be done beyond a `std::mem::swap` when returning a GodotString.
8592
fn move_return_ptr;
8693
}
8794

88-
// SAFETY:
89-
// GodotStrings are properly initialized through a `from_sys` call, but the ref-count should be
90-
// incremented as that is the callee's responsibility.
91-
//
92-
// Using `std::mem::forget(string.share())` increments the ref count.
93-
unsafe fn from_arg_ptr(ptr: sys::GDExtensionTypePtr, _call_type: sys::CallType) -> Self {
95+
unsafe fn from_arg_ptr(ptr: sys::GDExtensionTypePtr, _call_type: sys::PtrcallType) -> Self {
9496
let string = Self::from_sys(ptr);
9597
std::mem::forget(string.clone());
9698
string

godot-core/src/builtin/string_name.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,24 @@ impl StringName {
3131
}
3232
}
3333

34+
// SAFETY:
35+
// - `move_return_ptr`
36+
// Nothing special needs to be done beyond a `std::mem::swap` when returning a StringName.
37+
// So we can just use `ffi_methods`.
38+
//
39+
// - `from_arg_ptr`
40+
// StringNames are properly initialized through a `from_sys` call, but the ref-count should be
41+
// incremented as that is the callee's responsibility. Which we do by calling
42+
// `std::mem::forget(string_name.share())`.
3443
unsafe impl GodotFfi for StringName {
3544
ffi_methods! { type sys::GDExtensionTypePtr = *mut Opaque;
3645
fn from_sys;
3746
fn sys;
3847
fn from_sys_init;
39-
// SAFETY:
40-
// Nothing special needs to be done beyond a `std::mem::swap` when returning a StringName.
4148
fn move_return_ptr;
4249
}
4350

44-
// SAFETY:
45-
// StringNames are properly initialized through a `from_sys` call, but the ref-count should be
46-
// incremented as that is the callee's responsibility.
47-
//
48-
// Using `std::mem::forget(string_name.share())` increments the ref count.
49-
unsafe fn from_arg_ptr(ptr: sys::GDExtensionTypePtr, _call_type: sys::CallType) -> Self {
51+
unsafe fn from_arg_ptr(ptr: sys::GDExtensionTypePtr, _call_type: sys::PtrcallType) -> Self {
5052
let string_name = Self::from_sys(ptr);
5153
std::mem::forget(string_name.clone());
5254
string_name

godot-core/src/builtin/transform2d.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ impl GlamConv for Transform2D {
359359
}
360360

361361
// SAFETY:
362-
// This type is transparently represented as `Self` in Godot, so `*mut Self` is sound.
362+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
363363
unsafe impl GodotFfi for Transform2D {
364364
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
365365
}

godot-core/src/builtin/transform3d.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ impl GlamConv for Transform3D {
353353
}
354354

355355
// SAFETY:
356-
// This type is transparently represented as `Self` in Godot, so `*mut Self` is sound.
356+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
357357
unsafe impl GodotFfi for Transform3D {
358358
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
359359
}

godot-core/src/builtin/vector2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ impl_vector_operators!(Vector2, real, (x, y));
311311
impl_vector_index!(Vector2, real, (x, y), Vector2Axis, (X, Y));
312312

313313
// SAFETY:
314-
// This type is transparently represented as `Self` in Godot, so `*mut Self` is sound.
314+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
315315
unsafe impl GodotFfi for Vector2 {
316316
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
317317
}
@@ -327,7 +327,7 @@ pub enum Vector2Axis {
327327
}
328328

329329
// SAFETY:
330-
// This type is transparently represented as `Self` in Godot, so `*mut Self` is sound.
330+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
331331
unsafe impl GodotFfi for Vector2Axis {
332332
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
333333
}

godot-core/src/builtin/vector2i.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl_vector_operators!(Vector2i, i32, (x, y));
8989
impl_vector_index!(Vector2i, i32, (x, y), Vector2iAxis, (X, Y));
9090

9191
// SAFETY:
92-
// This type is transparently represented as `Self` in Godot, so `*mut Self` is sound.
92+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
9393
unsafe impl GodotFfi for Vector2i {
9494
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
9595
}
@@ -105,7 +105,7 @@ pub enum Vector2iAxis {
105105
}
106106

107107
// SAFETY:
108-
// This type is transparently represented as `Self` in Godot, so `*mut Self` is sound.
108+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
109109
unsafe impl GodotFfi for Vector2iAxis {
110110
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
111111
}

0 commit comments

Comments
 (0)