@@ -119,30 +119,12 @@ 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- }
145- } ;
127+ let _ = unsafe { libc:: write ( fd, s. as_ptr ( ) . cast :: < libc:: c_void > ( ) , s. len ( ) as _ ) } ;
146128 }
147129
148130 // _Py_DumpHexadecimal (traceback.c)
@@ -158,16 +140,7 @@ mod decl {
158140 buf[ 2 + i] = HEX_CHARS [ digit] ;
159141 }
160142
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- } ;
143+ puts_bytes ( fd, & buf[ ..2 + width] ) ;
171144 }
172145
173146 // _Py_DumpDecimal (traceback.c)
@@ -188,17 +161,7 @@ mod decl {
188161 v /= 10 ;
189162 }
190163
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- } ;
164+ puts_bytes ( fd, & buf[ i..] ) ;
202165 }
203166
204167 /// Get current thread ID
@@ -857,30 +820,31 @@ mod decl {
857820 drop ( guard) ; // Release lock before I/O
858821
859822 // 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) ;
823+ cfg_select ! {
824+ target_arch = "wasm32" => {
825+ let _ = ( exit, fd, & header) ;
880826 }
827+ _ => {
828+ puts_bytes( fd, header. as_bytes( ) ) ;
829+
830+ // Use thread frame slots when threading is enabled (includes all threads).
831+ // Fall back to live frame walking for non-threaded builds.
832+ cfg_select! {
833+ feature = "threading" => {
834+ for ( tid, slot) in & thread_frame_slots {
835+ let frames = slot. frames. lock( ) ;
836+ dump_traceback_thread_frames( fd, * tid, false , & frames) ;
837+ }
838+ }
839+ _ => {
840+ write_thread_id( fd, current_thread_id( ) , false ) ;
841+ dump_live_frames( fd) ;
842+ }
843+ }
881844
882- if exit {
883- rustpython_host_env:: os:: exit ( 1 ) ;
845+ if exit {
846+ rustpython_host_env:: os:: exit( 1 ) ;
847+ }
884848 }
885849 }
886850
0 commit comments