aboutsummaryrefslogtreecommitdiff
path: root/src/io
diff options
context:
space:
mode:
authorGravatar Dylan Conway <35280289+dylan-conway@users.noreply.github.com> 2023-07-18 01:20:20 -0700
committerGravatar GitHub <noreply@github.com> 2023-07-18 01:20:20 -0700
commit661355546a4658ea927bfd70698577c1db301243 (patch)
tree2b8d33ea64ab6f23c5f1729d106076cbadd44c89 /src/io
parent71f1aa1802360d74d823b1a1544454b199b27898 (diff)
downloadbun-661355546a4658ea927bfd70698577c1db301243.tar.gz
bun-661355546a4658ea927bfd70698577c1db301243.tar.zst
bun-661355546a4658ea927bfd70698577c1db301243.zip
zig upgrade (#3667)
* upgrade * more fixes * Bump Zig --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/io')
-rw-r--r--src/io/io_darwin.zig56
-rw-r--r--src/io/io_linux.zig80
-rw-r--r--src/io/time.zig2
3 files changed, 69 insertions, 69 deletions
diff --git a/src/io/io_darwin.zig b/src/io/io_darwin.zig
index 9ebc6f4d6..c44b285c2 100644
--- a/src/io/io_darwin.zig
+++ b/src/io/io_darwin.zig
@@ -250,7 +250,7 @@ pub fn asError(err: anytype) Errno {
err;
return switch (int) {
- 1...errno_map.len => |val| errno_map[@intCast(u8, val)],
+ 1...errno_map.len => |val| errno_map[@as(u8, @intCast(val))],
else => error.Unexpected,
};
}
@@ -402,7 +402,7 @@ pub const Syscall = struct {
pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) Errno!usize {
const rc = darwin.@"fcntl$NOCANCEL"(fd, cmd, arg);
return switch (darwin.getErrno(rc)) {
- .SUCCESS => @intCast(usize, rc),
+ .SUCCESS => @as(usize, @intCast(rc)),
else => |err| asError(err),
};
}
@@ -445,7 +445,7 @@ pub const Syscall = struct {
} || Errno;
pub fn setsockopt(fd: socket_t, level: u32, optname: u32, opt: []const u8) SetSockOptError!void {
- switch (darwin.getErrno(darwin.setsockopt(fd, level, optname, opt.ptr, @intCast(socklen_t, opt.len)))) {
+ switch (darwin.getErrno(darwin.setsockopt(fd, level, optname, opt.ptr, @as(socklen_t, @intCast(opt.len))))) {
.SUCCESS => {},
.DOM => return error.TimeoutTooBig,
.ISCONN => return error.AlreadyConnected,
@@ -462,7 +462,7 @@ pub const Syscall = struct {
const rc = darwin.socket(domain, filtered_sock_type, protocol);
switch (darwin.getErrno(rc)) {
.SUCCESS => {
- const fd = @intCast(fd_t, rc);
+ const fd = @as(fd_t, @intCast(rc));
try setSockFlags(fd, socket_type);
return fd;
},
@@ -540,7 +540,7 @@ pub const Waker = struct {
return asError(std.c.getErrno(count));
}
- return @intCast(usize, count);
+ return @as(usize, @intCast(count));
}
extern fn io_darwin_create_machport(
@@ -627,7 +627,7 @@ pub const UserFilterWaker = struct {
return asError(std.c.getErrno(errno));
}
- return @intCast(u64, errno);
+ return @as(u64, @intCast(errno));
}
pub fn init(_: std.mem.Allocator) !UserFilterWaker {
@@ -646,7 +646,7 @@ pub const UserFilterWaker = struct {
&events,
1,
&events,
- @intCast(c_int, events.len),
+ @as(c_int, @intCast(events.len)),
0,
&timespec,
);
@@ -742,16 +742,16 @@ fn flush(self: *IO, comptime _: @Type(.EnumLiteral)) !void {
// We need to wait (not poll) on kevent if there's nothing to submit or complete.
if (next_timeout) |timeout_ns| {
- ts.tv_nsec = @intCast(@TypeOf(ts.tv_nsec), timeout_ns % std.time.ns_per_s);
- ts.tv_sec = @intCast(@TypeOf(ts.tv_sec), timeout_ns / std.time.ns_per_s);
+ ts.tv_nsec = @as(@TypeOf(ts.tv_nsec), @intCast(timeout_ns % std.time.ns_per_s));
+ ts.tv_sec = @as(@TypeOf(ts.tv_sec), @intCast(timeout_ns / std.time.ns_per_s));
}
const new_events_ = std.os.system.kevent64(
self.waker.kq,
&events,
- @intCast(c_int, change_events),
+ @as(c_int, @intCast(change_events)),
&events,
- @intCast(c_int, events.len),
+ @as(c_int, @intCast(events.len)),
0,
if (next_timeout != null) &ts else null,
);
@@ -759,7 +759,7 @@ fn flush(self: *IO, comptime _: @Type(.EnumLiteral)) !void {
if (new_events_ < 0) {
return std.debug.panic("kevent() failed {s}", .{@tagName(std.c.getErrno(new_events_))});
}
- const new_events = @intCast(usize, new_events_);
+ const new_events = @as(usize, @intCast(new_events_));
// Mark the io events submitted only after kevent() successfully processed them
self.io_pending.out = io_pending;
@@ -776,7 +776,7 @@ fn flush(self: *IO, comptime _: @Type(.EnumLiteral)) !void {
continue;
}
- const completion = @ptrFromInt(*Completion, kevent.udata);
+ const completion = @as(*Completion, @ptrFromInt(kevent.udata));
completion.next = null;
self.completed.push(completion);
}
@@ -836,9 +836,9 @@ fn flush_io(_: *IO, events: []Kevent64, io_pending_top: *?*Completion) usize {
kevent.* = .{
.ext = [2]u64{ 0, 0 },
- .ident = @intCast(u32, event_info[0]),
- .filter = @intCast(i16, event_info[1]),
- .flags = @intCast(u16, event_info[2]),
+ .ident = @as(u32, @intCast(event_info[0])),
+ .filter = @as(i16, @intCast(event_info[1])),
+ .flags = @as(u16, @intCast(event_info[2])),
.fflags = 0,
.data = 0,
.udata = @intFromPtr(completion),
@@ -999,7 +999,7 @@ fn submitWithIncrementPending(
// Complete the Completion
return callback(
- @ptrFromInt(Context, @intFromPtr(_completion.context)),
+ @as(Context, @ptrFromInt(@intFromPtr(_completion.context))),
_completion,
result,
);
@@ -1023,7 +1023,7 @@ pub const AcceptError = os.AcceptError || os.SetSockOptError;
// -- NOT DONE YET
pub fn eventfd(self: *IO) os.fd_t {
- return @intCast(os.fd_t, self.last_event_fd.fetchAdd(1, .Monotonic));
+ return @as(os.fd_t, @intCast(self.last_event_fd.fetchAdd(1, .Monotonic)));
}
// -- NOT DONE YET
@@ -1204,10 +1204,10 @@ pub fn connect(
true => brk: {
var err_code: i32 = undefined;
var size: u32 = @sizeOf(u32);
- const rc = system.getsockopt(op.socket, os.SOL.SOCKET, os.SO.ERROR, @ptrCast([*]u8, &err_code), &size);
+ const rc = system.getsockopt(op.socket, os.SOL.SOCKET, os.SO.ERROR, @as([*]u8, @ptrCast(&err_code)), &size);
assert(size == 4);
break :brk switch (darwin.getErrno(rc)) {
- .SUCCESS => switch (@enumFromInt(os.E, err_code)) {
+ .SUCCESS => switch (@as(os.E, @enumFromInt(err_code))) {
.SUCCESS => {},
.ACCES => error.PermissionDenied,
.PERM => error.PermissionDenied,
@@ -1306,7 +1306,7 @@ pub fn openSync(
file_path: [:0]const u8,
flags: os.mode_t,
) OpenError!fd_t {
- return Syscall.open(file_path, @intCast(c_uint, flags));
+ return Syscall.open(file_path, @as(c_uint, @intCast(flags)));
}
pub const ReadError = error{
@@ -1343,7 +1343,7 @@ pub fn read(
.{
.fd = fd,
.buf = buffer.ptr,
- .len = @intCast(u32, buffer_limit(buffer.len)),
+ .len = @as(u32, @intCast(buffer_limit(buffer.len))),
.offset = offset_,
.positional = offset != null,
},
@@ -1356,7 +1356,7 @@ pub fn read(
op.len,
);
return switch (@intFromEnum(os.errno(rc))) {
- 0 => @intCast(usize, rc),
+ 0 => @as(usize, @intCast(rc)),
os.EINTR => continue,
os.EAGAIN => error.WouldBlock,
os.EBADF => error.NotOpenForReading,
@@ -1405,13 +1405,13 @@ pub fn recv(
.{
.socket = socket,
.buf = buffer.ptr,
- .len = @intCast(u32, buffer_limit(buffer.len)),
+ .len = @as(u32, @intCast(buffer_limit(buffer.len))),
},
struct {
fn doOperation(op: anytype) RecvError!usize {
const rc = system.@"recvfrom$NOCANCEL"(op.socket, op.buf, op.len, 0, null, null);
return switch (system.getErrno(rc)) {
- .SUCCESS => @intCast(usize, rc),
+ .SUCCESS => @as(usize, @intCast(rc)),
.AGAIN => error.WouldBlock,
.NOMEM => error.SystemResources,
.CONNREFUSED => error.ConnectionRefused,
@@ -1463,14 +1463,14 @@ pub fn send(
.{
.socket = socket,
.buf = buffer.ptr,
- .len = @intCast(u32, buffer_limit(buffer.len)),
+ .len = @as(u32, @intCast(buffer_limit(buffer.len))),
.flags = 0,
},
struct {
fn doOperation(op: anytype) SendError!usize {
const rc = system.@"sendto$NOCANCEL"(op.socket, op.buf, op.len, op.flags, null, 0);
return switch (system.getErrno(rc)) {
- .SUCCESS => @intCast(usize, rc),
+ .SUCCESS => @as(usize, @intCast(rc)),
.ACCES => error.AccessDenied,
.AGAIN => error.WouldBlock,
.ALREADY => error.FastOpenAlreadyInProgress,
@@ -1578,7 +1578,7 @@ pub fn write(
.{
.fd = fd,
.buf = buffer.ptr,
- .len = @intCast(u32, buffer_limit(buffer.len)),
+ .len = @as(u32, @intCast(buffer_limit(buffer.len))),
.offset = offset,
},
struct {
diff --git a/src/io/io_linux.zig b/src/io/io_linux.zig
index 7603eabfd..8f054490b 100644
--- a/src/io/io_linux.zig
+++ b/src/io/io_linux.zig
@@ -432,7 +432,7 @@ pub fn asError(err: anytype) Errno {
else
err;
return switch (errnum) {
- 1...errno_map.len => errno_map[@intCast(u8, errnum)],
+ 1...errno_map.len => errno_map[@as(u8, @intCast(errnum))],
else => error.Unexpected,
};
}
@@ -660,7 +660,7 @@ fn flush_completions(self: *IO, wait_nr: u32, timeouts: *usize, etime: *bool) !v
if (-cqe.res == os.ETIME) etime.* = true;
continue;
}
- const completion = @ptrFromInt(*Completion, @intCast(usize, cqe.user_data));
+ const completion = @as(*Completion, @ptrFromInt(@as(usize, @intCast(cqe.user_data))));
completion.result = cqe.res;
// We do not run the completion here (instead appending to a linked list) to avoid:
// * recursion through `flush_submissions()` and `flush_completions()`,
@@ -804,7 +804,7 @@ pub const Completion = struct {
os.EPERM => error.PermissionDenied,
os.EPROTO => error.ProtocolFailure,
else => |errno| asError(errno),
- } else @intCast(os.socket_t, completion.result);
+ } else @as(os.socket_t, @intCast(completion.result));
completion.callback(completion.context, completion, &result);
},
@@ -843,7 +843,7 @@ pub const Completion = struct {
os.EEXIST => error.PathAlreadyExists,
os.EBUSY => error.DeviceBusy,
else => |errno| asError(errno),
- } else @intCast(linux.fd_t, completion.result);
+ } else @as(linux.fd_t, @intCast(completion.result));
completion.callback(completion.context, completion, &result);
},
.connect => {
@@ -904,7 +904,7 @@ pub const Completion = struct {
os.EOVERFLOW => error.Unseekable,
os.ESPIPE => error.Unseekable,
else => |errno| asError(errno),
- } else @intCast(usize, completion.result);
+ } else @as(usize, @intCast(completion.result));
completion.callback(completion.context, completion, &result);
},
.readev, .recv => {
@@ -920,7 +920,7 @@ pub const Completion = struct {
os.ENOTSOCK => error.FileDescriptorNotASocket,
os.ECONNRESET => error.ConnectionResetByPeer,
else => |errno| asError(errno),
- } else @intCast(usize, completion.result);
+ } else @as(usize, @intCast(completion.result));
completion.callback(completion.context, completion, &result);
},
.writev, .send => {
@@ -942,7 +942,7 @@ pub const Completion = struct {
os.EOPNOTSUPP => error.OperationNotSupported,
os.EPIPE => error.BrokenPipe,
else => |errno| asError(errno),
- } else @intCast(usize, completion.result);
+ } else @as(usize, @intCast(completion.result));
completion.callback(completion.context, completion, &result);
},
.timeout => {
@@ -977,7 +977,7 @@ pub const Completion = struct {
os.EPIPE => error.BrokenPipe,
os.ESPIPE => error.Unseekable,
else => |errno| asError(errno),
- } else @intCast(usize, completion.result);
+ } else @as(usize, @intCast(completion.result));
completion.callback(completion.context, completion, &result);
},
}
@@ -988,7 +988,7 @@ pub const Waker = struct {
fd: os.fd_t,
pub fn init(allocator: std.mem.Allocator) !Waker {
- return initWithFileDescriptor(allocator, @intCast(os.fd_t, try std.os.eventfd(0, 0)));
+ return initWithFileDescriptor(allocator, @as(os.fd_t, @intCast(try std.os.eventfd(0, 0))));
}
pub fn initWithFileDescriptor(_: std.mem.Allocator, fd: os.fd_t) Waker {
@@ -999,15 +999,15 @@ pub const Waker = struct {
pub fn wait(this: Waker) !u64 {
var bytes: usize = 0;
- _ = std.os.read(this.fd, @ptrCast(*[8]u8, &bytes)) catch 0;
- return @intCast(u64, bytes);
+ _ = std.os.read(this.fd, @as(*[8]u8, @ptrCast(&bytes))) catch 0;
+ return @as(u64, @intCast(bytes));
}
pub fn wake(this: *const Waker) !void {
var bytes: usize = 1;
_ = std.os.write(
this.fd,
- @ptrCast(*[8]u8, &bytes),
+ @as(*[8]u8, @ptrCast(&bytes)),
) catch 0;
}
};
@@ -1107,9 +1107,9 @@ pub fn accept(
.callback = struct {
fn wrapper(ctx: ?*anyopaque, comp: *Completion, res: *const anyopaque) void {
callback(
- @ptrFromInt(Context, @intFromPtr(ctx)),
+ @as(Context, @ptrFromInt(@intFromPtr(ctx))),
comp,
- @ptrFromInt(*const AcceptError!os.socket_t, @intFromPtr(res)).*,
+ @as(*const AcceptError!os.socket_t, @ptrFromInt(@intFromPtr(res))).*,
);
}
}.wrapper,
@@ -1149,9 +1149,9 @@ pub fn close(
.callback = struct {
fn wrapper(ctx: ?*anyopaque, comp: *Completion, res: *const anyopaque) void {
callback(
- @ptrFromInt(Context, @intFromPtr(ctx)),
+ @as(Context, @ptrFromInt(@intFromPtr(ctx))),
comp,
- @ptrFromInt(*const CloseError!void, @intFromPtr(res)).*,
+ @as(*const CloseError!void, @ptrFromInt(@intFromPtr(res))).*,
);
}
}.wrapper,
@@ -1160,7 +1160,7 @@ pub fn close(
if (features.close_blocking) {
const rc = linux.close(fd);
- completion.result = @intCast(i32, rc);
+ completion.result = @as(i32, @intCast(rc));
self.next_tick.push(completion);
return;
}
@@ -1206,9 +1206,9 @@ pub fn connect(
.callback = struct {
fn wrapper(ctx: ?*anyopaque, comp: *Completion, res: *const anyopaque) void {
callback(
- @ptrFromInt(Context, @intFromPtr(ctx)),
+ @as(Context, @ptrFromInt(@intFromPtr(ctx))),
comp,
- @ptrFromInt(*const ConnectError!void, @intFromPtr(res)).*,
+ @as(*const ConnectError!void, @ptrFromInt(@intFromPtr(res))).*,
);
}
}.wrapper,
@@ -1222,7 +1222,7 @@ pub fn connect(
if (features.connect_blocking) {
const rc = linux.connect(socket, &address.any, address.getOsSockLen());
- completion.result = @intCast(i32, rc);
+ completion.result = @as(i32, @intCast(rc));
self.completed.push(completion);
return;
}
@@ -1257,9 +1257,9 @@ pub fn fsync(
.callback = struct {
fn wrapper(ctx: ?*anyopaque, comp: *Completion, res: *const anyopaque) void {
callback(
- @ptrFromInt(Context, @intFromPtr(ctx)),
+ @as(Context, @ptrFromInt(@intFromPtr(ctx))),
comp,
- @ptrFromInt(*const FsyncError!void, @intFromPtr(res)).*,
+ @as(*const FsyncError!void, @ptrFromInt(@intFromPtr(res))).*,
);
}
}.wrapper,
@@ -1303,9 +1303,9 @@ pub fn read(
.callback = struct {
fn wrapper(ctx: ?*anyopaque, comp: *Completion, res: *const anyopaque) void {
callback(
- @ptrFromInt(Context, @intFromPtr(ctx)),
+ @as(Context, @ptrFromInt(@intFromPtr(ctx))),
comp,
- @ptrFromInt(*const ReadError!usize, @intFromPtr(res)).*,
+ @as(*const ReadError!usize, @ptrFromInt(@intFromPtr(res))).*,
);
}
}.wrapper,
@@ -1355,9 +1355,9 @@ pub fn recv(
.callback = struct {
fn wrapper(ctx: ?*anyopaque, comp: *Completion, res: *const anyopaque) void {
callback(
- @ptrFromInt(Context, @intFromPtr(ctx)),
+ @as(Context, @ptrFromInt(@intFromPtr(ctx))),
comp,
- @ptrFromInt(*const RecvError!usize, @intFromPtr(res)).*,
+ @as(*const RecvError!usize, @ptrFromInt(@intFromPtr(res))).*,
);
}
}.wrapper,
@@ -1390,9 +1390,9 @@ pub fn readev(
.callback = struct {
fn wrapper(ctx: ?*anyopaque, comp: *Completion, res: *const anyopaque) void {
callback(
- @ptrFromInt(Context, @intFromPtr(ctx)),
+ @as(Context, @ptrFromInt(@intFromPtr(ctx))),
comp,
- @ptrFromInt(*const RecvError!usize, @intFromPtr(res)).*,
+ @as(*const RecvError!usize, @ptrFromInt(@intFromPtr(res))).*,
);
}
}.wrapper,
@@ -1446,9 +1446,9 @@ pub fn send(
.callback = struct {
fn wrapper(ctx: ?*anyopaque, comp: *Completion, res: *const anyopaque) void {
callback(
- @ptrFromInt(Context, @intFromPtr(ctx)),
+ @as(Context, @ptrFromInt(@intFromPtr(ctx))),
comp,
- @ptrFromInt(*const SendError!usize, @intFromPtr(res)).*,
+ @as(*const SendError!usize, @ptrFromInt(@intFromPtr(res))).*,
);
}
}.wrapper,
@@ -1538,16 +1538,16 @@ pub fn open(
.callback = struct {
fn wrapper(ctx: ?*anyopaque, comp: *Completion, res: *const anyopaque) void {
callback(
- @ptrFromInt(Context, @intFromPtr(ctx)),
+ @as(Context, @ptrFromInt(@intFromPtr(ctx))),
comp,
- @ptrFromInt(*const OpenError!linux.fd_t, @intFromPtr(res)).*,
+ @as(*const OpenError!linux.fd_t, @ptrFromInt(@intFromPtr(res))).*,
);
}
}.wrapper,
.operation = .{
.open = .{
.path = path,
- .flags = @intCast(u32, flags),
+ .flags = @as(u32, @intCast(flags)),
.mode = mode,
},
},
@@ -1575,9 +1575,9 @@ pub fn writev(
.callback = struct {
fn wrapper(ctx: ?*anyopaque, comp: *Completion, res: *const anyopaque) void {
callback(
- @ptrFromInt(Context, @intFromPtr(ctx)),
+ @as(Context, @ptrFromInt(@intFromPtr(ctx))),
comp,
- @ptrFromInt(*const SendError!usize, @intFromPtr(res)).*,
+ @as(*const SendError!usize, @ptrFromInt(@intFromPtr(res))).*,
);
}
}.wrapper,
@@ -1613,9 +1613,9 @@ pub fn timeout(
.callback = struct {
fn wrapper(ctx: ?*anyopaque, comp: *Completion, res: *const anyopaque) void {
callback(
- @ptrFromInt(Context, @intFromPtr(ctx)),
+ @as(Context, @ptrFromInt(@intFromPtr(ctx))),
comp,
- @ptrFromInt(*const TimeoutError!void, @intFromPtr(res)).*,
+ @as(*const TimeoutError!void, @ptrFromInt(@intFromPtr(res))).*,
);
}
}.wrapper,
@@ -1662,9 +1662,9 @@ pub fn write(
.callback = struct {
fn wrapper(ctx: ?*anyopaque, comp: *Completion, res: *const anyopaque) void {
callback(
- @ptrFromInt(Context, @intFromPtr(ctx)),
+ @as(Context, @ptrFromInt(@intFromPtr(ctx))),
comp,
- @ptrFromInt(*const WriteError!usize, @intFromPtr(res)).*,
+ @as(*const WriteError!usize, @ptrFromInt(@intFromPtr(res))).*,
);
}
}.wrapper,
@@ -1702,7 +1702,7 @@ const Syscall = struct {
pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!os.socket_t {
const rc = linux.socket(domain, socket_type, protocol);
return switch (linux.getErrno((rc))) {
- .SUCCESS => @intCast(os.fd_t, rc),
+ .SUCCESS => @as(os.fd_t, @intCast(rc)),
.ACCES => return error.PermissionDenied,
.AFNOSUPPORT => return error.AddressFamilyNotSupported,
.INVAL => return error.ProtocolFamilyNotAvailable,
diff --git a/src/io/time.zig b/src/io/time.zig
index 8ebf5de6e..1454d009b 100644
--- a/src/io/time.zig
+++ b/src/io/time.zig
@@ -40,7 +40,7 @@ pub const Time = struct {
// see https://github.com/ziglang/zig/pull/933#discussion_r656021295.
var ts: std.os.timespec = undefined;
std.os.clock_gettime(std.os.CLOCK_BOOTTIME, &ts) catch @panic("CLOCK_BOOTTIME required");
- break :blk @intCast(u64, ts.tv_sec) * std.time.ns_per_s + @intCast(u64, ts.tv_nsec);
+ break :blk @as(u64, @intCast(ts.tv_sec)) * std.time.ns_per_s + @as(u64, @intCast(ts.tv_nsec));
};
// "Oops!...I Did It Again"