Skip to content

Commit a756cd6

Browse files
committed
Fix broken build on ESP-IDF caused by rust-lang#115108
1 parent 481d45a commit a756cd6

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

library/std/src/sys/unix/process/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ pub use crate::sys_common::process::CommandEnvs;
66
#[cfg_attr(any(target_os = "espidf", target_os = "horizon"), allow(unused))]
77
mod process_common;
88

9+
#[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita"))]
10+
mod process_unsupported;
11+
912
cfg_if::cfg_if! {
1013
if #[cfg(target_os = "fuchsia")] {
1114
#[path = "process_fuchsia.rs"]
@@ -15,8 +18,9 @@ cfg_if::cfg_if! {
1518
#[path = "process_vxworks.rs"]
1619
mod process_inner;
1720
} else if #[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita"))] {
18-
#[path = "process_unsupported.rs"]
19-
mod process_inner;
21+
mod process_inner {
22+
pub use super::process_unsupported::*;
23+
}
2024
} else {
2125
#[path = "process_unix.rs"]
2226
mod process_inner;

library/std/src/sys/unix/process/process_unsupported.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ pub struct ExitStatusError(NonZero_c_int);
6363

6464
impl Into<ExitStatus> for ExitStatusError {
6565
fn into(self) -> ExitStatus {
66-
ExitStatus(self.0.into())
66+
ExitStatus::from(c_int::from(self.0))
6767
}
6868
}
6969

7070
impl ExitStatusError {
7171
pub fn code(self) -> Option<NonZeroI32> {
72-
ExitStatus(self.0.into()).code().map(|st| st.try_into().unwrap())
72+
ExitStatus::from(c_int::from(self.0)).code().map(|st| st.try_into().unwrap())
7373
}
7474
}

library/std/src/sys/unix/process/process_unsupported/wait_status.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
//! Emulated wait status for non-Unix #[cfg(unix) platforms
22
//!
33
//! Separate module to facilitate testing against a real Unix implementation.
4+
use core::ffi::NonZero_c_int;
45

56
use crate::ffi::c_int;
67
use crate::fmt;
78

9+
use super::ExitStatusError;
10+
811
/// Emulated wait status for use by `process_unsupported.rs`
912
///
1013
/// Uses the "traditional unix" encoding. For use on platfors which are `#[cfg(unix)]`
@@ -40,6 +43,18 @@ impl ExitStatus {
4043
if (w & 0x7f) == 0 { Some((w & 0xff00) >> 8) } else { None }
4144
}
4245

46+
pub fn exit_ok(&self) -> Result<(), ExitStatusError> {
47+
// This assumes that WIFEXITED(status) && WEXITSTATUS==0 corresponds to status==0. This is
48+
// true on all actual versions of Unix, is widely assumed, and is specified in SuS
49+
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html. If it is not
50+
// true for a platform pretending to be Unix, the tests (our doctests, and also
51+
// process_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
52+
match NonZero_c_int::try_from(self.wait_status) {
53+
/* was nonzero */ Ok(failure) => Err(ExitStatusError(failure)),
54+
/* was zero, couldn't convert */ Err(_) => Ok(()),
55+
}
56+
}
57+
4358
pub fn signal(&self) -> Option<i32> {
4459
let signal = self.wait_status & 0x007f;
4560
if signal > 0 && signal < 0x7f { Some(signal) } else { None }

0 commit comments

Comments
 (0)