Skip to content

Commit ca9dea5

Browse files
committed
- Cleanup docs in rawgd/gd
- Other cleanup
1 parent 2449468 commit ca9dea5

File tree

11 files changed

+195
-422
lines changed

11 files changed

+195
-422
lines changed

godot-core/src/builtin/callable.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use godot_ffi as sys;
88

9-
use crate::builtin::meta::{ToGodot, impl_godot_as_self, GodotType};
9+
use crate::builtin::meta::{impl_godot_as_self, GodotType, ToGodot};
1010
use crate::builtin::{inner, StringName, Variant, VariantArray};
1111
use crate::engine::Object;
1212
use crate::obj::mem::Memory;
@@ -284,13 +284,9 @@ unsafe impl GodotFfi for Callable {
284284
}
285285
}
286286

287-
<<<<<<< HEAD
288287
impl_godot_as_self!(Callable);
289288

290-
impl std::fmt::Debug for Callable {
291-
=======
292289
impl fmt::Debug for Callable {
293-
>>>>>>> c3e702329fc22e87254a732b2deeb4487c4faa6a
294290
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
295291
let method = self.method_name();
296292
let object = self.object();

godot-core/src/builtin/meta/godot_compat/impls.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ where
4545
}
4646

4747
impl GodotCompatible for sys::VariantType {
48-
type Via = i64;
48+
type Via = i32;
4949
}
5050

5151
impl ToGodot for sys::VariantType {
5252
fn to_godot(&self) -> Self::Via {
53-
*self as i64
53+
*self as i32
5454
}
5555

5656
fn into_godot(self) -> Self::Via {
57-
self as i64
57+
self as i32
5858
}
5959
}
6060

@@ -65,16 +65,16 @@ impl FromGodot for sys::VariantType {
6565
}
6666

6767
impl GodotCompatible for sys::VariantOperator {
68-
type Via = i64;
68+
type Via = i32;
6969
}
7070

7171
impl ToGodot for sys::VariantOperator {
7272
fn to_godot(&self) -> Self::Via {
73-
*self as i64
73+
*self as i32
7474
}
7575

7676
fn into_godot(self) -> Self::Via {
77-
self as i64
77+
self as i32
7878
}
7979
}
8080

godot-core/src/builtin/meta/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,6 @@ where
183183
}
184184
}
185185

186-
/// Stores meta-information about registered types or properties.
187-
///
188-
/// Filling this information properly is important so that Godot can use ptrcalls instead of varcalls
189-
/// (requires typed GDScript + sufficient information from the extension side)
190-
191186
// ----------------------------------------------------------------------------------------------------------------------------------------------
192187

193188
/// Rusty abstraction of `sys::GDExtensionPropertyInfo`.

