mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 21:01:52 +00:00
misc code cleanup
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user