Skip to content

Use GDExtensionCallableCustomInfo2 instead of deprecated GDExtensionCallableCustomInfo. #952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/other/deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down
26 changes: 20 additions & 6 deletions godot-core/src/builtin/callable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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::<F>),
free_func: Some(rust_callable_destroy::<FnWrapper<F>>),
Expand All @@ -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::<C>),
free_func: Some(rust_callable_destroy::<C>),
Expand All @@ -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))
}
})
}
}
Expand Down
Loading