Skip to content

Commit 59e4f75

Browse files
committed
Merge branch 'master' into feature/object-notification
# Conflicts: # itest/rust/src/virtual_methods_test.rs
2 parents 1b413a5 + afbd2cd commit 59e4f75

Some content is hidden

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

53 files changed

+1122
-330
lines changed

godot-codegen/src/central_generator.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ fn make_sys_code(central_items: &CentralItems) -> String {
180180
}
181181
}
182182

183-
impl GodotFfi for VariantType {
183+
// SAFETY:
184+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
185+
unsafe impl GodotFfi for VariantType {
184186
ffi_methods! { type GDExtensionTypePtr = *mut Self; .. }
185187
}
186188

@@ -211,7 +213,9 @@ fn make_sys_code(central_items: &CentralItems) -> String {
211213
}
212214
}
213215

214-
impl GodotFfi for VariantOperator {
216+
// SAFETY:
217+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
218+
unsafe impl GodotFfi for VariantOperator {
215219
ffi_methods! { type GDExtensionTypePtr = *mut Self; .. }
216220
}
217221
};

godot-codegen/src/class_generator.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,12 @@ fn make_method_definition(
842842
__method_name.string_sys(),
843843
#hash
844844
);
845+
assert!(
846+
!__method_bind.is_null(),
847+
"failed to load method {}::{} -- possible Godot and gdext version mismatch",
848+
#class_name_str,
849+
#method_name_str
850+
);
845851
let __call_fn = sys::interface_fn!(#function_provider);
846852
};
847853
let varcall_invocation = quote! {

godot-codegen/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ const SELECTED_CLASSES: &[&str] = &[
262262
"AudioStreamPlayer",
263263
"BaseButton",
264264
"Button",
265+
"BoxMesh",
265266
"Camera2D",
266267
"Camera3D",
267268
"CanvasItem",
@@ -275,9 +276,12 @@ const SELECTED_CLASSES: &[&str] = &[
275276
"Image",
276277
"ImageTextureLayered",
277278
"Input",
279+
"InputEvent",
280+
"InputEventAction",
278281
"Label",
279282
"MainLoop",
280283
"Marker2D",
284+
"Mesh",
281285
"Node",
282286
"Node2D",
283287
"Node3D",
@@ -287,9 +291,11 @@ const SELECTED_CLASSES: &[&str] = &[
287291
"PackedScene",
288292
"PathFollow2D",
289293
"PhysicsBody2D",
294+
"PrimitiveMesh",
290295
"RefCounted",
291296
"RenderingServer",
292297
"Resource",
298+
"ResourceFormatLoader",
293299
"ResourceLoader",
294300
"RigidBody2D",
295301
"SceneTree",
@@ -300,4 +306,6 @@ const SELECTED_CLASSES: &[&str] = &[
300306
"TextureLayered",
301307
"Time",
302308
"Timer",
309+
"Window",
310+
"Viewport",
303311
];

godot-codegen/src/util.rs

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

godot-core/src/builtin/aabb.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ impl Aabb {
8282
*/
8383
}
8484

85-
impl GodotFfi for Aabb {
85+
// SAFETY:
86+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
87+
unsafe impl GodotFfi for Aabb {
8688
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
8789
}

godot-core/src/builtin/array.rs

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

569-
impl<T: VariantMetadata> GodotFfi for Array<T> {
570-
ffi_methods! { type sys::GDExtensionTypePtr = *mut Opaque; .. }
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())`.
577+
unsafe impl<T: VariantMetadata> GodotFfi for Array<T> {
578+
ffi_methods! { type sys::GDExtensionTypePtr = *mut Opaque;
579+
fn from_sys;
580+
fn sys;
581+
fn from_sys_init;
582+
fn move_return_ptr;
583+
}
584+
585+
unsafe fn from_arg_ptr(ptr: sys::GDExtensionTypePtr, _call_type: sys::PtrcallType) -> Self {
586+
let array = Self::from_sys(ptr);
587+
std::mem::forget(array.share());
588+
array
589+
}
571590

572591
unsafe fn from_sys_init_default(init_fn: impl FnOnce(sys::GDExtensionTypePtr)) -> Self {
573592
let mut result = Self::default();
@@ -855,7 +874,7 @@ macro_rules! varray {
855874
/// [`set_typed`](https://docs.godotengine.org/en/latest/classes/class_array.html#class-array-method-set-typed).
856875
///
857876
/// We ignore the `script` parameter because it has no impact on typing in Godot.
858-
#[derive(Debug, PartialEq, Eq)]
877+
#[derive(PartialEq, Eq)]
859878
struct TypeInfo {
860879
variant_type: VariantType,
861880
class_name: StringName,
@@ -880,3 +899,16 @@ impl TypeInfo {
880899
self.variant_type != VariantType::Nil
881900
}
882901
}
902+
903+
impl fmt::Debug for TypeInfo {
904+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
905+
let class = self.class_name.to_string();
906+
let class_str = if class.is_empty() {
907+
String::new()
908+
} else {
909+
format!(" (class={class})")
910+
};
911+
912+
write!(f, "{:?}{}", self.variant_type, class_str)
913+
}
914+
}

godot-core/src/builtin/basis.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,9 @@ impl Mul<Vector3> for Basis {
570570
}
571571
}
572572

573-
impl GodotFfi for Basis {
573+
// SAFETY:
574+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
575+
unsafe impl GodotFfi for Basis {
574576
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
575577
}
576578

godot-core/src/builtin/color.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ impl Color {
311311
}
312312
}
313313

314-
impl GodotFfi for Color {
314+
// SAFETY:
315+
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
316+
unsafe impl GodotFfi for Color {
315317
ffi_methods! { type sys::GDExtensionTypePtr = *mut Self; .. }
316318
}
317319

godot-core/src/builtin/dictionary.rs

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

242-
impl GodotFfi for Dictionary {
243-
ffi_methods! { type sys::GDExtensionTypePtr = *mut Opaque; .. }
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())`.
251+
unsafe impl GodotFfi for Dictionary {
252+
ffi_methods! { type sys::GDExtensionTypePtr = *mut Opaque;
253+
fn from_sys;
254+
fn from_sys_init;
255+
fn sys;
256+
fn move_return_ptr;
257+
}
258+
259+
unsafe fn from_arg_ptr(ptr: sys::GDExtensionTypePtr, _call_type: sys::PtrcallType) -> Self {
260+
let dictionary = Self::from_sys(ptr);
261+
std::mem::forget(dictionary.share());
262+
dictionary
263+
}
244264

245265
unsafe fn from_sys_init_default(init_fn: impl FnOnce(sys::GDExtensionTypePtr)) -> Self {
246266
let mut result = Self::default();

godot-core/src/builtin/macros.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ macro_rules! impl_builtin_stub {
157157
}
158158
}
159159

160-
impl GodotFfi for $Class {
160+
// SAFETY:
161+
// This is simply a wrapper around an `Opaque` value representing a value of the type.
162+
// So this is safe.
163+
unsafe impl GodotFfi for $Class {
161164
ffi_methods! { type sys::GDExtensionTypePtr = *mut Opaque; .. }
162165
}
163166
};

0 commit comments

Comments
 (0)