From 4a415c6d367f425cd6b99a9c9fd6f51b275c5d74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20C=2E=20Fran=C3=A7a?= Date: Sat, 4 Mar 2023 11:20:57 -0300 Subject: [PATCH 1/2] fix nanosleep for Windows close: https://github.com/ziglang/zig/issues/8488 --- lib/std/os.zig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/std/os.zig b/lib/std/os.zig index fe664302a77d..03ae9ce9d8d4 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -5271,11 +5271,16 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 { } } +const size = switch(builtin.os.tag){ + .windows => c_long, + else => isize, +}; + /// Spurious wakeups are possible and no precision of timing is guaranteed. pub fn nanosleep(seconds: u64, nanoseconds: u64) void { var req = timespec{ .tv_sec = math.cast(isize, seconds) orelse math.maxInt(isize), - .tv_nsec = math.cast(isize, nanoseconds) orelse math.maxInt(isize), + .tv_nsec = math.cast(size, nanoseconds) orelse math.maxInt(size), }; var rem: timespec = undefined; while (true) { From 33db528dfea6bd9b686594094562c236b185ee29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20C=2E=20Fran=C3=A7a?= Date: Sat, 4 Mar 2023 12:20:26 -0300 Subject: [PATCH 2/2] rename size to nanosize --- lib/std/os.zig | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/std/os.zig b/lib/std/os.zig index 03ae9ce9d8d4..04bde6d59dcd 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -5271,16 +5271,13 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 { } } -const size = switch(builtin.os.tag){ - .windows => c_long, - else => isize, -}; +const nanosize = if (is_windows) c_long else isize; /// Spurious wakeups are possible and no precision of timing is guaranteed. pub fn nanosleep(seconds: u64, nanoseconds: u64) void { var req = timespec{ .tv_sec = math.cast(isize, seconds) orelse math.maxInt(isize), - .tv_nsec = math.cast(size, nanoseconds) orelse math.maxInt(size), + .tv_nsec = math.cast(nanosize, nanoseconds) orelse math.maxInt(nanosize), }; var rem: timespec = undefined; while (true) {