all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change
This commit is contained in:
@@ -128,14 +128,14 @@ const WindowsImpl = struct {
|
||||
// NTDLL functions work with time in units of 100 nanoseconds.
|
||||
// Positive values are absolute deadlines while negative values are relative durations.
|
||||
if (timeout) |delay| {
|
||||
timeout_value = @intCast(os.windows.LARGE_INTEGER, delay / 100);
|
||||
timeout_value = @as(os.windows.LARGE_INTEGER, @intCast(delay / 100));
|
||||
timeout_value = -timeout_value;
|
||||
timeout_ptr = &timeout_value;
|
||||
}
|
||||
|
||||
const rc = os.windows.ntdll.RtlWaitOnAddress(
|
||||
@ptrCast(?*const anyopaque, ptr),
|
||||
@ptrCast(?*const anyopaque, &expect),
|
||||
@as(?*const anyopaque, @ptrCast(ptr)),
|
||||
@as(?*const anyopaque, @ptrCast(&expect)),
|
||||
@sizeOf(@TypeOf(expect)),
|
||||
timeout_ptr,
|
||||
);
|
||||
@@ -151,7 +151,7 @@ const WindowsImpl = struct {
|
||||
}
|
||||
|
||||
fn wake(ptr: *const Atomic(u32), max_waiters: u32) void {
|
||||
const address = @ptrCast(?*const anyopaque, ptr);
|
||||
const address = @as(?*const anyopaque, @ptrCast(ptr));
|
||||
assert(max_waiters != 0);
|
||||
|
||||
switch (max_waiters) {
|
||||
@@ -186,7 +186,7 @@ const DarwinImpl = struct {
|
||||
// true so that we we know to ignore the ETIMEDOUT result.
|
||||
var timeout_overflowed = false;
|
||||
|
||||
const addr = @ptrCast(*const anyopaque, ptr);
|
||||
const addr = @as(*const anyopaque, @ptrCast(ptr));
|
||||
const flags = os.darwin.UL_COMPARE_AND_WAIT | os.darwin.ULF_NO_ERRNO;
|
||||
const status = blk: {
|
||||
if (supports_ulock_wait2) {
|
||||
@@ -202,7 +202,7 @@ const DarwinImpl = struct {
|
||||
};
|
||||
|
||||
if (status >= 0) return;
|
||||
switch (@enumFromInt(std.os.E, -status)) {
|
||||
switch (@as(std.os.E, @enumFromInt(-status))) {
|
||||
// Wait was interrupted by the OS or other spurious signalling.
|
||||
.INTR => {},
|
||||
// Address of the futex was paged out. This is unlikely, but possible in theory, and
|
||||
@@ -225,11 +225,11 @@ const DarwinImpl = struct {
|
||||
}
|
||||
|
||||
while (true) {
|
||||
const addr = @ptrCast(*const anyopaque, ptr);
|
||||
const addr = @as(*const anyopaque, @ptrCast(ptr));
|
||||
const status = os.darwin.__ulock_wake(flags, addr, 0);
|
||||
|
||||
if (status >= 0) return;
|
||||
switch (@enumFromInt(std.os.E, -status)) {
|
||||
switch (@as(std.os.E, @enumFromInt(-status))) {
|
||||
.INTR => continue, // spurious wake()
|
||||
.FAULT => unreachable, // __ulock_wake doesn't generate EFAULT according to darwin pthread_cond_t
|
||||
.NOENT => return, // nothing was woken up
|
||||
@@ -245,14 +245,14 @@ const LinuxImpl = struct {
|
||||
fn wait(ptr: *const Atomic(u32), expect: u32, timeout: ?u64) error{Timeout}!void {
|
||||
var ts: os.timespec = undefined;
|
||||
if (timeout) |timeout_ns| {
|
||||
ts.tv_sec = @intCast(@TypeOf(ts.tv_sec), timeout_ns / std.time.ns_per_s);
|
||||
ts.tv_nsec = @intCast(@TypeOf(ts.tv_nsec), timeout_ns % std.time.ns_per_s);
|
||||
ts.tv_sec = @as(@TypeOf(ts.tv_sec), @intCast(timeout_ns / std.time.ns_per_s));
|
||||
ts.tv_nsec = @as(@TypeOf(ts.tv_nsec), @intCast(timeout_ns % std.time.ns_per_s));
|
||||
}
|
||||
|
||||
const rc = os.linux.futex_wait(
|
||||
@ptrCast(*const i32, &ptr.value),
|
||||
@as(*const i32, @ptrCast(&ptr.value)),
|
||||
os.linux.FUTEX.PRIVATE_FLAG | os.linux.FUTEX.WAIT,
|
||||
@bitCast(i32, expect),
|
||||
@as(i32, @bitCast(expect)),
|
||||
if (timeout != null) &ts else null,
|
||||
);
|
||||
|
||||
@@ -272,7 +272,7 @@ const LinuxImpl = struct {
|
||||
|
||||
fn wake(ptr: *const Atomic(u32), max_waiters: u32) void {
|
||||
const rc = os.linux.futex_wake(
|
||||
@ptrCast(*const i32, &ptr.value),
|
||||
@as(*const i32, @ptrCast(&ptr.value)),
|
||||
os.linux.FUTEX.PRIVATE_FLAG | os.linux.FUTEX.WAKE,
|
||||
std.math.cast(i32, max_waiters) orelse std.math.maxInt(i32),
|
||||
);
|
||||
@@ -299,8 +299,8 @@ const FreebsdImpl = struct {
|
||||
|
||||
tm._flags = 0; // use relative time not UMTX_ABSTIME
|
||||
tm._clockid = os.CLOCK.MONOTONIC;
|
||||
tm._timeout.tv_sec = @intCast(@TypeOf(tm._timeout.tv_sec), timeout_ns / std.time.ns_per_s);
|
||||
tm._timeout.tv_nsec = @intCast(@TypeOf(tm._timeout.tv_nsec), timeout_ns % std.time.ns_per_s);
|
||||
tm._timeout.tv_sec = @as(@TypeOf(tm._timeout.tv_sec), @intCast(timeout_ns / std.time.ns_per_s));
|
||||
tm._timeout.tv_nsec = @as(@TypeOf(tm._timeout.tv_nsec), @intCast(timeout_ns % std.time.ns_per_s));
|
||||
}
|
||||
|
||||
const rc = os.freebsd._umtx_op(
|
||||
@@ -347,14 +347,14 @@ const OpenbsdImpl = struct {
|
||||
fn wait(ptr: *const Atomic(u32), expect: u32, timeout: ?u64) error{Timeout}!void {
|
||||
var ts: os.timespec = undefined;
|
||||
if (timeout) |timeout_ns| {
|
||||
ts.tv_sec = @intCast(@TypeOf(ts.tv_sec), timeout_ns / std.time.ns_per_s);
|
||||
ts.tv_nsec = @intCast(@TypeOf(ts.tv_nsec), timeout_ns % std.time.ns_per_s);
|
||||
ts.tv_sec = @as(@TypeOf(ts.tv_sec), @intCast(timeout_ns / std.time.ns_per_s));
|
||||
ts.tv_nsec = @as(@TypeOf(ts.tv_nsec), @intCast(timeout_ns % std.time.ns_per_s));
|
||||
}
|
||||
|
||||
const rc = os.openbsd.futex(
|
||||
@ptrCast(*const volatile u32, &ptr.value),
|
||||
@as(*const volatile u32, @ptrCast(&ptr.value)),
|
||||
os.openbsd.FUTEX_WAIT | os.openbsd.FUTEX_PRIVATE_FLAG,
|
||||
@bitCast(c_int, expect),
|
||||
@as(c_int, @bitCast(expect)),
|
||||
if (timeout != null) &ts else null,
|
||||
null, // FUTEX_WAIT takes no requeue address
|
||||
);
|
||||
@@ -377,7 +377,7 @@ const OpenbsdImpl = struct {
|
||||
|
||||
fn wake(ptr: *const Atomic(u32), max_waiters: u32) void {
|
||||
const rc = os.openbsd.futex(
|
||||
@ptrCast(*const volatile u32, &ptr.value),
|
||||
@as(*const volatile u32, @ptrCast(&ptr.value)),
|
||||
os.openbsd.FUTEX_WAKE | os.openbsd.FUTEX_PRIVATE_FLAG,
|
||||
std.math.cast(c_int, max_waiters) orelse std.math.maxInt(c_int),
|
||||
null, // FUTEX_WAKE takes no timeout ptr
|
||||
@@ -411,8 +411,8 @@ const DragonflyImpl = struct {
|
||||
}
|
||||
}
|
||||
|
||||
const value = @bitCast(c_int, expect);
|
||||
const addr = @ptrCast(*const volatile c_int, &ptr.value);
|
||||
const value = @as(c_int, @bitCast(expect));
|
||||
const addr = @as(*const volatile c_int, @ptrCast(&ptr.value));
|
||||
const rc = os.dragonfly.umtx_sleep(addr, value, timeout_us);
|
||||
|
||||
switch (os.errno(rc)) {
|
||||
@@ -441,7 +441,7 @@ const DragonflyImpl = struct {
|
||||
// https://man.dragonflybsd.org/?command=umtx§ion=2
|
||||
// > umtx_wakeup() will generally return 0 unless the address is bad.
|
||||
// We are fine with the address being bad (e.g. for Semaphore.post() where Semaphore.wait() frees the Semaphore)
|
||||
const addr = @ptrCast(*const volatile c_int, &ptr.value);
|
||||
const addr = @as(*const volatile c_int, @ptrCast(&ptr.value));
|
||||
_ = os.dragonfly.umtx_wakeup(addr, to_wake);
|
||||
}
|
||||
};
|
||||
@@ -488,8 +488,8 @@ const PosixImpl = struct {
|
||||
var ts: os.timespec = undefined;
|
||||
if (timeout) |timeout_ns| {
|
||||
os.clock_gettime(os.CLOCK.REALTIME, &ts) catch unreachable;
|
||||
ts.tv_sec +|= @intCast(@TypeOf(ts.tv_sec), timeout_ns / std.time.ns_per_s);
|
||||
ts.tv_nsec += @intCast(@TypeOf(ts.tv_nsec), timeout_ns % std.time.ns_per_s);
|
||||
ts.tv_sec +|= @as(@TypeOf(ts.tv_sec), @intCast(timeout_ns / std.time.ns_per_s));
|
||||
ts.tv_nsec += @as(@TypeOf(ts.tv_nsec), @intCast(timeout_ns % std.time.ns_per_s));
|
||||
|
||||
if (ts.tv_nsec >= std.time.ns_per_s) {
|
||||
ts.tv_sec +|= 1;
|
||||
|
||||
@@ -242,12 +242,12 @@ const NonAtomicCounter = struct {
|
||||
value: [2]u64 = [_]u64{ 0, 0 },
|
||||
|
||||
fn get(self: NonAtomicCounter) u128 {
|
||||
return @bitCast(u128, self.value);
|
||||
return @as(u128, @bitCast(self.value));
|
||||
}
|
||||
|
||||
fn inc(self: *NonAtomicCounter) void {
|
||||
for (@bitCast([2]u64, self.get() + 1), 0..) |v, i| {
|
||||
@ptrCast(*volatile u64, &self.value[i]).* = v;
|
||||
for (@as([2]u64, @bitCast(self.get() + 1)), 0..) |v, i| {
|
||||
@as(*volatile u64, @ptrCast(&self.value[i])).* = v;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user