From 6f21759a0ebce27ad43b864c4fc4348046034553 Mon Sep 17 00:00:00 2001 From: Yarvin Date: Sat, 23 Nov 2024 13:49:04 +0100 Subject: [PATCH 1/2] Use `GDExtensionCallableCustomInfo2` instead of deprecated `GDExtensionCallableCustomInfo`. ====== MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The only difference between old and new `GDExtensionCallableCustomInfo` is an addition of `get_argument_count_func`. In godot-cpp implementation the only way to get this count is overriding method in the question; For now we are leaving nullptr – consider implementing builder pattern for the Callable (`Callable::from_…ex(…).arg_count(n).done()`) if the need to do so arise. --- godot-core/src/builtin/callable.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/godot-core/src/builtin/callable.rs b/godot-core/src/builtin/callable.rs index bb6095bcb..32b136ff1 100644 --- a/godot-core/src/builtin/callable.rs +++ b/godot-core/src/builtin/callable.rs @@ -16,6 +16,11 @@ use crate::obj::{Gd, GodotClass, InstanceId}; use std::{fmt, ptr}; use sys::{ffi_methods, GodotFfi}; +#[cfg(all(since_api = "4.2", before_api = "4.3"))] +type CallableCustomInfo = sys::GDExtensionCallableCustomInfo; +#[cfg(since_api = "4.3")] +type CallableCustomInfo = sys::GDExtensionCallableCustomInfo2; + /// A `Callable` represents a function in Godot. /// /// Usually a callable is a reference to an `Object` and a method name, this is a standard callable. But can @@ -61,8 +66,8 @@ impl Callable { } #[cfg(since_api = "4.2")] - fn default_callable_custom_info() -> sys::GDExtensionCallableCustomInfo { - sys::GDExtensionCallableCustomInfo { + fn default_callable_custom_info() -> CallableCustomInfo { + CallableCustomInfo { callable_userdata: ptr::null_mut(), token: ptr::null_mut(), object_id: 0, @@ -74,6 +79,8 @@ impl Callable { // Op < is only used in niche scenarios and default is usually good enough, see https://github.com/godotengine/godot/issues/81901. less_than_func: None, to_string_func: None, + #[cfg(since_api = "4.3")] + get_argument_count_func: None, } } @@ -105,7 +112,7 @@ impl Callable { }, }; - let info = sys::GDExtensionCallableCustomInfo { + let info = CallableCustomInfo { callable_userdata: Box::into_raw(Box::new(userdata)) as *mut std::ffi::c_void, call_func: Some(rust_callable_call_fn::), free_func: Some(rust_callable_destroy::>), @@ -126,7 +133,7 @@ impl Callable { // - a type-erased workaround for PartialEq supertrait (which has a `Self` type parameter and thus is not object-safe) let userdata = CallableUserdata { inner: callable }; - let info = sys::GDExtensionCallableCustomInfo { + let info = CallableCustomInfo { callable_userdata: Box::into_raw(Box::new(userdata)) as *mut std::ffi::c_void, call_func: Some(rust_callable_call_custom::), free_func: Some(rust_callable_destroy::), @@ -140,11 +147,18 @@ impl Callable { } #[cfg(since_api = "4.2")] - fn from_custom_info(mut info: sys::GDExtensionCallableCustomInfo) -> Callable { + fn from_custom_info(mut info: CallableCustomInfo) -> Callable { // SAFETY: callable_custom_create() is a valid way of creating callables. unsafe { Callable::new_with_uninit(|type_ptr| { - sys::interface_fn!(callable_custom_create)(type_ptr, ptr::addr_of_mut!(info)) + #[cfg(before_api = "4.3")] + { + sys::interface_fn!(callable_custom_create)(type_ptr, ptr::addr_of_mut!(info)) + } + #[cfg(since_api = "4.3")] + { + sys::interface_fn!(callable_custom_create2)(type_ptr, ptr::addr_of_mut!(info)) + } }) } } From b9d5318c51ce8f7406bde12e6da2019b8b66076e Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Sat, 23 Nov 2024 17:06:33 +0100 Subject: [PATCH 2/2] cargo-deny: allow 'Unicode-3.0' license --- .github/other/deny.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/other/deny.toml b/.github/other/deny.toml index ce6054fc3..c4474efdf 100644 --- a/.github/other/deny.toml +++ b/.github/other/deny.toml @@ -104,6 +104,7 @@ allow = [ "BSD-3-Clause", "ISC", "Unicode-DFS-2016", + "Unicode-3.0", # unicode-ident "MPL-2.0", #"Apache-2.0 WITH LLVM-exception", ]