]> git.lizzy.rs Git - rust.git/commitdiff
Move process::ExitCode internals to sys
authorScott McMurray <scottmcm@users.noreply.github.com>
Sun, 4 Mar 2018 02:29:30 +0000 (18:29 -0800)
committerScott McMurray <scottmcm@users.noreply.github.com>
Sun, 4 Mar 2018 02:44:44 +0000 (18:44 -0800)
Now begins the saga of fixing compilation errors on other platforms...

src/libstd/process.rs
src/libstd/sys/cloudabi/shims/process.rs
src/libstd/sys/redox/process.rs
src/libstd/sys/unix/process/mod.rs
src/libstd/sys/unix/process/process_common.rs
src/libstd/sys/wasm/process.rs
src/libstd/sys/windows/process.rs

index 5a06bf45aaabdff434e7f677235dbb69d33eee0a..d5ac2d19e831f81c6fa4b7c15d1c6800493277ab 100644 (file)
@@ -1098,38 +1098,26 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 ///
 /// [RFC #1937]: https://github.com/rust-lang/rfcs/pull/1937
 #[derive(Clone, Copy, Debug)]
-#[unstable(feature = "process_exitcode_placeholder", issue = "43301")]
-pub struct ExitCode(pub i32);
+#[unstable(feature = "process_exitcode_placeholder", issue = "48711")]
+pub struct ExitCode(imp::ExitCode);
 
