Skip to content

Commit

Permalink
- Cleanup docs in rawgd/gd
Browse files Browse the repository at this point in the history
- Other cleanup
  • Loading branch information
lilizoey committed Oct 2, 2023
1 parent 2449468 commit 7f47fcc
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 423 deletions.
9 changes: 3 additions & 6 deletions godot-core/src/builtin/callable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use godot_ffi as sys;

use crate::builtin::meta::{ToGodot, impl_godot_as_self, GodotType};
use crate::builtin::meta::{impl_godot_as_self, GodotType, ToGodot};
use crate::builtin::{inner, StringName, Variant, VariantArray};
use crate::engine::Object;
use crate::obj::mem::Memory;
Expand Down Expand Up @@ -46,7 +46,8 @@ impl Callable {
unsafe {
sys::from_sys_init_or_init_default::<Self>(|self_ptr| {
let ctor = sys::builtin_fn!(callable_from_object_method);
let args = [object.to_ffi().as_arg_ptr(), method.sys_const()];
let raw = object.to_ffi();
let args = [raw.as_arg_ptr(), method.sys_const()];
ctor(self_ptr, args.as_ptr());
})
}
Expand Down Expand Up @@ -284,13 +285,9 @@ unsafe impl GodotFfi for Callable {
}
}

<<<<<<< HEAD
impl_godot_as_self!(Callable);

impl std::fmt::Debug for Callable {
=======
impl fmt::Debug for Callable {
>>>>>>> c3e702329fc22e87254a732b2deeb4487c4faa6a
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let method = self.method_name();
let object = self.object();
Expand Down
12 changes: 6 additions & 6 deletions godot-core/src/builtin/meta/godot_compat/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ where
}

impl GodotCompatible for sys::VariantType {
type Via = i64;
type Via = i32;
}

impl ToGodot for sys::VariantType {
fn to_godot(&self) -> Self::Via {
*self as i64
*self as i32
}

fn into_godot(self) -> Self::Via {
self as i64
self as i32
}
}

Expand All @@ -65,16 +65,16 @@ impl FromGodot for sys::VariantType {
}

impl GodotCompatible for sys::VariantOperator {
type Via = i64;
type Via = i32;
}

impl ToGodot for sys::VariantOperator {
fn to_godot(&self) -> Self::Via {
*self as i64
*self as i32
}

fn into_godot(self) -> Self::Via {
self as i64
self as i32
}
}

Expand Down
5 changes: 0 additions & 5 deletions godot-core/src/builtin/meta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,6 @@ where
}
}

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