godot-core/src/builtin/meta/signature.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ macro_rules! impl_varcall_signature_for_tuple {
114114
$R:ident
115115
$(, ($pn:ident, $n:tt) : $Pn:ident)* // $n cannot be literal if substituted as tuple index .0
116116
) => {
117-
// R: FromVariantIndirect, Pn: ToVariant -> when calling engine APIs
118-
// R: ToVariant, Pn:
119117
#[allow(unused_variables)]
120118
impl<$R, $($Pn,)*> VarcallSignatureTuple for ($R, $($Pn,)*)
121119
where
@@ -181,7 +179,7 @@ macro_rules! impl_varcall_signature_for_tuple {
181179

182180
// Note: varcalls are not safe from failing, if the happen through an object pointer -> validity check necessary.
183181
if let Some(instance_id) = maybe_instance_id {
184-
crate::engine::ensure_object_alive(instance_id, object_ptr, method_name);
182+
crate::engine::ensure_object_alive(Some(instance_id), object_ptr, method_name).unwrap();
185183
}
186184

187185
let class_fn = sys::interface_fn!(object_method_bind_call);
@@ -292,7 +290,7 @@ macro_rules! impl_ptrcall_signature_for_tuple {
292290
) -> Self::Ret {
293291
// $crate::out!("out_class_ptrcall: {method_name}");
294292
if let Some(instance_id) = maybe_instance_id {
295-
crate::engine::ensure_object_alive(instance_id, object_ptr, method_name);
293+
crate::engine::ensure_object_alive(Some(instance_id), object_ptr, method_name).unwrap();
296294
}
297295

298296
let class_fn = sys::interface_fn!(object_method_bind_ptrcall);
@@ -402,7 +400,7 @@ unsafe fn varcall_return<R: ToGodot>(
402400
/// # Safety
403401
/// See [`varcall_return`].
404402
#[cfg(since_api = "4.2")] // unused before
405-
pub(crate) unsafe fn varcall_return_checked<R: ToVariant>(
403+
pub(crate) unsafe fn varcall_return_checked<R: ToGodot>(
406404
ret_val: Result<R, ()>, // TODO Err should be custom CallError enum
407405
ret: sys::GDExtensionVariantPtr,
408406
err: *mut sys::GDExtensionCallError,

godot-core/src/builtin/string/string_name.rs

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ use std::fmt;
1212
use crate::builtin::meta::impl_godot_as_self;
1313
use crate::builtin::{inner, GodotString, NodePath};
1414

15-
use std::fmt;
16-
1715
/// A string optimized for unique names.
1816
///
1917
/// StringNames are immutable strings designed for representing unique names. StringName ensures that only

godot-core/src/builtin/vectors/vector_axis.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,18 @@ impl EngineEnum for Vector2Axis {
9898
}
9999

100100
impl GodotCompatible for Vector2Axis {
101-
type Via = i64;
101+
type Via = i32;
102102
}
103103

104104
impl ToGodot for Vector2Axis {
105105
fn to_godot(&self) -> Self::Via {
106-
self.ord() as i64
106+
self.ord()
107107
}
108108
}
109109

110110
impl FromGodot for Vector2Axis {
111111
fn try_from_godot(via: Self::Via) -> Option<Self> {
112-
Self::try_from_ord(via as i32)
112+
Self::try_from_ord(via)
113113
}
114114
}
115115

@@ -146,18 +146,18 @@ impl EngineEnum for Vector3Axis {
146146
}
147147

148148
impl GodotCompatible for Vector3Axis {
149-
type Via = i64;
149+
type Via = i32;
150150
}
151151

152152
impl ToGodot for Vector3Axis {
153153
fn to_godot(&self) -> Self::Via {
154-
self.ord() as i64
154+
self.ord()
155155
}
156156
}
157157

158158
impl FromGodot for Vector3Axis {
159159
fn try_from_godot(via: Self::Via) -> Option<Self> {
160-
Self::try_from_ord(via as i32)
160+
Self::try_from_ord(via)
161161
}
162162
}
163163

@@ -197,18 +197,18 @@ impl EngineEnum for Vector4Axis {
197197
}
198198

199199
impl GodotCompatible for Vector4Axis {
200-
type Via = i64;
200+
type Via = i32;
201201
}
202202

203203
impl ToGodot for Vector4Axis {
204204
fn to_godot(&self) -> Self::Via {
205-
self.ord() as i64
205+
self.ord()
206206
}
207207
}
208208

209209
impl FromGodot for Vector4Axis {
210210
fn try_from_godot(via: Self::Via) -> Option<Self> {
211-
Self::try_from_ord(via as i32)
211+
Self::try_from_ord(via)
212212
}
213213
}
214214

godot-core/src/engine.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
//! Godot engine classes and methods.
88
9-
use godot_ffi::GodotNullableFfi;
10-
119
// Re-exports of generated symbols
1210
use crate::builtin::{GodotString, NodePath};
1311
use crate::obj::dom::EngineDomain;
@@ -218,23 +216,29 @@ pub(crate) fn object_ptr_from_id(instance_id: InstanceId) -> sys::GDExtensionObj
218216
}
219217

220218
pub(crate) fn ensure_object_alive(
221-
instance_id: InstanceId,
219+
instance_id: Option<InstanceId>,
222220
old_object_ptr: sys::GDExtensionObjectPtr,
223221
method_name: &'static str,
224-
) {
222+
) -> Result<(), String> {
223+
let Some(instance_id) = instance_id else {
224+
return Err(format!("{method_name}: cannot call method on null object"));
225+
};
226+
225227
let new_object_ptr = object_ptr_from_id(instance_id);
226228

227-
assert!(
228-
!new_object_ptr.is_null(),
229-
"{method_name}: access to instance with ID {instance_id} after it has been freed"
230-
);
229+
if new_object_ptr.is_null() {
230+
return Err(format!(
231+
"{method_name}: access to instance with ID {instance_id} after it has been freed"
232+
));
233+
}
231234

232235
// This should not happen, as reuse of instance IDs was fixed according to https://github.com/godotengine/godot/issues/32383,
233236
// namely in PR https://github.com/godotengine/godot/pull/36189. Double-check to make sure.
234-
assert_eq!(
235-
new_object_ptr, old_object_ptr,
236-
"{method_name}: instance ID {instance_id} points to a stale, reused object. Please report this to gdext maintainers."
237-
);
237+
if new_object_ptr != old_object_ptr {
238+
return Err(format!("{method_name}: instance ID {instance_id} points to a stale, reused object. Please report this to gdext maintainers."));
239+
}
240+
241+
Ok(())
238242
}
239243

240244
// ----------------------------------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)