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

0 commit comments

Comments
 (0)