Skip to content

Commit c82104f

Browse files
committed
Update runtime_version to use non-deprecated get_godot_version pointer.
1 parent 69c346e commit c82104f

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

godot-ffi/src/interface_init.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn ensure_static_runtime_compatibility(
7171
let minor = unsafe { data_ptr.offset(1).read() };
7272
if minor == 0 {
7373
// SAFETY: at this point it's reasonably safe to say that we are indeed dealing with that version struct; read the whole.
74-
let data_ptr = get_proc_address as *const sys::GDExtensionGodotVersion;
74+
let data_ptr = get_proc_address as *const sys::GodotSysVersion;
7575
let runtime_version_str = unsafe { read_version_string(&data_ptr.read()) };
7676

7777
panic!(
@@ -114,7 +114,7 @@ pub fn ensure_static_runtime_compatibility(
114114

115115
pub unsafe fn runtime_version(
116116
get_proc_address: sys::GDExtensionInterfaceGetProcAddress,
117-
) -> sys::GDExtensionGodotVersion {
117+
) -> sys::GodotSysVersion {
118118
let get_proc_address = get_proc_address.expect("get_proc_address unexpectedly null");
119119

120120
runtime_version_inner(get_proc_address)
@@ -125,17 +125,17 @@ unsafe fn runtime_version_inner(
125125
get_proc_address: unsafe extern "C" fn(
126126
*const std::ffi::c_char,
127127
) -> sys::GDExtensionInterfaceFunctionPtr,
128-
) -> sys::GDExtensionGodotVersion {
128+
) -> sys::GodotSysVersion {
129129
// SAFETY: `self.0` is a valid `get_proc_address` pointer.
130-
let get_godot_version = unsafe { get_proc_address(sys::c_str(b"get_godot_version\0")) }; //.expect("get_godot_version unexpectedly null");
130+
let get_godot_version = unsafe { get_proc_address(sys::c_str(sys::GET_GODOT_VERSION_SYS_STR)) }; //.expect("get_godot_version unexpectedly null");
131131

132-
// SAFETY: `sys::GDExtensionInterfaceGetGodotVersion` is an `Option` of an `unsafe extern "C"` function pointer.
132+
// SAFETY: `GDExtensionInterfaceGetGodotVersion` is an `Option` of an `unsafe extern "C"` function pointer.
133133
let get_godot_version =
134-
crate::unsafe_cast_fn_ptr!(get_godot_version as sys::GDExtensionInterfaceGetGodotVersion);
134+
crate::unsafe_cast_fn_ptr!(get_godot_version as sys::GetGodotSysVersion);
135135

136-
let mut version = std::mem::MaybeUninit::<sys::GDExtensionGodotVersion>::zeroed();
136+
let mut version = std::mem::MaybeUninit::<sys::GodotSysVersion>::zeroed();
137137

138-
// SAFETY: `get_proc_address` with "get_godot_version" does return a valid `sys::GDExtensionInterfaceGetGodotVersion` pointer, and since we have a valid
138+
// SAFETY: `get_proc_address` with "get_godot_version" does return a valid `GDExtensionInterfaceGetGodotVersion` pointer, and since we have a valid
139139
// `get_proc_address` pointer then it must be callable.
140140
unsafe { get_godot_version(version.as_mut_ptr()) };
141141

godot-ffi/src/lib.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,36 @@ use binding::{
111111
#[cfg(not(wasm_nothreads))]
112112
static MAIN_THREAD_ID: ManualInitCell<std::thread::ThreadId> = ManualInitCell::new();
113113

114+
#[cfg(before_api = "4.5")]
115+
mod version_symbols {
116+
117+
pub type GodotSysVersion = super::GDExtensionGodotVersion;
118+
pub type GetGodotSysVersion = super::GDExtensionInterfaceGetGodotVersion;
119+
pub const GET_GODOT_VERSION_SYS_STR: &[u8] = b"get_godot_version\0";
120+
}
121+
122+
#[cfg(since_api = "4.5")]
123+
mod version_symbols {
124+
pub type GodotSysVersion = super::GDExtensionGodotVersion2;
125+
126+
pub type GetGodotSysVersion = super::GDExtensionInterfaceGetGodotVersion2;
127+
pub const GET_GODOT_VERSION_SYS_STR: &[u8] = b"get_godot_version2\0";
128+
}
129+
130+
use version_symbols::*;
131+
114132
// ----------------------------------------------------------------------------------------------------------------------------------------------
115133

116134
pub struct GdextRuntimeMetadata {
117-
godot_version: GDExtensionGodotVersion,
135+
godot_version: GodotSysVersion,
118136
}
119137

120138
impl GdextRuntimeMetadata {
121139
/// # Safety
122140
///
123141
/// - The `string` field of `godot_version` must not be written to while this struct exists.
124142
/// - The `string` field of `godot_version` must be safe to read from while this struct exists.
125-
pub unsafe fn new(godot_version: GDExtensionGodotVersion) -> Self {
143+
pub unsafe fn new(godot_version: GodotSysVersion) -> Self {
126144
Self { godot_version }
127145
}
128146
}
@@ -264,7 +282,7 @@ fn safeguards_level_string() -> &'static str {
264282
}
265283
}
266284

267-
fn print_preamble(version: GDExtensionGodotVersion) {
285+
fn print_preamble(version: GodotSysVersion) {
268286
let api_version: &'static str = GdextBuild::godot_static_version_string();
269287
let runtime_version = read_version_string(&version);
270288
let safeguards_level = safeguards_level_string();

godot-ffi/src/toolbox.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ pub(crate) fn load_utility_function(
402402
})
403403
}
404404

405-
pub(crate) fn read_version_string(version_ptr: &sys::GDExtensionGodotVersion) -> String {
405+
pub(crate) fn read_version_string(version_ptr: &sys::GodotSysVersion) -> String {
406406
let char_ptr = version_ptr.string;
407407

408408
// SAFETY: GDExtensionGodotVersion has the (manually upheld) invariant of a valid string field.

0 commit comments

Comments
 (0)