Skip to content

Commit 74c5c6e

Browse files
committed
Move process::ExitCode internals to sys
Now begins the saga of fixing compilation errors on other platforms...
1 parent 2ce2b40 commit 74c5c6e

File tree

7 files changed

+72
-24
lines changed

7 files changed

+72
-24
lines changed

src/libstd/process.rs

+8-21
Original file line numberDiff line numberDiff line change
@@ -1098,38 +1098,26 @@ impl fmt::Display for ExitStatus {
10981098
///
10991099
/// [RFC #1937]: https://github.com/rust-lang/rfcs/pull/1937
11001100
#[derive(Clone, Copy, Debug)]
1101-
#[unstable(feature = "process_exitcode_placeholder", issue = "43301")]
1102-
pub struct ExitCode(pub i32);
1101+
#[unstable(feature = "process_exitcode_placeholder", issue = "48711")]
1102+
pub struct ExitCode(imp::ExitCode);
11031103

1104-
#[cfg(target_arch = "wasm32")]
1105-
mod rawexit {
1106-
pub const SUCCESS: i32 = 0;
1107-
pub const FAILURE: i32 = 1;
1108-
}
1109-
#[cfg(not(target_arch = "wasm32"))]
1110-
mod rawexit {
1111-
use libc;
1112-
pub const SUCCESS: i32 = libc::EXIT_SUCCESS;
1113-
pub const FAILURE: i32 = libc::EXIT_FAILURE;
1114-
}
1115-
1116-
#[unstable(feature = "process_exitcode_placeholder", issue = "43301")]
1104+
#[unstable(feature = "process_exitcode_placeholder", issue = "48711")]
11171105
impl ExitCode {
11181106
/// The canonical ExitCode for successful termination on this platform.
11191107
///
11201108
/// Note that a `()`-returning `main` implicitly results in a successful
11211109
/// termination, so there's no need to return this from `main` unless
11221110
/// you're also returning other possible codes.
1123-
#[unstable(feature = "process_exitcode_placeholder", issue = "43301")]
1124-
pub const SUCCESS: ExitCode = ExitCode(rawexit::SUCCESS);
1111+
#[unstable(feature = "process_exitcode_placeholder", issue = "48711")]
1112+
pub const SUCCESS: ExitCode = ExitCode(imp::ExitCode::SUCCESS);
11251113

11261114
/// The canonical ExitCode for unsuccessful termination on this platform.
11271115
///
11281116
/// If you're only returning this and `SUCCESS` from `main`, consider
11291117
/// instead returning `Err(_)` and `Ok(())` respectively, which will
11301118
/// return the same codes (but will also `eprintln!` the error).
1131-
#[unstable(feature = "process_exitcode_placeholder", issue = "43301")]
1132-
pub const FAILURE: ExitCode = ExitCode(rawexit::FAILURE);
1119+
#[unstable(feature = "process_exitcode_placeholder", issue = "48711")]
1120+
pub const FAILURE: ExitCode = ExitCode(imp::ExitCode::FAILURE);
11331121
}
11341122

11351123
impl Child {
@@ -1494,8 +1482,7 @@ impl<E: fmt::Debug> Termination for Result<!, E> {
14941482
#[unstable(feature = "termination_trait_lib", issue = "43301")]
14951483
impl Termination for ExitCode {
14961484
fn report(self) -> i32 {
1497-
let ExitCode(code) = self;
1498-
code
1485+
self.0.as_i32()
14991486
}
15001487
}
15011488

src/libstd/sys/cloudabi/shims/process.rs

+12
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ impl fmt::Display for ExitStatus {
126126
}
127127
}
128128

129+
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
130+
pub struct ExitCode(bool);
131+
132+
impl ExitCode {
133+
pub const SUCCESS: ExitCode = ExitCode(false);
134+
pub const FAILURE: ExitCode = ExitCode(true);
135+
136+
pub fn as_i32(&self) -> i32 {
137+
self.0 as i32
138+
}
139+
}
140+
129141
pub struct Process(Void);
130142

131143
impl Process {

src/libstd/sys/redox/process.rs

+13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use ffi::OsStr;
1313
use os::unix::ffi::OsStrExt;
1414
use fmt;
1515
use io::{self, Error, ErrorKind};
16+
use libc::{EXIT_SUCCESS, EXIT_FAILURE};
1617
use path::{Path, PathBuf};
1718
use sys::fd::FileDesc;
1819
use sys::fs::{File, OpenOptions};
@@ -480,6 +481,18 @@ impl fmt::Display for ExitStatus {
480481
}
481482
}
482483

484+
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
485+
pub struct ExitCode(u8);
486+
487+
impl ExitCode {
488+
pub const SUCCESS: ExitCode = ExitCode(EXIT_SUCCESS as _);
489+
pub const FAILURE: ExitCode = ExitCode(EXIT_FAILURE as _);
490+
491+
pub fn as_i32(&self) -> i32 {
492+
self.0 as i32
493+
}
494+
}
495+
483496
/// The unique id of the process (this should never be negative).
484497
pub struct Process {
485498
pid: usize,

src/libstd/sys/unix/process/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
pub use self::process_common::{Command, ExitStatus, Stdio, StdioPipes};
11+
pub use self::process_common::{Command, ExitStatus, ExitCode, Stdio, StdioPipes};
1212
pub use self::process_inner::Process;
1313

1414
mod process_common;

src/libstd/sys/unix/process/process_common.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use os::unix::prelude::*;
1313
use ffi::{OsString, OsStr, CString, CStr};
1414
use fmt;
1515
use io;
16-
use libc::{self, c_int, gid_t, uid_t, c_char};
16+
use libc::{self, c_int, gid_t, uid_t, c_char, EXIT_SUCCESS, EXIT_FAILURE};
1717
use ptr;
1818
use sys::fd::FileDesc;
1919
use sys::fs::{File, OpenOptions};
@@ -393,6 +393,18 @@ impl fmt::Display for ExitStatus {
393393
}
394394
}
395395

396+
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
397+
pub struct ExitCode(u8);
398+
399+
impl ExitCode {
400+
pub const SUCCESS: ExitCode = ExitCode(EXIT_SUCCESS as _);
401+
pub const FAILURE: ExitCode = ExitCode(EXIT_FAILURE as _);
402+
403+
pub fn as_i32(&self) -> i32 {
404+
self.0 as i32
405+
}
406+
}
407+
396408
#[cfg(all(test, not(target_os = "emscripten")))]
397409
mod tests {
398410
use super::*;

src/libstd/sys/wasm/process.rs

+12
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ impl fmt::Display for ExitStatus {
129129
}
130130
}
131131

132+
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
133+
pub struct ExitCode(bool);
134+
135+
impl ExitCode {
136+
pub const SUCCESS: ExitCode = ExitCode(false);
137+
pub const FAILURE: ExitCode = ExitCode(true);
138+
139+
pub fn as_i32(&self) -> i32 {
140+
self.0 as i32
141+
}
142+
}
143+
132144
pub struct Process(Void);
133145

134146
impl Process {

src/libstd/sys/windows/process.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use ffi::{OsString, OsStr};
1818
use fmt;
1919
use fs;
2020
use io::{self, Error, ErrorKind};
21-
use libc::c_void;
21+
use libc::{c_void, EXIT_SUCCESS, EXIT_FAILURE};
2222
use mem;
2323
use os::windows::ffi::OsStrExt;
2424
use path::Path;
@@ -408,6 +408,18 @@ impl fmt::Display for ExitStatus {
408408
}
409409
}
410410

411+
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
412+
pub struct ExitCode(c::DWORD);
413+
414+
impl ExitCode {
415+
pub const SUCCESS: ExitCode = ExitCode(EXIT_SUCCESS as _);
416+
pub const FAILURE: ExitCode = ExitCode(EXIT_FAILURE as _);
417+
418+
pub fn as_i32(&self) -> i32 {
419+
self.0 as i32
420+
}
421+
}
422+
411423
fn zeroed_startupinfo() -> c::STARTUPINFO {
412424
c::STARTUPINFO {
413425
cb: 0,

0 commit comments

Comments
 (0)