/// Rusty abstraction of `sys::GDExtensionPropertyInfo`.
Expand Down
8 changes: 3 additions & 5 deletions godot-core/src/builtin/meta/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ macro_rules! impl_varcall_signature_for_tuple {
$R:ident
$(, ($pn:ident, $n:tt) : $Pn:ident)* // $n cannot be literal if substituted as tuple index .0
) => {
// R: FromVariantIndirect, Pn: ToVariant -> when calling engine APIs
// R: ToVariant, Pn:
#[allow(unused_variables)]
impl<$R, $($Pn,)*> VarcallSignatureTuple for ($R, $($Pn,)*)
where
Expand Down Expand Up @@ -181,7 +179,7 @@ macro_rules! impl_varcall_signature_for_tuple {

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

let class_fn = sys::interface_fn!(object_method_bind_call);
Expand Down Expand Up @@ -292,7 +290,7 @@ macro_rules! impl_ptrcall_signature_for_tuple {
) -> Self::Ret {
// $crate::out!("out_class_ptrcall: {method_name}");
if let Some(instance_id) = maybe_instance_id {
crate::engine::ensure_object_alive(instance_id, object_ptr, method_name);
crate::engine::ensure_object_alive(Some(instance_id), object_ptr, method_name).unwrap();
}

let class_fn = sys::interface_fn!(object_method_bind_ptrcall);
Expand Down Expand Up @@ -402,7 +400,7 @@ unsafe fn varcall_return<R: ToGodot>(
/// # Safety
/// See [`varcall_return`].
#[cfg(since_api = "4.2")] // unused before
pub(crate) unsafe fn varcall_return_checked<R: ToVariant>(
pub(crate) unsafe fn varcall_return_checked<R: ToGodot>(
ret_val: Result<R, ()>, // TODO Err should be custom CallError enum
ret: sys::GDExtensionVariantPtr,
err: *mut sys::GDExtensionCallError,
Expand Down
2 changes: 0 additions & 2 deletions godot-core/src/builtin/string/string_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ use std::fmt;
use crate::builtin::meta::impl_godot_as_self;
use crate::builtin::{inner, GodotString, NodePath};

use std::fmt;

/// A string optimized for unique names.
///
/// StringNames are immutable strings designed for representing unique names. StringName ensures that only
Expand Down
18 changes: 9 additions & 9 deletions godot-core/src/builtin/vectors/vector_axis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ impl EngineEnum for Vector2Axis {
}

impl GodotCompatible for Vector2Axis {
type Via = i64;
type Via = i32;
}

impl ToGodot for Vector2Axis {
fn to_godot(&self) -> Self::Via {
self.ord() as i64
self.ord()
}
}

impl FromGodot for Vector2Axis {
fn try_from_godot(via: Self::Via) -> Option<Self> {
Self::try_from_ord(via as i32)
Self::try_from_ord(via)
}
}

Expand Down Expand Up @@ -146,18 +146,18 @@ impl EngineEnum for Vector3Axis {
}

impl GodotCompatible for Vector3Axis {
type Via = i64;
type Via = i32;
}

impl ToGodot for Vector3Axis {
fn to_godot(&self) -> Self::Via {
self.ord() as i64
self.ord()
}
}

impl FromGodot for Vector3Axis {
fn try_from_godot(via: Self::Via) -> Option<Self> {
Self::try_from_ord(via as i32)
Self::try_from_ord(via)
}
}

Expand Down Expand Up @@ -197,18 +197,18 @@ impl EngineEnum for Vector4Axis {
}

impl GodotCompatible for Vector4Axis {
type Via = i64;
type Via = i32;
}

impl ToGodot for Vector4Axis {
fn to_godot(&self) -> Self::Via {
self.ord() as i64
self.ord()
}
}

impl FromGodot for Vector4Axis {
fn try_from_godot(via: Self::Via) -> Option<Self> {
Self::try_from_ord(via as i32)
Self::try_from_ord(via)
}
}

Expand Down
28 changes: 16 additions & 12 deletions godot-core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

//! Godot engine classes and methods.
use godot_ffi::GodotNullableFfi;

// Re-exports of generated symbols
use crate::builtin::{GodotString, NodePath};
use crate::obj::dom::EngineDomain;
Expand Down Expand Up @@ -218,23 +216,29 @@ pub(crate) fn object_ptr_from_id(instance_id: InstanceId) -> sys::GDExtensionObj
}

pub(crate) fn ensure_object_alive(
instance_id: InstanceId,
instance_id: Option<InstanceId>,
old_object_ptr: sys::GDExtensionObjectPtr,
method_name: &'static str,
) {
) -> Result<(), String> {
let Some(instance_id) = instance_id else {
return Err(format!("{method_name}: cannot call method on null object"));
};

let new_object_ptr = object_ptr_from_id(instance_id);

assert!(
!new_object_ptr.is_null(),
"{method_name}: access to instance with ID {instance_id} after it has been freed"
);
if new_object_ptr.is_null() {
return Err(format!(
"{method_name}: access to instance with ID {instance_id} after it has been freed"
));
}

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

Ok(())
}

// ----------------------------------------------------------------------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 7f47fcc

Please sign in to comment.