@@ -162,10 +162,12 @@ impl Callable {
162162        F :  ' static  + FnMut ( & [ & Variant ] )  -> R , 
163163        S :  meta:: AsArg < GString > , 
164164    { 
165+         #[ cfg( debug_assertions) ]  
165166        meta:: arg_into_owned!( name) ; 
166167
167168        Self :: from_fn_wrapper :: < F ,  R > ( FnWrapper  { 
168169            rust_function, 
170+             #[ cfg( debug_assertions) ]  
169171            name, 
170172            thread_id :  Some ( std:: thread:: current ( ) . id ( ) ) , 
171173            linked_obj_id :  None , 
@@ -187,10 +189,12 @@ impl Callable {
187189        F :  ' static  + FnMut ( & [ & Variant ] )  -> R , 
188190        S :  meta:: AsArg < GString > , 
189191    { 
192+         #[ cfg( debug_assertions) ]  
190193        meta:: arg_into_owned!( name) ; 
191194
192195        Self :: from_fn_wrapper :: < F ,  R > ( FnWrapper  { 
193196            rust_function, 
197+             #[ cfg( debug_assertions) ]  
194198            name, 
195199            thread_id :  Some ( std:: thread:: current ( ) . id ( ) ) , 
196200            linked_obj_id :  Some ( linked_object. instance_id ( ) ) , 
@@ -254,10 +258,12 @@ impl Callable {
254258        F :  FnMut ( & [ & Variant ] )  -> Variant , 
255259        Fc :  FnOnce ( & Callable )  -> R , 
256260    { 
261+         #[ cfg( debug_assertions) ]  
257262        meta:: arg_into_owned!( name) ; 
258263
259264        let  callable = Self :: from_fn_wrapper :: < F ,  Variant > ( FnWrapper  { 
260265            rust_function, 
266+             #[ cfg( debug_assertions) ]  
261267            name, 
262268            thread_id :  Some ( std:: thread:: current ( ) . id ( ) ) , 
263269            linked_obj_id :  None , 
@@ -292,10 +298,12 @@ impl Callable {
292298        F :  ' static  + Send  + Sync  + FnMut ( & [ & Variant ] )  -> R , 
293299        S :  meta:: AsArg < GString > , 
294300    { 
301+         #[ cfg( debug_assertions) ]  
295302        meta:: arg_into_owned!( name) ; 
296303
297304        Self :: from_fn_wrapper :: < F ,  R > ( FnWrapper  { 
298305            rust_function, 
306+             #[ cfg( debug_assertions) ]  
299307            name, 
300308            thread_id :  None , 
301309            linked_obj_id :  None , 
@@ -340,6 +348,7 @@ impl Callable {
340348            callable_userdata :  Box :: into_raw ( Box :: new ( userdata) )  as  * mut  std:: ffi:: c_void , 
341349            call_func :  Some ( rust_callable_call_fn :: < F ,  R > ) , 
342350            free_func :  Some ( rust_callable_destroy :: < FnWrapper < F > > ) , 
351+             #[ cfg( debug_assertions) ]  
343352            to_string_func :  Some ( rust_callable_to_string_named :: < F > ) , 
344353            is_valid_func :  Some ( rust_callable_is_valid) , 
345354            ..Self :: default_callable_custom_info ( ) 
@@ -608,6 +617,7 @@ mod custom_callable {
608617
609618    pub ( crate )  struct  FnWrapper < F >  { 
610619        pub ( super )  rust_function :  F , 
620+         #[ cfg( debug_assertions) ]  
611621        pub ( super )  name :  GString , 
612622
613623        /// `None` if the callable is multi-threaded ([`Callable::from_sync_fn`]). 
@@ -658,11 +668,14 @@ mod custom_callable {
658668    )  { 
659669        let  arg_refs:  & [ & Variant ]  = Variant :: borrow_ref_slice ( p_args,  p_argument_count as  usize ) ; 
660670
661-         let  name = { 
671+         #[ cfg( debug_assertions) ]  
672+         let  name = & { 
662673            let  c:  & C  = CallableUserdata :: inner_from_raw ( callable_userdata) ; 
663674            c. to_string ( ) 
664675        } ; 
665-         let  ctx = meta:: CallContext :: custom_callable ( name. as_str ( ) ) ; 
676+         #[ cfg( not( debug_assertions) ) ]  
677+         let  name = "<optimized out>" ; 
678+         let  ctx = meta:: CallContext :: custom_callable ( name) ; 
666679
667680        crate :: private:: handle_varcall_panic ( & ctx,  & mut  * r_error,  move  || { 
668681            // Get the RustCallable again inside closure so it doesn't have to be UnwindSafe. 
@@ -685,11 +698,14 @@ mod custom_callable {
685698    { 
686699        let  arg_refs:  & [ & Variant ]  = Variant :: borrow_ref_slice ( p_args,  p_argument_count as  usize ) ; 
687700
688-         let  name = { 
701+         #[ cfg( debug_assertions) ]  
702+         let  name = & { 
689703            let  w:  & FnWrapper < F >  = CallableUserdata :: inner_from_raw ( callable_userdata) ; 
690704            w. name . to_string ( ) 
691705        } ; 
692-         let  ctx = meta:: CallContext :: custom_callable ( name. as_str ( ) ) ; 
706+         #[ cfg( not( debug_assertions) ) ]  
707+         let  name = "<optimized out>" ; 
708+         let  ctx = meta:: CallContext :: custom_callable ( name) ; 
693709
694710        crate :: private:: handle_varcall_panic ( & ctx,  & mut  * r_error,  move  || { 
695711            // Get the FnWrapper again inside closure so the FnMut doesn't have to be UnwindSafe. 
@@ -698,12 +714,16 @@ mod custom_callable {
698714            if  w. thread_id 
699715                . is_some_and ( |tid| tid != std:: thread:: current ( ) . id ( ) ) 
700716            { 
717+                 #[ cfg( debug_assertions) ]  
718+                 let  name = & w. name ; 
719+                 #[ cfg( not( debug_assertions) ) ]  
720+                 let  name = "<optimized out>" ; 
701721                // NOTE: this panic is currently not propagated to the caller, but results in an error message and Nil return. 
702722                // See comments in itest callable_call() for details. 
703723                panic ! ( 
704724                    "Callable '{}' created with from_fn() must be called from the same thread it was created in.\n \  
705725, 
706-                     w . name
726+                     name
707727                ) ; 
708728            } 
709729
@@ -749,6 +769,7 @@ mod custom_callable {
749769        * r_is_valid = sys:: conv:: SYS_TRUE ; 
750770    } 
751771
772+     #[ cfg( debug_assertions) ]  
752773    pub  unsafe  extern  "C"  fn  rust_callable_to_string_named < F > ( 
753774        callable_userdata :  * mut  std:: ffi:: c_void , 
754775        r_is_valid :  * mut  sys:: GDExtensionBool , 
0 commit comments