@@ -8,14 +8,11 @@ use crate::obj::GodotClass;
8
8
use crate :: out;
9
9
use godot_ffi as sys;
10
10
11
- use std:: any:: type_name;
12
-
13
11
#[ derive( Copy , Clone , Debug ) ]
14
12
pub enum Lifecycle {
15
13
// Warning: when reordering/changing enumerators, update match in AtomicLifecycle below
16
14
Alive ,
17
15
Destroying ,
18
- Dead , // reading this would typically already be too late, only best-effort in case of UB
19
16
}
20
17
21
18
#[ cfg( not( feature = "experimental-threads" ) ) ]
@@ -123,7 +120,6 @@ mod single_threaded {
123
120
124
121
#[ cfg( feature = "experimental-threads" ) ]
125
122
mod multi_threaded {
126
- use std:: any:: type_name;
127
123
use std:: sync;
128
124
use std:: sync:: atomic:: { AtomicU32 , Ordering } ;
129
125
@@ -146,14 +142,18 @@ mod multi_threaded {
146
142
pub fn get ( & self ) -> Lifecycle {
147
143
match self . atomic . load ( Ordering :: Relaxed ) {
148
144
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}" ) ,
152
147
}
153
148
}
154
149
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 ) ;
157
157
}
158
158
}
159
159
@@ -170,7 +170,7 @@ mod multi_threaded {
170
170
/// For all Godot extension classes
171
171
impl < T : GodotClass > InstanceStorage < T > {
172
172
pub fn construct ( user_instance : T , base : Base < T :: Base > ) -> Self {
173
- out ! ( " Storage::construct <{}>" , type_name :: < T > ( ) ) ;
173
+ out ! ( " Storage::construct <{:? }>" , base ) ;
174
174
175
175
Self {
176
176
user_instance : sync:: RwLock :: new ( user_instance) ,
@@ -183,20 +183,18 @@ mod multi_threaded {
183
183
pub ( crate ) fn on_inc_ref ( & self ) {
184
184
self . godot_ref_count . fetch_add ( 1 , Ordering :: Relaxed ) ;
185
185
out ! (
186
- " Storage::on_inc_ref (rc={}) <{}>" , // -- { :?}",
186
+ " Storage::on_inc_ref (rc={}) <{:?}> " ,
187
187
self . godot_ref_count( ) ,
188
- type_name:: <T >( ) ,
189
- //self.user_instance
188
+ self . base,
190
189
) ;
191
190
}
192
191
193
192
pub ( crate ) fn on_dec_ref ( & self ) {
194
193
self . godot_ref_count . fetch_sub ( 1 , Ordering :: Relaxed ) ;
195
194
out ! (
196
- " | Storage::on_dec_ref (rc={}) <{}>" , // -- { :?}",
195
+ " | Storage::on_dec_ref (rc={}) <{:?}> " ,
197
196
self . godot_ref_count( ) ,
198
- type_name:: <T >( ) ,
199
- //self.user_instance
197
+ self . base,
200
198
) ;
201
199
}
202
200
@@ -208,21 +206,21 @@ mod multi_threaded {
208
206
pub fn get ( & self ) -> sync:: RwLockReadGuard < T > {
209
207
self . read_ignoring_poison ( ) . unwrap_or_else ( || {
210
208
panic ! (
211
- "Gd<T>::bind() failed, already bound; T = {}.\n \
209
+ "Gd<T>::bind() failed, already bound; obj = {}.\n \
212
210
Make sure there is no &mut T live at the time.\n \
213
211
This often occurs when calling a GDScript function/signal from Rust, which then calls again Rust code.",
214
- type_name :: < T > ( )
212
+ self . base ,
215
213
)
216
214
} )
217
215
}
218
216
219
217
pub fn get_mut ( & self ) -> sync:: RwLockWriteGuard < T > {
220
218
self . write_ignoring_poison ( ) . unwrap_or_else ( || {
221
219
panic ! (
222
- "Gd<T>::bind_mut() failed, already bound; T = {}.\n \
220
+ "Gd<T>::bind_mut() failed, already bound; obj = {}.\n \
223
221
Make sure there is no &T or &mut T live at the time.\n \
224
222
This often occurs when calling a GDScript function/signal from Rust, which then calls again Rust code.",
225
- type_name :: < T > ( )
223
+ self . base ,
226
224
)
227
225
} )
228
226
}
@@ -311,27 +309,19 @@ impl<T: GodotClass> InstanceStorage<T> {
311
309
self . lifecycle. get( ) ,
312
310
self . base,
313
311
) ;
314
- matches ! (
315
- self . lifecycle. get( ) ,
316
- Lifecycle :: Destroying | Lifecycle :: Dead
317
- )
312
+ matches ! ( self . lifecycle. get( ) , Lifecycle :: Destroying )
318
313
}
319
314
}
320
315
321
316
impl < T : GodotClass > Drop for InstanceStorage < T > {
322
317
fn drop ( & mut self ) {
323
318
out ! (
324
- " Storage::drop (rc={}) <{}>" , // -- { :?}",
319
+ " Storage::drop (rc={}) <{:?}> " ,
325
320
self . godot_ref_count( ) ,
326
- type_name:: <T >( ) ,
327
- //self.user_instance
321
+ self . base,
328
322
) ;
329
323
//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);
335
325
}
336
326
}
337
327
0 commit comments