From a6d72fea06364da26b4efacb188303c5bddf5da3 Mon Sep 17 00:00:00 2001 From: Garrett Squire Date: Wed, 24 Mar 2021 18:27:56 -0700 Subject: [PATCH] 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. --- lib/std/child_process.zig | 4 ++-- lib/std/os/bits/darwin.zig | 4 ++-- lib/std/os/bits/dragonfly.zig | 4 ++-- lib/std/os/bits/freebsd.zig | 4 ++-- lib/std/os/bits/haiku.zig | 4 ++-- lib/std/os/bits/linux.zig | 4 ++-- lib/std/os/bits/netbsd.zig | 4 ++-- lib/std/os/bits/openbsd.zig | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/std/child_process.zig b/lib/std/child_process.zig index 10bfe6d3f2..1cdb3ef34c 100644 --- a/lib/std/child_process.zig +++ b/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) }; } }); diff --git a/lib/std/os/bits/darwin.zig b/lib/std/os/bits/darwin.zig index 2f188e924e..be77722c05 100644 --- a/lib/std/os/bits/darwin.zig +++ b/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); diff --git a/lib/std/os/bits/dragonfly.zig b/lib/std/os/bits/dragonfly.zig index 5b61db9e7f..9f6d3088ba 100644 --- a/lib/std/os/bits/dragonfly.zig +++ b/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; diff --git a/lib/std/os/bits/freebsd.zig b/lib/std/os/bits/freebsd.zig index c3bcafaa65..6d227a168a 100644 --- a/lib/std/os/bits/freebsd.zig +++ b/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; diff --git a/lib/std/os/bits/haiku.zig b/lib/std/os/bits/haiku.zig index bd677e22e8..cb31166608 100644 --- a/lib/std/os/bits/haiku.zig +++ b/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 { diff --git a/lib/std/os/bits/linux.zig b/lib/std/os/bits/linux.zig index 8887e9d223..d4491da6d0 100644 --- a/lib/std/os/bits/linux.zig +++ b/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; diff --git a/lib/std/os/bits/netbsd.zig b/lib/std/os/bits/netbsd.zig index 168d0f1c48..747978de65 100644 --- a/lib/std/os/bits/netbsd.zig +++ b/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; diff --git a/lib/std/os/bits/openbsd.zig b/lib/std/os/bits/openbsd.zig index 2ff81fae0d..3b9f8ccd4a 100644 --- a/lib/std/os/bits/openbsd.zig +++ b/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);