55 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
66 */
77
8- #[ cfg( safeguards_at_least = "strict" ) ]
8+ #[ cfg( safeguards_strict ) ]
99use std:: cell:: Cell ;
1010use std:: cell:: RefCell ;
1111use std:: collections:: hash_map:: Entry ;
1212use std:: collections:: HashMap ;
1313use std:: fmt:: { Debug , Display , Formatter , Result as FmtResult } ;
1414use std:: mem:: ManuallyDrop ;
15+ #[ cfg( safeguards_strict) ]
1516use std:: rc:: Rc ;
1617
1718use crate :: builtin:: Callable ;
@@ -27,7 +28,7 @@ thread_local! {
2728}
2829
2930/// Represents the initialization state of a `Base<T>` object.
30- #[ cfg( safeguards_at_least = "strict" ) ]
31+ #[ cfg( safeguards_strict ) ]
3132#[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
3233enum InitState {
3334 /// Object is being constructed (inside `I*::init()` or `Gd::from_init_fn()`).
@@ -38,14 +39,14 @@ enum InitState {
3839 Script ,
3940}
4041
41- #[ cfg( safeguards_at_least = "strict" ) ]
42+ #[ cfg( safeguards_strict ) ]
4243macro_rules! base_from_obj {
4344 ( $obj: expr, $state: expr) => {
4445 Base :: from_obj( $obj, $state)
4546 } ;
4647}
4748
48- #[ cfg( not( safeguards_at_least = "strict" ) ) ]
49+ #[ cfg( not( safeguards_strict ) ) ]
4950macro_rules! base_from_obj {
5051 ( $obj: expr, $state: expr) => {
5152 Base :: from_obj( $obj)
@@ -82,7 +83,7 @@ pub struct Base<T: GodotClass> {
8283 /// Tracks the initialization state of this `Base<T>` in Debug mode.
8384 ///
8485 /// Rc allows to "copy-construct" the base from an existing one, while still affecting the user-instance through the original `Base<T>`.
85- #[ cfg( safeguards_at_least = "strict" ) ]
86+ #[ cfg( safeguards_strict ) ]
8687 init_state : Rc < Cell < InitState > > ,
8788}
8889
@@ -95,14 +96,14 @@ impl<T: GodotClass> Base<T> {
9596 /// `base` must be alive at the time of invocation, i.e. user `init()` (which could technically destroy it) must not have run yet.
9697 /// If `base` is destroyed while the returned `Base<T>` is in use, that constitutes a logic error, not a safety issue.
9798 pub ( crate ) unsafe fn from_base ( base : & Base < T > ) -> Base < T > {
98- #[ cfg( safeguards_at_least = "strict" ) ]
99+ #[ cfg( safeguards_strict ) ]
99100 assert ! ( base. obj. is_instance_valid( ) ) ;
100101
101102 let obj = Gd :: from_obj_sys_weak ( base. obj . obj_sys ( ) ) ;
102103
103104 Self {
104105 obj : ManuallyDrop :: new ( obj) ,
105- #[ cfg( safeguards_at_least = "strict" ) ]
106+ #[ cfg( safeguards_strict ) ]
106107 init_state : Rc :: clone ( & base. init_state ) ,
107108 }
108109 }
@@ -115,7 +116,7 @@ impl<T: GodotClass> Base<T> {
115116 /// `gd` must be alive at the time of invocation. If it is destroyed while the returned `Base<T>` is in use, that constitutes a logic
116117 /// error, not a safety issue.
117118 pub ( crate ) unsafe fn from_script_gd ( gd : & Gd < T > ) -> Self {
118- #[ cfg( safeguards_at_least = "strict" ) ]
119+ #[ cfg( safeguards_strict ) ]
119120 assert ! ( gd. is_instance_valid( ) ) ;
120121
121122 let obj = Gd :: from_obj_sys_weak ( gd. obj_sys ( ) ) ;
@@ -143,15 +144,15 @@ impl<T: GodotClass> Base<T> {
143144 base_from_obj ! ( obj, InitState :: ObjectConstructing )
144145 }
145146
146- #[ cfg( safeguards_at_least = "strict" ) ]
147+ #[ cfg( safeguards_strict ) ]
147148 fn from_obj ( obj : Gd < T > , init_state : InitState ) -> Self {
148149 Self {
149150 obj : ManuallyDrop :: new ( obj) ,
150151 init_state : Rc :: new ( Cell :: new ( init_state) ) ,
151152 }
152153 }
153154
154- #[ cfg( not( safeguards_at_least = "strict" ) ) ]
155+ #[ cfg( not( safeguards_strict ) ) ]
155156 fn from_obj ( obj : Gd < T > ) -> Self {
156157 Self {
157158 obj : ManuallyDrop :: new ( obj) ,
@@ -178,7 +179,7 @@ impl<T: GodotClass> Base<T> {
178179 /// # Panics (Debug)
179180 /// If called outside an initialization function, or for ref-counted objects on a non-main thread.
180181 pub fn to_init_gd ( & self ) -> Gd < T > {
181- #[ cfg( safeguards_at_least = "strict" ) ] // debug_assert! still checks existence of symbols.
182+ #[ cfg( safeguards_strict ) ] // debug_assert! still checks existence of symbols.
182183 assert ! (
183184 self . is_initializing( ) ,
184185 "Base::to_init_gd() can only be called during object initialization, inside I*::init() or Gd::from_init_fn()"
@@ -250,7 +251,7 @@ impl<T: GodotClass> Base<T> {
250251
251252 /// Finalizes the initialization of this `Base<T>` and returns whether
252253 pub ( crate ) fn mark_initialized ( & mut self ) {
253- #[ cfg( safeguards_at_least = "strict" ) ]
254+ #[ cfg( safeguards_strict ) ]
254255 {
255256 assert_eq ! (
256257 self . init_state. get( ) ,
@@ -267,7 +268,7 @@ impl<T: GodotClass> Base<T> {
267268 /// Returns a [`Gd`] referencing the base object, assuming the derived object is fully constructed.
268269 #[ doc( hidden) ]
269270 pub fn __fully_constructed_gd ( & self ) -> Gd < T > {
270- #[ cfg( safeguards_at_least = "strict" ) ] // debug_assert! still checks existence of symbols.
271+ #[ cfg( safeguards_strict ) ] // debug_assert! still checks existence of symbols.
271272 assert ! (
272273 !self . is_initializing( ) ,
273274 "WithBaseField::to_gd(), base(), base_mut() can only be called on fully-constructed objects, after I*::init() or Gd::from_init_fn()"
@@ -298,7 +299,7 @@ impl<T: GodotClass> Base<T> {
298299
299300 /// Returns a passive reference to the base object, for use in script contexts only.
300301 pub ( crate ) fn to_script_passive ( & self ) -> PassiveGd < T > {
301- #[ cfg( safeguards_at_least = "strict" ) ]
302+ #[ cfg( safeguards_strict ) ]
302303 assert_eq ! (
303304 self . init_state. get( ) ,
304305 InitState :: Script ,
@@ -310,15 +311,15 @@ impl<T: GodotClass> Base<T> {
310311 }
311312
312313 /// Returns `true` if this `Base<T>` is currently in the initializing state.
313- #[ cfg( safeguards_at_least = "strict" ) ]
314+ #[ cfg( safeguards_strict ) ]
314315 fn is_initializing ( & self ) -> bool {
315316 self . init_state . get ( ) == InitState :: ObjectConstructing
316317 }
317318
318319 /// Returns a [`Gd`] referencing the base object, assuming the derived object is fully constructed.
319320 #[ doc( hidden) ]
320321 pub fn __constructed_gd ( & self ) -> Gd < T > {
321- #[ cfg( safeguards_at_least = "strict" ) ] // debug_assert! still checks existence of symbols.
322+ #[ cfg( safeguards_strict ) ] // debug_assert! still checks existence of symbols.
322323 assert ! (
323324 !self . is_initializing( ) ,
324325 "WithBaseField::to_gd(), base(), base_mut() can only be called on fully-constructed objects, after I*::init() or Gd::from_init_fn()"
@@ -335,7 +336,7 @@ impl<T: GodotClass> Base<T> {
335336 /// # Safety
336337 /// Caller must ensure that the underlying object remains valid for the entire lifetime of the returned `PassiveGd`.
337338 pub ( crate ) unsafe fn constructed_passive ( & self ) -> PassiveGd < T > {
338- #[ cfg( safeguards_at_least = "strict" ) ] // debug_assert! still checks existence of symbols.
339+ #[ cfg( safeguards_strict ) ] // debug_assert! still checks existence of symbols.
339340 assert ! (
340341 !self . is_initializing( ) ,
341342 "WithBaseField::base(), base_mut() can only be called on fully-constructed objects, after I*::init() or Gd::from_init_fn()"
0 commit comments