Skip to content

Commit 31dbd8e

Browse files
committed
Remove unused Lifecycle::Dead, some logging
1 parent 4fe09b4 commit 31dbd8e

File tree

2 files changed

+23
-33
lines changed

2 files changed

+23
-33
lines changed

godot-core/src/storage.rs

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@ use crate::obj::GodotClass;
88
use crate::out;
99
use godot_ffi as sys;
1010

11-
use std::any::type_name;
12-
1311
#[derive(Copy, Clone, Debug)]
1412
pub enum Lifecycle {
1513
// Warning: when reordering/changing enumerators, update match in AtomicLifecycle below
1614
Alive,
1715
Destroying,
18-
Dead, // reading this would typically already be too late, only best-effort in case of UB
1916
}
2017

2118
#[cfg(not(feature = "experimental-threads"))]
@@ -123,7 +120,6 @@ mod single_threaded {
123120

124121
#[cfg(feature = "experimental-threads")]
125122
mod multi_threaded {
126-
use std::any::type_name;
127123
use std::sync;
128124
use std::sync::atomic::{AtomicU32, Ordering};
129125

@@ -146,14 +142,18 @@ mod multi_threaded {
146142
pub fn get(&self) -> Lifecycle {
147143
match self.atomic.load(Ordering::Relaxed) {
148144
0 => Lifecycle::Alive,
149-
1 => Lifecycle::Dead,
150-
2 => Lifecycle::Destroying,
151-
other => panic!("Invalid lifecycle {other}"),
145+
1 => Lifecycle::Destroying,
146+
other => panic!("invalid lifecycle {other}"),
152147
}
153148
}
154149

155-
pub fn set(&self, value: Lifecycle) {
156-
self.atomic.store(value as u32, Ordering::Relaxed);
150+
pub fn set(&self, lifecycle: Lifecycle) {
151+
let value = match lifecycle {
152+
Lifecycle::Alive => 0,
153+
Lifecycle::Destroying => 1,
154+
};
155+
156+
self.atomic.store(value, Ordering::Relaxed);
157157
}
158158
}
159159

@@ -170,7 +170,7 @@ mod multi_threaded {
170170
/// For all Godot extension classes
171171
impl<T: GodotClass> InstanceStorage<T> {
172172
pub fn construct(user_instance: T, base: Base<T::Base>) -> Self {
173-
out!(" Storage::construct <{}>", type_name::<T>());
173+
out!(" Storage::construct <{:?}>", base);
174174

175175
Self {
176176
user_instance: sync::RwLock::new(user_instance),
@@ -183,20 +183,18 @@ mod multi_threaded {
183183
pub(crate) fn on_inc_ref(&self) {
184184
self.godot_ref_count.fetch_add(1, Ordering::Relaxed);
185185
out!(
186-
" Storage::on_inc_ref (rc={}) <{}>", // -- {:?}",
186+
" Storage::on_inc_ref (rc={}) <{:?}>",
187187
self.godot_ref_count(),
188-
type_name::<T>(),
189-
//self.user_instance
188+
self.base,
190189
);
191190
}
192191

193192
pub(crate) fn on_dec_ref(&self) {
194193
self.godot_ref_count.fetch_sub(1, Ordering::Relaxed);
195194
out!(
196-
" | Storage::on_dec_ref (rc={}) <{}>", // -- {:?}",
195+
" | Storage::on_dec_ref (rc={}) <{:?}>",
197196
self.godot_ref_count(),
198-
type_name::<T>(),
199-
//self.user_instance
197+
self.base,
200198
);
201199
}
202200

@@ -208,21 +206,21 @@ mod multi_threaded {
208206
pub fn get(&self) -> sync::RwLockReadGuard<T> {
209207
self.read_ignoring_poison().unwrap_or_else(|| {
210208
panic!(
211-
"Gd<T>::bind() failed, already bound; T = {}.\n \
209+
"Gd<T>::bind() failed, already bound; obj = {}.\n \
212210
Make sure there is no &mut T live at the time.\n \
213211
This often occurs when calling a GDScript function/signal from Rust, which then calls again Rust code.",
214-
type_name::<T>()
212+
self.base,
215213
)
216214
})
217215
}
218216

219217
pub fn get_mut(&self) -> sync::RwLockWriteGuard<T> {
220218
self.write_ignoring_poison().unwrap_or_else(|| {
221219
panic!(
222-
"Gd<T>::bind_mut() failed, already bound; T = {}.\n \
220+
"Gd<T>::bind_mut() failed, already bound; obj = {}.\n \
223221
Make sure there is no &T or &mut T live at the time.\n \
224222
This often occurs when calling a GDScript function/signal from Rust, which then calls again Rust code.",
225-
type_name::<T>()
223+
self.base,
226224
)
227225
})
228226
}
@@ -311,27 +309,19 @@ impl<T: GodotClass> InstanceStorage<T> {
311309
self.lifecycle.get(),
312310
self.base,
313311
);
314-
matches!(
315-
self.lifecycle.get(),
316-
Lifecycle::Destroying | Lifecycle::Dead
317-
)
312+
matches!(self.lifecycle.get(), Lifecycle::Destroying)
318313
}
319314
}
320315

321316
impl<T: GodotClass> Drop for InstanceStorage<T> {
322317
fn drop(&mut self) {
323318
out!(
324-
" Storage::drop (rc={}) <{}>", // -- {:?}",
319+
" Storage::drop (rc={}) <{:?}>",
325320
self.godot_ref_count(),
326-
type_name::<T>(),
327-
//self.user_instance
321+
self.base,
328322
);
329323
//let _ = mem::take(&mut self.user_instance);
330-
out!(
331-
" Storage::drop end <{}>", // -- {:?}",
332-
type_name::<T>(),
333-
//self.user_instance
334-
);
324+
//out!(" Storage::drop end <{:?}>", self.base);
335325
}
336326
}
337327

itest/rust/src/register_tests/func_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl RefCountedVirtual for GdSelfReference {
235235

236236
#[cfg(all())]
237237
fn on_notification(&mut self, _: godot::engine::notify::ObjectNotification) {
238-
godot_print!("Hello!");
238+
// Do nothing.
239239
}
240240

241241
#[cfg(any())]

0 commit comments

Comments
 (0)