Skip to content

Commit

Permalink
update-zig
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Mar 22, 2024
1 parent 418cac6 commit 128855e
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 287 deletions.
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

368 changes: 184 additions & 184 deletions src/backend/kqueue.zig

Large diffs are not rendered by default.

58 changes: 29 additions & 29 deletions src/watcher/async.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const std = @import("std");
const builtin = @import("builtin");
const assert = std.debug.assert;
const os = std.os;
const posix = std.posix;
const common = @import("common.zig");

pub fn Async(comptime xev: type) type {
Expand Down Expand Up @@ -30,20 +30,20 @@ fn AsyncEventFd(comptime xev: type) type {
pub const WaitError = xev.ReadError;

/// eventfd file descriptor
fd: os.fd_t,
fd: posix.fd_t,

/// Create a new async. An async can be assigned to exactly one loop
/// to be woken up. The completion must be allocated in advance.
pub fn init() !Self {
return .{
.fd = try std.os.eventfd(0, 0),
.fd = try std.posix.eventfd(0, 0),
};
}

/// Clean up the async. This will forcibly deinitialize any resources
/// and may result in erroneous wait callbacks to be fired.
pub fn deinit(self: *Self) void {
std.os.close(self.fd);
std.posix.close(self.fd);
}

/// Wait for a message on this async. Note that async messages may be
Expand Down Expand Up @@ -113,7 +113,7 @@ fn AsyncEventFd(comptime xev: type) type {
pub fn notify(self: Self) !void {
// We want to just write "1" in the correct byte order as our host.
const val = @as([8]u8, @bitCast(@as(u64, 1)));
_ = os.write(self.fd, &val) catch |err| switch (err) {
_ = posix.write(self.fd, &val) catch |err| switch (err) {
error.WouldBlock => return,
else => return err,
};
Expand All @@ -136,24 +136,24 @@ fn AsyncMachPort(comptime xev: type) type {
pub const WaitError = xev.Sys.MachPortError;

/// The mach port
port: os.system.mach_port_name_t,
port: posix.system.mach_port_name_t,

/// Create a new async. An async can be assigned to exactly one loop
/// to be woken up. The completion must be allocated in advance.
pub fn init() !Self {
const mach_self = os.system.mach_task_self();
const mach_self = posix.system.mach_task_self();

// Allocate the port
var mach_port: os.system.mach_port_name_t = undefined;
switch (os.system.getKernError(os.system.mach_port_allocate(
var mach_port: posix.system.mach_port_name_t = undefined;
switch (posix.system.getKernError(posix.system.mach_port_allocate(
mach_self,
@intFromEnum(os.system.MACH_PORT_RIGHT.RECEIVE),
@intFromEnum(posix.system.MACH_PORT_RIGHT.RECEIVE),
&mach_port,
))) {
.SUCCESS => {}, // Success
else => return error.MachPortAllocFailed,
}
errdefer _ = os.system.mach_port_deallocate(mach_self, mach_port);
errdefer _ = posix.system.mach_port_deallocate(mach_self, mach_port);

return .{
.port = mach_port,
Expand All @@ -163,8 +163,8 @@ fn AsyncMachPort(comptime xev: type) type {
/// Clean up the async. This will forcibly deinitialize any resources
/// and may result in erroneous wait callbacks to be fired.
pub fn deinit(self: *Self) void {
_ = os.system.mach_port_deallocate(
os.system.mach_task_self(),
_ = posix.system.mach_port_deallocate(
posix.system.mach_task_self(),
self.port,
);
}
Expand Down Expand Up @@ -226,20 +226,20 @@ fn AsyncMachPort(comptime xev: type) type {
}

/// Drain the given mach port. All message bodies are discarded.
fn drain(port: os.system.mach_port_name_t) void {
fn drain(port: posix.system.mach_port_name_t) void {
var message: struct {
header: os.system.mach_msg_header_t,
header: posix.system.mach_msg_header_t,
} = undefined;

while (true) {
switch (os.system.getMachMsgError(os.system.mach_msg(
switch (posix.system.getMachMsgError(posix.system.mach_msg(
&message.header,
os.system.MACH_RCV_MSG | os.system.MACH_RCV_TIMEOUT,
posix.system.MACH_RCV_MSG | posix.system.MACH_RCV_TIMEOUT,
0,
@sizeOf(@TypeOf(message)),
port,
os.system.MACH_MSG_TIMEOUT_NONE,
os.system.MACH_PORT_NULL,
posix.system.MACH_MSG_TIMEOUT_NONE,
posix.system.MACH_PORT_NULL,
))) {
// This means a read would've blocked, so we drained.
.RCV_TIMED_OUT => return,
Expand All @@ -265,24 +265,24 @@ fn AsyncMachPort(comptime xev: type) type {
/// ticking or not).
pub fn notify(self: Self) !void {
// This constructs an empty mach message. It has no data.
var msg: os.system.mach_msg_header_t = .{
.msgh_bits = @intFromEnum(os.system.MACH_MSG_TYPE.MAKE_SEND_ONCE),
.msgh_size = @sizeOf(os.system.mach_msg_header_t),
var msg: posix.system.mach_msg_header_t = .{
.msgh_bits = @intFromEnum(posix.system.MACH_MSG_TYPE.MAKE_SEND_ONCE),
.msgh_size = @sizeOf(posix.system.mach_msg_header_t),
.msgh_remote_port = self.port,
.msgh_local_port = os.system.MACH_PORT_NULL,
.msgh_local_port = posix.system.MACH_PORT_NULL,
.msgh_voucher_port = undefined,
.msgh_id = undefined,
};

return switch (os.system.getMachMsgError(
os.system.mach_msg(
return switch (posix.system.getMachMsgError(
posix.system.mach_msg(
&msg,
os.system.MACH_SEND_MSG,
posix.system.MACH_SEND_MSG,
msg.msgh_size,
0,
os.system.MACH_PORT_NULL,
os.system.MACH_MSG_TIMEOUT_NONE,
os.system.MACH_PORT_NULL,
posix.system.MACH_PORT_NULL,
posix.system.MACH_MSG_TIMEOUT_NONE,
posix.system.MACH_PORT_NULL,
),
)) {
.SUCCESS => {},
Expand Down
4 changes: 2 additions & 2 deletions src/watcher/file.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const std = @import("std");
const builtin = @import("builtin");
const common = @import("common.zig");
const assert = std.debug.assert;
const os = std.os;
const posix = std.posix;
const main = @import("../main.zig");
const stream = @import("stream.zig");

Expand All @@ -27,7 +27,7 @@ const stream = @import("stream.zig");
pub fn File(comptime xev: type) type {
return struct {
const Self = @This();
const FdType = if (xev.backend == .iocp) os.windows.HANDLE else os.socket_t;
const FdType = if (xev.backend == .iocp) std.windows.HANDLE else posix.socket_t;

/// The underlying file
fd: FdType,
Expand Down
34 changes: 17 additions & 17 deletions src/watcher/process.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const std = @import("std");
const builtin = @import("builtin");
const assert = std.debug.assert;
const os = std.os;
const posix = std.posix;
const common = @import("common.zig");

/// Process management, such as waiting for process exit.
Expand Down Expand Up @@ -32,21 +32,21 @@ fn ProcessPidFd(comptime xev: type) type {
};

/// pidfd file descriptor
fd: os.fd_t,
fd: posix.fd_t,

/// Create a new process watcher for the given pid.
pub fn init(pid: os.pid_t) !Self {
pub fn init(pid: posix.pid_t) !Self {
// Note: SOCK_NONBLOCK == PIDFD_NONBLOCK but we should PR that
// over to Zig.
const res = os.linux.pidfd_open(pid, os.SOCK.NONBLOCK);
const fd = switch (os.errno(res)) {
.SUCCESS => @as(os.fd_t, @intCast(res)),
const res = posix.linux.pidfd_open(pid, posix.SOCK.NONBLOCK);
const fd = switch (posix.errno(res)) {
.SUCCESS => @as(posix.fd_t, @intCast(res)),
.INVAL => return error.InvalidArgument,
.MFILE => return error.ProcessFdQuotaExceeded,
.NFILE => return error.SystemFdQuotaExceeded,
.NODEV => return error.SystemResources,
.NOMEM => return error.SystemResources,
else => |err| return os.unexpectedErrno(err),
else => |err| return posix.unexpectedErrno(err),
};

return .{
Expand All @@ -56,7 +56,7 @@ fn ProcessPidFd(comptime xev: type) type {

/// Clean up the process watcher.
pub fn deinit(self: *Self) void {
std.os.close(self.fd);
std.posix.close(self.fd);
}

/// Wait for the process to exit. This will automatically call
Expand All @@ -75,8 +75,8 @@ fn ProcessPidFd(comptime xev: type) type {
) xev.CallbackAction,
) void {
const events: u32 = comptime switch (xev.backend) {
.io_uring => os.POLL.IN,
.epoll => os.linux.EPOLL.IN,
.io_uring => posix.POLL.IN,
.epoll => posix.linux.EPOLL.IN,
else => unreachable,
};

Expand All @@ -102,10 +102,10 @@ fn ProcessPidFd(comptime xev: type) type {

// We need to wait on the pidfd because it is noted as ready
const fd = c_inner.op.poll.fd;
var info: os.linux.siginfo_t = undefined;
const res = os.linux.waitid(.PIDFD, fd, &info, os.linux.W.EXITED);
var info: posix.linux.siginfo_t = undefined;
const res = posix.linux.waitid(.PIDFD, fd, &info, posix.linux.W.EXITED);

break :arg switch (os.errno(res)) {
break :arg switch (posix.errno(res)) {
.SUCCESS => @as(u32, @intCast(info.fields.common.second.sigchld.status)),
.CHILD => error.InvalidChild,

Expand Down Expand Up @@ -143,10 +143,10 @@ fn ProcessKqueue(comptime xev: type) type {
pub const WaitError = xev.Sys.ProcError;

/// The pid to watch.
pid: os.pid_t,
pid: posix.pid_t,

/// Create a new process watcher for the given pid.
pub fn init(pid: os.pid_t) !Self {
pub fn init(pid: posix.pid_t) !Self {
return .{
.pid = pid,
};
Expand Down Expand Up @@ -176,7 +176,7 @@ fn ProcessKqueue(comptime xev: type) type {
.op = .{
.proc = .{
.pid = self.pid,
.flags = os.system.NOTE_EXIT | os.system.NOTE_EXITSTATUS,
.flags = posix.system.NOTE_EXIT | posix.system.NOTE_EXITSTATUS,
},
},

Expand Down Expand Up @@ -215,7 +215,7 @@ fn ProcessIocp(comptime xev: type) type {
job: windows.HANDLE,
process: windows.HANDLE,

pub fn init(process: os.pid_t) !Self {
pub fn init(process: posix.pid_t) !Self {
const current_process = windows.kernel32.GetCurrentProcess();

// Duplicate the process handle so we don't rely on the caller keeping it alive
Expand Down
24 changes: 12 additions & 12 deletions src/watcher/stream.zig
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ pub fn GenericStream(comptime xev: type) type {
const Self = @This();

/// The underlying file
fd: std.os.fd_t,
fd: std.posix.fd_t,

pub usingnamespace Stream(xev, Self, .{
.close = true,
Expand All @@ -515,7 +515,7 @@ pub fn GenericStream(comptime xev: type) type {
});

/// Initialize a generic stream from a file descriptor.
pub fn initFd(fd: std.os.fd_t) Self {
pub fn initFd(fd: std.posix.fd_t) Self {
return .{
.fd = fd,
};
Expand Down Expand Up @@ -764,8 +764,8 @@ const Pty = struct {
/// to the master/slave side respectively, and while that terminology is
/// the officially used terminology of the syscall, I will use parent/child
/// here.
parent: std.os.fd_t,
child: std.os.fd_t,
parent: std.posix.fd_t,
child: std.posix.fd_t,

/// Redeclare this winsize struct so we can just use a Zig struct. This
/// layout should be correct on all tested platforms.
Expand All @@ -778,8 +778,8 @@ const Pty = struct {

// libc pty.h
extern "c" fn openpty(
parent: *std.os.fd_t,
child: *std.os.fd_t,
parent: *std.posix.fd_t,
child: *std.posix.fd_t,
name: ?[*]u8,
termios: ?*const anyopaque, // termios but we don't use it
winsize: ?*const Winsize,
Expand All @@ -794,8 +794,8 @@ const Pty = struct {
.ws_ypixel = 600,
};

var parent_fd: std.os.fd_t = undefined;
var child_fd: std.os.fd_t = undefined;
var parent_fd: std.posix.fd_t = undefined;
var child_fd: std.posix.fd_t = undefined;
if (openpty(
&parent_fd,
&child_fd,
Expand All @@ -805,8 +805,8 @@ const Pty = struct {
) < 0)
return error.OpenptyFailed;
errdefer {
_ = std.os.system.close(parent_fd);
_ = std.os.system.close(child_fd);
_ = std.posix.system.close(parent_fd);
_ = std.posix.system.close(child_fd);
}

return .{
Expand All @@ -816,7 +816,7 @@ const Pty = struct {
}

pub fn deinit(self: *Pty) void {
std.os.close(self.parent);
std.os.close(self.child);
std.posix.close(self.parent);
std.posix.close(self.child);
}
};

0 comments on commit 128855e

Please sign in to comment.