Skip to content

Commit

Permalink
Ignore unnecessary unsafe warnings
Browse files Browse the repository at this point in the history
This is a work-around for a libc issue:
rust-lang/libc#1888.
  • Loading branch information
Thomasdezeeuw committed Sep 11, 2020
1 parent 7c3e1ff commit c394624
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
1 change: 0 additions & 1 deletion library/std/src/sys/unix/fd.rs
Expand Up @@ -6,7 +6,6 @@ mod tests;
use crate::cmp;
use crate::io::{self, Initializer, IoSlice, IoSliceMut, Read};
use crate::mem;
#[cfg(not(any(target_os = "redox", target_env = "newlib")))]
use crate::sys::cvt;
use crate::sys_common::AsInner;

Expand Down
22 changes: 21 additions & 1 deletion library/std/src/sys/unix/process/process_unix.rs
Expand Up @@ -459,18 +459,38 @@ impl ExitStatus {
}

fn exited(&self) -> bool {
unsafe { libc::WIFEXITED(self.0) }
// On Linux-like OSes this function is safe, on others it is not. See
// libc issue: https://github.com/rust-lang/libc/issues/1888.
#[cfg_attr(
any(target_os = "linux", target_os = "android", target_os = "emscripten"),
allow(unused_unsafe)
)]
unsafe {
libc::WIFEXITED(self.0)
}
}

pub fn success(&self) -> bool {
self.code() == Some(0)
}

pub fn code(&self) -> Option<i32> {
// On Linux-like OSes this function is safe, on others it is not. See
// libc issue: https://github.com/rust-lang/libc/issues/1888.
#[cfg_attr(
any(target_os = "linux", target_os = "android", target_os = "emscripten"),
allow(unused_unsafe)
)]
if self.exited() { Some(unsafe { libc::WEXITSTATUS(self.0) }) } else { None }
}

pub fn signal(&self) -> Option<i32> {
// On Linux-like OSes this function is safe, on others it is not. See
// libc issue: https://github.com/rust-lang/libc/issues/1888.
#[cfg_attr(
any(target_os = "linux", target_os = "android", target_os = "emscripten"),
allow(unused_unsafe)
)]
if !self.exited() { Some(unsafe { libc::WTERMSIG(self.0) }) } else { None }
}
}
Expand Down

0 comments on commit c394624

Please sign in to comment.