@@ -119,29 +119,14 @@ mod decl {
119119 // PUTS macro
120120 #[ cfg( any( unix, windows) ) ]
121121 fn puts ( fd : i32 , s : & str ) {
122- let _ = unsafe {
123- #[ cfg( windows) ]
124- {
125- libc:: write ( fd, s. as_ptr ( ) as * const libc:: c_void , s. len ( ) as u32 )
126- }
127- #[ cfg( not( windows) ) ]
128- {
129- libc:: write ( fd, s. as_ptr ( ) as * const libc:: c_void , s. len ( ) )
130- }
131- } ;
122+ puts_bytes ( fd, s. as_bytes ( ) )
132123 }
133124
134125 #[ cfg( any( unix, windows) ) ]
135126 fn puts_bytes ( fd : i32 , s : & [ u8 ] ) {
136- let _ = unsafe {
137- #[ cfg( windows) ]
138- {
139- libc:: write ( fd, s. as_ptr ( ) as * const libc:: c_void , s. len ( ) as u32 )
140- }
141- #[ cfg( not( windows) ) ]
142- {
143- libc:: write ( fd, s. as_ptr ( ) as * const libc:: c_void , s. len ( ) )
144- }
127+ let _ = cfg_select ! {
128+ windows => unsafe { libc:: write( fd, s. as_ptr( ) as * const libc:: c_void, s. len( ) as u32 ) } ,
129+ _ => unsafe { libc:: write( fd, s. as_ptr( ) as * const libc:: c_void, s. len( ) ) } ,
145130 } ;
146131 }
147132
@@ -158,16 +143,7 @@ mod decl {
158143 buf[ 2 + i] = HEX_CHARS [ digit] ;
159144 }
160145
161- let _ = unsafe {
162- #[ cfg( windows) ]
163- {
164- libc:: write ( fd, buf. as_ptr ( ) as * const libc:: c_void , ( 2 + width) as u32 )
165- }
166- #[ cfg( not( windows) ) ]
167- {
168- libc:: write ( fd, buf. as_ptr ( ) as * const libc:: c_void , 2 + width)
169- }
170- } ;
146+ puts_bytes ( fd, & buf[ ..2 + width] ) ;
171147 }
172148
173149 // _Py_DumpDecimal (traceback.c)
@@ -188,17 +164,7 @@ mod decl {
188164 v /= 10 ;
189165 }
190166
191- let len = buf. len ( ) - i;
192- let _ = unsafe {
193- #[ cfg( windows) ]
194- {
195- libc:: write ( fd, buf[ i..] . as_ptr ( ) as * const libc:: c_void , len as u32 )
196- }
197- #[ cfg( not( windows) ) ]
198- {
199- libc:: write ( fd, buf[ i..] . as_ptr ( ) as * const libc:: c_void , len)
200- }
201- } ;
167+ puts_bytes ( fd, & buf[ ..buf. len ( ) - i] ) ;
202168 }
203169
204170 /// Get current thread ID
@@ -857,30 +823,31 @@ mod decl {
857823 drop ( guard) ; // Release lock before I/O
858824
859825 // Timeout occurred, dump traceback
860- #[ cfg( target_arch = "wasm32" ) ]
861- let _ = ( exit, fd, & header) ;
862-
863- #[ cfg( not( target_arch = "wasm32" ) ) ]
864- {
865- puts_bytes ( fd, header. as_bytes ( ) ) ;
866-
867- // Use thread frame slots when threading is enabled (includes all threads).
868- // Fall back to live frame walking for non-threaded builds.
869- #[ cfg( feature = "threading" ) ]
870- {
871- for ( tid, slot) in & thread_frame_slots {
872- let frames = slot. frames . lock ( ) ;
873- dump_traceback_thread_frames ( fd, * tid, false , & frames) ;
874- }
875- }
876- #[ cfg( not( feature = "threading" ) ) ]
877- {
878- write_thread_id ( fd, current_thread_id ( ) , false ) ;
879- dump_live_frames ( fd) ;
826+ cfg_select ! {
827+ target_arch = "wasm32" => {
828+ let _ = ( exit, fd, & header) ;
880829 }
830+ _ => {
831+ puts_bytes( fd, header. as_bytes( ) ) ;
832+
833+ // Use thread frame slots when threading is enabled (includes all threads).
834+ // Fall back to live frame walking for non-threaded builds.
835+ cfg_select! {
836+ feature = "threading" => {
837+ for ( tid, slot) in & thread_frame_slots {
838+ let frames = slot. frames. lock( ) ;
839+ dump_traceback_thread_frames( fd, * tid, false , & frames) ;
840+ }
841+ }
842+ _ => {
843+ write_thread_id( fd, current_thread_id( ) , false ) ;
844+ dump_live_frames( fd) ;
845+ }
846+ }
881847
882- if exit {
883- rustpython_host_env:: os:: exit ( 1 ) ;
848+ if exit {
849+ rustpython_host_env:: os:: exit( 1 ) ;
850+ }
884851 }
885852 }
886853
0 commit comments