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.
This commit is contained in:
Garrett Squire 2021-03-24 18:27:56 -07:00 committed by Veikka Tuominen
parent ea4a25287e
commit a6d72fea06
8 changed files with 16 additions and 16 deletions

View File

@ -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) };
}
});

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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 {

View File

@ -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;

View File

@ -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;

View File

@ -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);