File tree 2 files changed +8
-8
lines changed
2 files changed +8
-8
lines changed Original file line number Diff line number Diff line change 16
16
#![ deny( unsafe_op_in_unsafe_fn) ]
17
17
#![ allow( unused_macros) ]
18
18
19
+ use crate :: ffi:: CString ;
20
+
19
21
// Re-export some of our utilities which are expected by other crates.
20
22
pub use crate :: panicking:: { begin_panic, begin_panic_fmt, panic_count} ;
21
23
@@ -38,7 +40,7 @@ unsafe fn init(argc: isize, argv: *const *const u8) {
38
40
// created. Note that this isn't necessary in general for new threads,
39
41
// but we just do this to name the main thread and to give it correct
40
42
// info about the stack bounds.
41
- let thread = Thread :: new ( Some ( "main" . to_owned ( ) ) ) ;
43
+ let thread = Thread :: new ( Some ( CString :: new ( "main" ) . unwrap ( ) ) ) ;
42
44
thread_info:: set ( main_guard, thread) ;
43
45
}
44
46
}
Original file line number Diff line number Diff line change @@ -457,7 +457,9 @@ impl Builder {
457
457
458
458
let stack_size = stack_size. unwrap_or_else ( thread:: min_stack) ;
459
459
460
- let my_thread = Thread :: new ( name) ;
460
+ let my_thread = Thread :: new ( name. map ( |name| {
461
+ CString :: new ( name) . expect ( "thread name may not contain interior null bytes" )
462
+ } ) ) ;
461
463
let their_thread = my_thread. clone ( ) ;
462
464
463
465
let my_packet: Arc < UnsafeCell < Option < Result < T > > > > = Arc :: new ( UnsafeCell :: new ( None ) ) ;
@@ -1073,12 +1075,8 @@ pub struct Thread {
1073
1075
impl Thread {
1074
1076
// Used only internally to construct a thread object without spawning
1075
1077
// Panics if the name contains nuls.
1076
- pub ( crate ) fn new ( name : Option < String > ) -> Thread {
1077
- let cname =
1078
- name. map ( |n| CString :: new ( n) . expect ( "thread name may not contain interior null bytes" ) ) ;
1079
- Thread {
1080
- inner : Arc :: new ( Inner { name : cname, id : ThreadId :: new ( ) , parker : Parker :: new ( ) } ) ,
1081
- }
1078
+ pub ( crate ) fn new ( name : Option < CString > ) -> Thread {
1079
+ Thread { inner : Arc :: new ( Inner { name, id : ThreadId :: new ( ) , parker : Parker :: new ( ) } ) }
1082
1080
}
1083
1081
1084
1082
/// Atomically makes the handle's token available if it is not already.
You can’t perform that action at this time.
0 commit comments