-#[cfg(target_arch = "wasm32")]
-mod rawexit {
-    pub const SUCCESS: i32 = 0;
-    pub const FAILURE: i32 = 1;
-}
-#[cfg(not(target_arch = "wasm32"))]
-mod rawexit {
-    use libc;
-    pub const SUCCESS: i32 = libc::EXIT_SUCCESS;
-    pub const FAILURE: i32 = libc::EXIT_FAILURE;
-}
-
-#[unstable(feature = "process_exitcode_placeholder", issue = "43301")]
+#[unstable(feature = "process_exitcode_placeholder", issue = "48711")]
 impl ExitCode {
     /// The canonical ExitCode for successful termination on this platform.
     ///
     /// Note that a `()`-returning `main` implicitly results in a successful
     /// termination, so there's no need to return this from `main` unless
     /// you're also returning other possible codes.
-    #[unstable(feature = "process_exitcode_placeholder", issue = "43301")]
-    pub const SUCCESS: ExitCode = ExitCode(rawexit::SUCCESS);
+    #[unstable(feature = "process_exitcode_placeholder", issue = "48711")]
+    pub const SUCCESS: ExitCode = ExitCode(imp::ExitCode::SUCCESS);
 
     /// The canonical ExitCode for unsuccessful termination on this platform.
     ///
     /// If you're only returning this and `SUCCESS` from `main`, consider
     /// instead returning `Err(_)` and `Ok(())` respectively, which will
     /// return the same codes (but will also `eprintln!` the error).
-    #[unstable(feature = "process_exitcode_placeholder", issue = "43301")]
-    pub const FAILURE: ExitCode = ExitCode(rawexit::FAILURE);
+    #[unstable(feature = "process_exitcode_placeholder", issue = "48711")]
+    pub const FAILURE: ExitCode = ExitCode(imp::ExitCode::FAILURE);
 }
 
 impl Child {
@@ -1494,8 +1482,7 @@ fn report(self) -> i32 {
 #[unstable(feature = "termination_trait_lib", issue = "43301")]
 impl Termination for ExitCode {
     fn report(self) -> i32 {
-        let ExitCode(code) = self;
-        code
+        self.0.as_i32()
     }
 }
 
index 52e8c82e2b2393e916c8a56bacfc976fe4f88670..fcd40c15c1708bf77e63559d5103f9461aa3c132 100644 (file)
@@ -126,6 +126,18 @@ fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
+#[derive(PartialEq, Eq, Clone, Copy, Debug)]
+pub struct ExitCode(bool);
+
+impl ExitCode {
+    pub const SUCCESS: ExitCode = ExitCode(false);
+    pub const FAILURE: ExitCode = ExitCode(true);
+
+    pub fn as_i32(&self) -> i32 {
+        self.0 as i32
+    }
+}
+
 pub struct Process(Void);
 
 impl Process {
index 3fd54973896977cef0e348035df8a1a1c5f9ce55..d0b94e14f54e93e1c4bd14ee117ca523b604a45c 100644 (file)
@@ -13,6 +13,7 @@
 use os::unix::ffi::OsStrExt;
 use fmt;
 use io::{self, Error, ErrorKind};
+use libc::{EXIT_SUCCESS, EXIT_FAILURE};
 use path::{Path, PathBuf};
 use sys::fd::FileDesc;
 use sys::fs::{File, OpenOptions};
@@ -480,6 +481,18 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
+#[derive(PartialEq, Eq, Clone, Copy, Debug)]
+pub struct ExitCode(u8);
+
+impl ExitCode {
+    pub const SUCCESS: ExitCode = ExitCode(EXIT_SUCCESS as _);
+    pub const FAILURE: ExitCode = ExitCode(EXIT_FAILURE as _);
+
+    pub fn as_i32(&self) -> i32 {
+        self.0 as i32
+    }
+}
+
 /// The unique id of the process (this should never be negative).
 pub struct Process {
     pid: usize,
index 2a331069bc2c29e3378901a664ee3d80c3892467..d8ac26c45b172982e07543a570e8189237b2f632 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-pub use self::process_common::{Command, ExitStatus, Stdio, StdioPipes};
+pub use self::process_common::{Command, ExitStatus, ExitCode, Stdio, StdioPipes};
 pub use self::process_inner::Process;
 
 mod process_common;
index 7e057401fab70a2a0d41407677e97c90916e9a2b..d0486f06a143af2598f3987ed18054583f4bd552 100644 (file)
@@ -13,7 +13,7 @@
 use ffi::{OsString, OsStr, CString, CStr};
 use fmt;
 use io;
-use libc::{self, c_int, gid_t, uid_t, c_char};
+use libc::{self, c_int, gid_t, uid_t, c_char, EXIT_SUCCESS, EXIT_FAILURE};
 use ptr;
 use sys::fd::FileDesc;
 use sys::fs::{File, OpenOptions};
@@ -393,6 +393,18 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
+#[derive(PartialEq, Eq, Clone, Copy, Debug)]
+pub struct ExitCode(u8);
+
+impl ExitCode {
+    pub const SUCCESS: ExitCode = ExitCode(EXIT_SUCCESS as _);
+    pub const FAILURE: ExitCode = ExitCode(EXIT_FAILURE as _);
+
+    pub fn as_i32(&self) -> i32 {
+        self.0 as i32
+    }
+}
+
 #[cfg(all(test, not(target_os = "emscripten")))]
 mod tests {
     use super::*;
index f3f5de350f176bdb2f71f15a5422a8737ab9d39e..433e9cec7c8accf78195af2536c004396268f89d 100644 (file)
@@ -129,6 +129,18 @@ fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
+#[derive(PartialEq, Eq, Clone, Copy, Debug)]
+pub struct ExitCode(bool);
+
+impl ExitCode {
+    pub const SUCCESS: ExitCode = ExitCode(false);
+    pub const FAILURE: ExitCode = ExitCode(true);
+
+    pub fn as_i32(&self) -> i32 {
+        self.0 as i32
+    }
+}
+
 pub struct Process(Void);
 
 impl Process {
index c93179869a6511786b9771d6e519a22a23cf99d2..f1ab9c4760965e38efcf59dbb4b98ebd603dcca9 100644 (file)
@@ -18,7 +18,7 @@
 use fmt;
 use fs;
 use io::{self, Error, ErrorKind};
-use libc::c_void;
+use libc::{c_void, EXIT_SUCCESS, EXIT_FAILURE};
 use mem;
 use os::windows::ffi::OsStrExt;
 use path::Path;
@@ -408,6 +408,18 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
+#[derive(PartialEq, Eq, Clone, Copy, Debug)]
+pub struct ExitCode(c::DWORD);
+
+impl ExitCode {
+    pub const SUCCESS: ExitCode = ExitCode(EXIT_SUCCESS as _);
+    pub const FAILURE: ExitCode = ExitCode(EXIT_FAILURE as _);
+
+    pub fn as_i32(&self) -> i32 {
+        self.0 as i32
+    }
+}
+
 fn zeroed_startupinfo() -> c::STARTUPINFO {
     c::STARTUPINFO {
         cb: 0,