From 7e965b3e61ac00a40c3945798bdbef39bbb45104 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Fri, 26 Jan 2024 21:12:10 -0800 Subject: [PATCH] misc code cleanup --- src/bun.js/api/bun/process.zig | 11 ++--------- src/bun.zig | 2 ++ src/deps/libuv.zig | 36 ++++++++-------------------------- 3 files changed, 12 insertions(+), 37 deletions(-) diff --git a/src/bun.js/api/bun/process.zig b/src/bun.js/api/bun/process.zig index a371f0e53d..36afd18a4e 100644 --- a/src/bun.js/api/bun/process.zig +++ b/src/bun.js/api/bun/process.zig @@ -96,28 +96,21 @@ pub const ProcessExitHandler = struct { this.ptr = TaggedPointer.init(ptr); } - pub fn call(this: *const ProcessExitHandler, comptime ProcessType: type, process: *ProcessType, status: Status, rusage: *const Rusage) void { + pub fn call(this: *const ProcessExitHandler, process: *Process, status: Status, rusage: *const Rusage) void { if (this.ptr.isNull()) { return; } switch (this.ptr.tag()) { .Subprocess => { - if (comptime ProcessType != Process) - unreachable; const subprocess = this.ptr.as(Subprocess); subprocess.onProcessExit(process, status, rusage); }, .LifecycleScriptSubprocess => { - if (comptime ProcessType != Process) - unreachable; const subprocess = this.ptr.as(LifecycleScriptSubprocess); subprocess.onProcessExit(process, status, rusage); }, @field(TaggedPointer.Tag, bun.meta.typeBaseName(@typeName(ShellSubprocess))) => { - if (comptime ProcessType != Process) - unreachable; - const subprocess = this.ptr.as(ShellSubprocess); subprocess.onProcessExit(process, status, rusage); }, @@ -186,7 +179,7 @@ pub const Process = struct { this.detach(); } - exit_handler.call(Process, this, status, rusage); + exit_handler.call(this, status, rusage); } pub fn signalCode(this: *const Process) ?bun.SignalCode { diff --git a/src/bun.zig b/src/bun.zig index 2d2aa0ed9a..79222d66b2 100644 --- a/src/bun.zig +++ b/src/bun.zig @@ -915,6 +915,8 @@ pub const SignalCode = enum(u8) { return null; } + /// Shell scripts use exit codes 128 + signal number + /// https://tldp.org/LDP/abs/html/exitcodes.html pub fn toExitCode(value: SignalCode) ?u8 { return switch (@intFromEnum(value)) { 1...31 => 128 +% @intFromEnum(value), diff --git a/src/deps/libuv.zig b/src/deps/libuv.zig index f21eaf3a0e..5093df3368 100644 --- a/src/deps/libuv.zig +++ b/src/deps/libuv.zig @@ -415,7 +415,7 @@ fn HandleMixin(comptime Type: type) type { pub fn setData(handle: *Type, ptr: ?*anyopaque) void { uv_handle_set_data(@ptrCast(handle), ptr); } - pub fn close(this: *Type, cb: uv_close_cb) void { + pub fn close(this: *Type, cb: *const fn (*Type) callconv(.C) void) void { uv_close(@ptrCast(this), @ptrCast(cb)); } @@ -435,6 +435,10 @@ fn HandleMixin(comptime Type: type) type { return uv_is_closing(@ptrCast(this)) != 0; } + pub fn isClosed(this: *const Type) bool { + return uv_is_closed(@ptrCast(this)) != 0; + } + pub fn isActive(this: *const Type) bool { return uv_is_active(@ptrCast(this)) != 0; } @@ -974,6 +978,8 @@ pub const struct_uv_stream_s = extern struct { activecnt: c_int, read_req: uv_read_t, stream: union_unnamed_384, + + pub usingnamespace HandleMixin(@This()); }; const union_unnamed_390 = extern union { fd: c_int, @@ -1353,33 +1359,7 @@ pub const uv_process = extern struct { process_handle: HANDLE, exit_cb_pending: u8, - pub fn isActive(this: *const @This()) bool { - return uv_is_active(@as(*const uv_handle_t, @alignCast(@ptrCast(this)))) != 0; - } - - pub fn isClosing(this: *const @This()) bool { - return uv_is_closing(@as(*const uv_handle_t, @alignCast(@ptrCast(this)))) != 0; - } - - pub fn isClosed(this: *const @This()) bool { - return uv_is_closed(@as(*const uv_handle_t, @alignCast(@ptrCast(this)))) != 0; - } - - pub fn close(this: *@This(), cb: *const fn (*uv_process_t) callconv(.C) void) void { - uv_close(@alignCast(@ptrCast(this)), @alignCast(@ptrCast(cb))); - } - - pub fn ref(this: *@This()) void { - uv_ref(@alignCast(@ptrCast(this))); - } - - pub fn unref(this: *@This()) void { - uv_unref(@alignCast(@ptrCast(this))); - } - - pub fn hasRef(this: *const @This()) bool { - return uv_has_ref(@alignCast(@ptrCast(this))) != 0; - } + pub usingnamespace HandleMixin(@This()); pub fn kill(this: *@This(), signum: c_int) ReturnCode { return uv_process_kill(@alignCast(@ptrCast(this)), signum);