Commit a6d72fea06

Garrett Squire <github@garrettsquire.com>
2021-03-25 02:27:56
Make std.ChildProcess exit code u8 to match std.process.exit
This patch adjusts the exit code for a child process to be a u8. Since the WEXITSTATUS macro returns the lower eight bits, it's safe to assume that we can truncate the returned u32.
1 parent ea4a252
lib/std/os/bits/darwin.zig
@@ -844,8 +844,8 @@ fn wstatus(x: u32) u32 {
     return x & 0o177;
 }
 const wstopped = 0o177;
-pub fn WEXITSTATUS(x: u32) u32 {
-    return x >> 8;
+pub fn WEXITSTATUS(x: u32) u8 {
+    return @intCast(u8, x >> 8);
 }
 pub fn WTERMSIG(x: u32) u32 {
     return wstatus(x);
lib/std/os/bits/dragonfly.zig
@@ -332,8 +332,8 @@ pub const AT_REMOVEDIR = 2;
 pub const AT_EACCESS = 4;
 pub const AT_SYMLINK_FOLLOW = 8;
 
-pub fn WEXITSTATUS(s: u32) u32 {
-    return (s & 0xff00) >> 8;
+pub fn WEXITSTATUS(s: u32) u8 {
+    return @intCast(u8, (s & 0xff00) >> 8);
 }
 pub fn WTERMSIG(s: u32) u32 {
     return s & 0x7f;
lib/std/os/bits/freebsd.zig
@@ -729,8 +729,8 @@ pub const TIOCGSID = 0x40047463;
 pub const TIOCGPTN = 0x4004740f;
 pub const TIOCSIG = 0x2004745f;
 
-pub fn WEXITSTATUS(s: u32) u32 {
-    return (s & 0xff00) >> 8;
+pub fn WEXITSTATUS(s: u32) u8 {
+    return @intCast(u8, (s & 0xff00) >> 8);
 }
 pub fn WTERMSIG(s: u32) u32 {
     return s & 0x7f;
lib/std/os/bits/haiku.zig
@@ -661,8 +661,8 @@ pub const TIOCSBRK = 0x8020;
 pub const TIOCCBRK = 0x8021;
 pub const TIOCGSID = 0x8024;
 
-pub fn WEXITSTATUS(s: u32) u32 {
-    return (s & 0xff);
+pub fn WEXITSTATUS(s: u32) u8 {
+    return @intCast(u8, s & 0xff);
 }
 
 pub fn WTERMSIG(s: u32) u32 {
lib/std/os/bits/linux.zig
@@ -1043,8 +1043,8 @@ pub const TFD_CLOEXEC = O_CLOEXEC;
 pub const TFD_TIMER_ABSTIME = 1;
 pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1);
 
-pub fn WEXITSTATUS(s: u32) u32 {
-    return (s & 0xff00) >> 8;
+pub fn WEXITSTATUS(s: u32) u8 {
+    return @intCast(u8, (s & 0xff00) >> 8);
 }
 pub fn WTERMSIG(s: u32) u32 {
     return s & 0x7f;
lib/std/os/bits/netbsd.zig
@@ -686,8 +686,8 @@ pub const TIOCSWINSZ = 0x80087467;
 pub const TIOCUCNTL = 0x80047466;
 pub const TIOCXMTFRAME = 0x80087444;
 
-pub fn WEXITSTATUS(s: u32) u32 {
-    return (s >> 8) & 0xff;
+pub fn WEXITSTATUS(s: u32) u8 {
+    return @intCast(u8, (s >> 8) & 0xff);
 }
 pub fn WTERMSIG(s: u32) u32 {
     return s & 0x7f;
lib/std/os/bits/openbsd.zig
@@ -669,8 +669,8 @@ pub const TIOCSWINSZ = 0x80087467;
 pub const TIOCUCNTL = 0x80047466;
 pub const TIOCXMTFRAME = 0x80087444;
 
-pub fn WEXITSTATUS(s: u32) u32 {
-    return (s >> 8) & 0xff;
+pub fn WEXITSTATUS(s: u32) u8 {
+    return @intCast(u8, (s >> 8) & 0xff);
 }
 pub fn WTERMSIG(s: u32) u32 {
     return (s & 0x7f);
lib/std/child_process.zig
@@ -78,7 +78,7 @@ pub const ChildProcess = struct {
     } || os.ExecveError || os.SetIdError || os.ChangeCurDirError || windows.CreateProcessError || windows.WaitForSingleObjectError;
 
     pub const Term = union(enum) {
-        Exited: u32,
+        Exited: u8,
         Signal: u32,
         Stopped: u32,
         Unknown: u32,
@@ -347,7 +347,7 @@ pub const ChildProcess = struct {
             if (windows.kernel32.GetExitCodeProcess(self.handle, &exit_code) == 0) {
                 break :x Term{ .Unknown = 0 };
             } else {
-                break :x Term{ .Exited = exit_code };
+                break :x Term{ .Exited = @truncate(u8, exit_code) };
             }
         });