@@ -202,26 +202,26 @@ impl Command {
202
202
// emscripten has no signal support.
203
203
#[ cfg( not( any( target_os = "emscripten" ) ) ) ]
204
204
{
205
- use crate :: mem;
205
+ use crate :: mem:: { self , MaybeUninit } ;
206
206
// Reset signal handling so the child process starts in a
207
207
// standardized state. libstd ignores SIGPIPE, and signal-handling
208
208
// libraries often set a mask. Child processes inherit ignored
209
209
// signals and the signal mask from their parent, but most
210
210
// UNIX programs do not reset these things on their own, so we
211
211
// need to clean things up now to avoid confusing the program
212
212
// we're about to run.
213
- let mut set: libc:: sigset_t = mem :: uninitialized ( ) ;
213
+ let mut set = MaybeUninit :: < libc:: sigset_t > :: uninit ( ) ;
214
214
if cfg ! ( target_os = "android" ) {
215
215
// Implementing sigemptyset allow us to support older Android
216
216
// versions. See the comment about Android and sig* functions in
217
217
// process_common.rs
218
- libc:: memset ( & mut set as * mut _ as * mut _ ,
218
+ libc:: memset ( set. as_mut_ptr ( ) as * mut _ ,
219
219
0 ,
220
220
mem:: size_of :: < libc:: sigset_t > ( ) ) ;
221
221
} else {
222
- cvt ( libc:: sigemptyset ( & mut set) ) ?;
222
+ cvt ( libc:: sigemptyset ( set. as_mut_ptr ( ) ) ) ?;
223
223
}
224
- cvt ( libc:: pthread_sigmask ( libc:: SIG_SETMASK , & set,
224
+ cvt ( libc:: pthread_sigmask ( libc:: SIG_SETMASK , set. as_ptr ( ) ,
225
225
ptr:: null_mut ( ) ) ) ?;
226
226
let ret = sys:: signal ( libc:: SIGPIPE , libc:: SIG_DFL ) ;
227
227
if ret == libc:: SIG_ERR {
@@ -273,7 +273,7 @@ impl Command {
273
273
fn posix_spawn ( & mut self , stdio : & ChildPipes , envp : Option < & CStringArray > )
274
274
-> io:: Result < Option < Process > >
275
275
{
276
- use crate :: mem;
276
+ use crate :: mem:: MaybeUninit ;
277
277
use crate :: sys;
278
278
279
279
if self . get_gid ( ) . is_some ( ) ||
@@ -315,63 +315,63 @@ impl Command {
315
315
316
316
let mut p = Process { pid : 0 , status : None } ;
317
317
318
- struct PosixSpawnFileActions ( libc:: posix_spawn_file_actions_t ) ;
318
+ struct PosixSpawnFileActions ( MaybeUninit < libc:: posix_spawn_file_actions_t > ) ;
319
319
320
320
impl Drop for PosixSpawnFileActions {
321
321
fn drop ( & mut self ) {
322
322
unsafe {
323
- libc:: posix_spawn_file_actions_destroy ( & mut self . 0 ) ;
323
+ libc:: posix_spawn_file_actions_destroy ( self . 0 . as_mut_ptr ( ) ) ;
324
324
}
325
325
}
326
326
}
327
327
328
- struct PosixSpawnattr ( libc:: posix_spawnattr_t ) ;
328
+ struct PosixSpawnattr ( MaybeUninit < libc:: posix_spawnattr_t > ) ;
329
329
330
330
impl Drop for PosixSpawnattr {
331
331
fn drop ( & mut self ) {
332
332
unsafe {
333
- libc:: posix_spawnattr_destroy ( & mut self . 0 ) ;
333
+ libc:: posix_spawnattr_destroy ( self . 0 . as_mut_ptr ( ) ) ;
334
334
}
335
335
}
336
336
}
337
337
338
338
unsafe {
339
- let mut file_actions = PosixSpawnFileActions ( mem :: uninitialized ( ) ) ;
340
- let mut attrs = PosixSpawnattr ( mem :: uninitialized ( ) ) ;
339
+ let mut file_actions = PosixSpawnFileActions ( MaybeUninit :: uninit ( ) ) ;
340
+ let mut attrs = PosixSpawnattr ( MaybeUninit :: uninit ( ) ) ;
341
341
342
- libc:: posix_spawnattr_init ( & mut attrs. 0 ) ;
343
- libc:: posix_spawn_file_actions_init ( & mut file_actions. 0 ) ;
342
+ libc:: posix_spawnattr_init ( attrs. 0 . as_mut_ptr ( ) ) ;
343
+ libc:: posix_spawn_file_actions_init ( file_actions. 0 . as_mut_ptr ( ) ) ;
344
344
345
345
if let Some ( fd) = stdio. stdin . fd ( ) {
346
- cvt ( libc:: posix_spawn_file_actions_adddup2 ( & mut file_actions. 0 ,
346
+ cvt ( libc:: posix_spawn_file_actions_adddup2 ( file_actions. 0 . as_mut_ptr ( ) ,
347
347
fd,
348
348
libc:: STDIN_FILENO ) ) ?;
349
349
}
350
350
if let Some ( fd) = stdio. stdout . fd ( ) {
351
- cvt ( libc:: posix_spawn_file_actions_adddup2 ( & mut file_actions. 0 ,
351
+ cvt ( libc:: posix_spawn_file_actions_adddup2 ( file_actions. 0 . as_mut_ptr ( ) ,
352
352
fd,
353
353
libc:: STDOUT_FILENO ) ) ?;
354
354
}
355
355
if let Some ( fd) = stdio. stderr . fd ( ) {
356
- cvt ( libc:: posix_spawn_file_actions_adddup2 ( & mut file_actions. 0 ,
356
+ cvt ( libc:: posix_spawn_file_actions_adddup2 ( file_actions. 0 . as_mut_ptr ( ) ,
357
357
fd,
358
358
libc:: STDERR_FILENO ) ) ?;
359
359
}
360
360
if let Some ( ( f, cwd) ) = addchdir {
361
- cvt ( f ( & mut file_actions. 0 , cwd. as_ptr ( ) ) ) ?;
361
+ cvt ( f ( file_actions. 0 . as_mut_ptr ( ) , cwd. as_ptr ( ) ) ) ?;
362
362
}
363
363
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) ) ?;
364
+ let mut set = MaybeUninit :: < libc:: sigset_t > :: uninit ( ) ;
365
+ cvt ( libc:: sigemptyset ( set. as_mut_ptr ( ) ) ) ?;
366
+ cvt ( libc:: posix_spawnattr_setsigmask ( attrs. 0 . as_mut_ptr ( ) ,
367
+ set. as_ptr ( ) ) ) ?;
368
+ cvt ( libc:: sigaddset ( set. as_mut_ptr ( ) , libc:: SIGPIPE ) ) ?;
369
+ cvt ( libc:: posix_spawnattr_setsigdefault ( attrs. 0 . as_mut_ptr ( ) ,
370
+ set. as_ptr ( ) ) ) ?;
371
371
372
372
let flags = libc:: POSIX_SPAWN_SETSIGDEF |
373
373
libc:: POSIX_SPAWN_SETSIGMASK ;
374
- cvt ( libc:: posix_spawnattr_setflags ( & mut attrs. 0 , flags as _ ) ) ?;
374
+ cvt ( libc:: posix_spawnattr_setflags ( attrs. 0 . as_mut_ptr ( ) , flags as _ ) ) ?;
375
375
376
376
// Make sure we synchronize access to the global `environ` resource
377
377
let _env_lock = sys:: os:: env_lock ( ) ;
@@ -380,8 +380,8 @@ impl Command {
380
380
let ret = libc:: posix_spawnp (
381
381
& mut p. pid ,
382
382
self . get_argv ( ) [ 0 ] ,
383
- & file_actions. 0 ,
384
- & attrs. 0 ,
383
+ file_actions. 0 . as_ptr ( ) ,
384
+ attrs. 0 . as_ptr ( ) ,
385
385
self . get_argv ( ) . as_ptr ( ) as * const _ ,
386
386
envp as * const _ ,
387
387
) ;
0 commit comments