@@ -202,26 +202,24 @@ impl Command {
202202 // emscripten has no signal support.
203203 #[ cfg( not( any( target_os = "emscripten" ) ) ) ]
204204 {
205- use crate :: mem;
205+ use crate :: mem:: MaybeUninit ;
206206 // Reset signal handling so the child process starts in a
207207 // standardized state. libstd ignores SIGPIPE, and signal-handling
208208 // libraries often set a mask. Child processes inherit ignored
209209 // signals and the signal mask from their parent, but most
210210 // UNIX programs do not reset these things on their own, so we
211211 // need to clean things up now to avoid confusing the program
212212 // we're about to run.
213- let mut set: libc:: sigset_t = mem :: uninitialized ( ) ;
213+ let mut set = MaybeUninit :: < libc:: sigset_t > :: uninit ( ) ;
214214 if cfg ! ( target_os = "android" ) {
215215 // Implementing sigemptyset allow us to support older Android
216216 // versions. See the comment about Android and sig* functions in
217217 // process_common.rs
218- libc:: memset ( & mut set as * mut _ as * mut _ ,
219- 0 ,
220- mem:: size_of :: < libc:: sigset_t > ( ) ) ;
218+ set. as_mut_ptr ( ) . write_bytes ( 0u8 , 1 ) ;
221219 } else {
222- cvt ( libc:: sigemptyset ( & mut set) ) ?;
220+ cvt ( libc:: sigemptyset ( set. as_mut_ptr ( ) ) ) ?;
223221 }
224- cvt ( libc:: pthread_sigmask ( libc:: SIG_SETMASK , & set,
222+ cvt ( libc:: pthread_sigmask ( libc:: SIG_SETMASK , set. as_ptr ( ) ,
225223 ptr:: null_mut ( ) ) ) ?;
226224 let ret = sys:: signal ( libc:: SIGPIPE , libc:: SIG_DFL ) ;
227225 if ret == libc:: SIG_ERR {
@@ -273,7 +271,7 @@ impl Command {
273271 fn posix_spawn ( & mut self , stdio : & ChildPipes , envp : Option < & CStringArray > )
274272 -> io:: Result < Option < Process > >
275273 {
276- use crate :: mem;
274+ use crate :: mem:: MaybeUninit ;
277275 use crate :: sys;
278276
279277 if self . get_gid ( ) . is_some ( ) ||
@@ -315,63 +313,63 @@ impl Command {
315313
316314 let mut p = Process { pid : 0 , status : None } ;
317315
318- struct PosixSpawnFileActions ( libc:: posix_spawn_file_actions_t ) ;
316+ struct PosixSpawnFileActions ( MaybeUninit < libc:: posix_spawn_file_actions_t > ) ;
319317
320318 impl Drop for PosixSpawnFileActions {
321319 fn drop ( & mut self ) {
322320 unsafe {
323- libc:: posix_spawn_file_actions_destroy ( & mut self . 0 ) ;
321+ libc:: posix_spawn_file_actions_destroy ( self . 0 . as_mut_ptr ( ) ) ;
324322 }
325323 }
326324 }
327325
328- struct PosixSpawnattr ( libc:: posix_spawnattr_t ) ;
326+ struct PosixSpawnattr ( MaybeUninit < libc:: posix_spawnattr_t > ) ;
329327
330328 impl Drop for PosixSpawnattr {
331329 fn drop ( & mut self ) {
332330 unsafe {
333- libc:: posix_spawnattr_destroy ( & mut self . 0 ) ;
331+ libc:: posix_spawnattr_destroy ( self . 0 . as_mut_ptr ( ) ) ;
334332 }
335333 }
336334 }
337335
338336 unsafe {
339- let mut file_actions = PosixSpawnFileActions ( mem :: uninitialized ( ) ) ;
340- let mut attrs = PosixSpawnattr ( mem :: uninitialized ( ) ) ;
337+ let mut file_actions = PosixSpawnFileActions ( MaybeUninit :: uninit ( ) ) ;
338+ let mut attrs = PosixSpawnattr ( MaybeUninit :: uninit ( ) ) ;
341339
342- libc:: posix_spawnattr_init ( & mut attrs. 0 ) ;
343- libc:: posix_spawn_file_actions_init ( & mut file_actions. 0 ) ;
340+ libc:: posix_spawnattr_init ( attrs. 0 . as_mut_ptr ( ) ) ;
341+ libc:: posix_spawn_file_actions_init ( file_actions. 0 . as_mut_ptr ( ) ) ;
344342
345343 if let Some ( fd) = stdio. stdin . fd ( ) {
346- cvt ( libc:: posix_spawn_file_actions_adddup2 ( & mut file_actions. 0 ,
344+ cvt ( libc:: posix_spawn_file_actions_adddup2 ( file_actions. 0 . as_mut_ptr ( ) ,
347345 fd,
348346 libc:: STDIN_FILENO ) ) ?;
349347 }
350348 if let Some ( fd) = stdio. stdout . fd ( ) {
351- cvt ( libc:: posix_spawn_file_actions_adddup2 ( & mut file_actions. 0 ,
349+ cvt ( libc:: posix_spawn_file_actions_adddup2 ( file_actions. 0 . as_mut_ptr ( ) ,
352350 fd,
353351 libc:: STDOUT_FILENO ) ) ?;
354352 }
355353 if let Some ( fd) = stdio. stderr . fd ( ) {
356- cvt ( libc:: posix_spawn_file_actions_adddup2 ( & mut file_actions. 0 ,
354+ cvt ( libc:: posix_spawn_file_actions_adddup2 ( file_actions. 0 . as_mut_ptr ( ) ,
357355 fd,
358356 libc:: STDERR_FILENO ) ) ?;
359357 }
360358 if let Some ( ( f, cwd) ) = addchdir {
361- cvt ( f ( & mut file_actions. 0 , cwd. as_ptr ( ) ) ) ?;
359+ cvt ( f ( file_actions. 0 . as_mut_ptr ( ) , cwd. as_ptr ( ) ) ) ?;
362360 }
363361
364- let mut set: libc:: sigset_t = mem :: uninitialized ( ) ;
365- cvt ( libc:: sigemptyset ( & mut set) ) ?;
366- cvt ( libc:: posix_spawnattr_setsigmask ( & mut attrs. 0 ,
367- & set) ) ?;
368- cvt ( libc:: sigaddset ( & mut set, libc:: SIGPIPE ) ) ?;
369- cvt ( libc:: posix_spawnattr_setsigdefault ( & mut attrs. 0 ,
370- & set) ) ?;
362+ let mut set = MaybeUninit :: < libc:: sigset_t > :: uninit ( ) ;
363+ cvt ( libc:: sigemptyset ( set. as_mut_ptr ( ) ) ) ?;
364+ cvt ( libc:: posix_spawnattr_setsigmask ( attrs. 0 . as_mut_ptr ( ) ,
365+ set. as_ptr ( ) ) ) ?;
366+ cvt ( libc:: sigaddset ( set. as_mut_ptr ( ) , libc:: SIGPIPE ) ) ?;
367+ cvt ( libc:: posix_spawnattr_setsigdefault ( attrs. 0 . as_mut_ptr ( ) ,
368+ set. as_ptr ( ) ) ) ?;
371369
372370 let flags = libc:: POSIX_SPAWN_SETSIGDEF |
373371 libc:: POSIX_SPAWN_SETSIGMASK ;
374- cvt ( libc:: posix_spawnattr_setflags ( & mut attrs. 0 , flags as _ ) ) ?;
372+ cvt ( libc:: posix_spawnattr_setflags ( attrs. 0 . as_mut_ptr ( ) , flags as _ ) ) ?;
375373
376374 // Make sure we synchronize access to the global `environ` resource
377375 let _env_lock = sys:: os:: env_lock ( ) ;
@@ -380,8 +378,8 @@ impl Command {
380378 let ret = libc:: posix_spawnp (
381379 & mut p. pid ,
382380 self . get_argv ( ) [ 0 ] ,
383- & file_actions. 0 ,
384- & attrs. 0 ,
381+ file_actions. 0 . as_ptr ( ) ,
382+ attrs. 0 . as_ptr ( ) ,
385383 self . get_argv ( ) . as_ptr ( ) as * const _ ,
386384 envp as * const _ ,
387385 ) ;
0 commit comments