From c1542ee268d3a210dec42975b404b4b7b5ef66a9 Mon Sep 17 00:00:00 2001 From: Chen Kai <281165273grape@gmail.com> Date: Sun, 24 Nov 2024 21:00:17 +0800 Subject: [PATCH] feat:make build and test works with zig master Signed-off-by: Chen Kai <281165273grape@gmail.com> --- .gitignore | 1 + README.md | 5 +- build.zig | 190 +++++++++++++++++++++++------------------- src/Async.zig | 2 +- src/Idle.zig | 2 +- src/Loop.zig | 6 +- src/Pipe.zig | 8 +- src/Prepare.zig | 2 +- src/Thread.zig | 4 +- src/Timer.zig | 4 +- src/Tty.zig | 2 +- src/cimport_linux.zig | 36 ++++---- src/cimport_macos.zig | 180 +++++++++++++++++++-------------------- src/error.zig | 9 +- src/handle.zig | 16 ++-- src/stream.zig | 37 ++++---- 16 files changed, 260 insertions(+), 244 deletions(-) diff --git a/.gitignore b/.gitignore index e73c965..928caff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ zig-cache/ zig-out/ +.zig-cache diff --git a/README.md b/README.md index b69ca72..ba27283 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,6 @@
-**⚠️ Project Archived ⚠️.** This project is archived. I used this for a few -real projects since 2021 and it was stable, but I've since moved onto using -[libxev](https://github.com/mitchellh/libxev) so I'm no longer maintaining -the libuv bindings. +Forked this repo to upgrade the zig version to master. The original repo is [here](https://github.com/mitchellh/zig-libuv).
diff --git a/build.zig b/build.zig index e1c5eff..9e74f21 100644 --- a/build.zig +++ b/build.zig @@ -4,7 +4,7 @@ const std = @import("std"); const root = thisDir() ++ "/vendor/libuv/"; const include_path = root ++ "include"; -pub const pkg = std.build.Pkg{ +pub const pkg = .{ .name = "libuv", .source = .{ .path = thisDir() ++ "/src/main.zig" }, }; @@ -13,49 +13,48 @@ fn thisDir() []const u8 { return std.fs.path.dirname(@src().file) orelse "."; } -pub fn build(b: *std.build.Builder) !void { +pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const tests = b.addTest(.{ .name = "pixman-test", - .kind = .test_exe, - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = .{ .cwd_relative = "src/main.zig" }, .target = target, .optimize = optimize, }); _ = try link(b, tests); - tests.install(); + b.installArtifact(tests); const test_step = b.step("test", "Run tests"); - const tests_run = tests.run(); + const tests_run = b.addRunArtifact(tests); test_step.dependOn(&tests_run.step); } -pub fn link(b: *std.build.Builder, step: *std.build.LibExeObjStep) !*std.build.LibExeObjStep { +pub fn link(b: *std.Build, step: *std.Build.Step.Compile) !*std.Build.Step.Compile { const libuv = try buildLibuv(b, step); step.linkLibrary(libuv); - step.addIncludePath(include_path); + step.addIncludePath(.{ .cwd_relative = include_path }); return libuv; } pub fn buildLibuv( - b: *std.build.Builder, - step: *std.build.LibExeObjStep, -) !*std.build.LibExeObjStep { - const target = step.target; + b: *std.Build, + step: *std.Build.Step.Compile, +) !*std.Build.Step.Compile { + const target = step.root_module.resolved_target.?; const lib = b.addStaticLibrary(.{ .name = "uv", .target = target, - .optimize = step.optimize, + .optimize = step.root_module.optimize.?, }); // Include dirs - lib.addIncludePath(include_path); - lib.addIncludePath(root ++ "src"); + lib.addIncludePath(.{ .cwd_relative = include_path }); + lib.addIncludePath(.{ .cwd_relative = root ++ "src" }); // Links - if (target.isWindows()) { + if (target.result.os.tag == .windows) { lib.linkSystemLibrary("psapi"); lib.linkSystemLibrary("user32"); lib.linkSystemLibrary("advapi32"); @@ -63,7 +62,7 @@ pub fn buildLibuv( lib.linkSystemLibrary("userenv"); lib.linkSystemLibrary("ws2_32"); } - if (target.isLinux()) { + if (target.result.os.tag == .linux) { lib.linkSystemLibrary("pthread"); } lib.linkLibC(); @@ -73,21 +72,21 @@ pub fn buildLibuv( defer flags.deinit(); // try flags.appendSlice(&.{}); - if (!target.isWindows()) { + if (target.result.os.tag != .windows) { try flags.appendSlice(&.{ "-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE", }); } - if (target.isLinux()) { + if (target.result.os.tag == .linux) { try flags.appendSlice(&.{ "-D_GNU_SOURCE", "-D_POSIX_C_SOURCE=200112", }); } - if (target.isDarwin()) { + if (target.result.os.tag == .macos) { try flags.appendSlice(&.{ "-D_DARWIN_UNLIMITED_SELECT=1", "-D_DARWIN_USE_64_BIT_INODE=1", @@ -95,82 +94,103 @@ pub fn buildLibuv( } // C files common to all platforms - lib.addCSourceFiles(&.{ - root ++ "src/fs-poll.c", - root ++ "src/idna.c", - root ++ "src/inet.c", - root ++ "src/random.c", - root ++ "src/strscpy.c", - root ++ "src/strtok.c", - root ++ "src/threadpool.c", - root ++ "src/timer.c", - root ++ "src/uv-common.c", - root ++ "src/uv-data-getter-setters.c", - root ++ "src/version.c", - }, flags.items); - - if (!target.isWindows()) { - lib.addCSourceFiles(&.{ - root ++ "src/unix/async.c", - root ++ "src/unix/core.c", - root ++ "src/unix/dl.c", - root ++ "src/unix/fs.c", - root ++ "src/unix/getaddrinfo.c", - root ++ "src/unix/getnameinfo.c", - root ++ "src/unix/loop-watcher.c", - root ++ "src/unix/loop.c", - root ++ "src/unix/pipe.c", - root ++ "src/unix/poll.c", - root ++ "src/unix/process.c", - root ++ "src/unix/random-devurandom.c", - root ++ "src/unix/signal.c", - root ++ "src/unix/stream.c", - root ++ "src/unix/tcp.c", - root ++ "src/unix/thread.c", - root ++ "src/unix/tty.c", - root ++ "src/unix/udp.c", - }, flags.items); + lib.addCSourceFiles(.{ + .files = &.{ + root ++ "src/fs-poll.c", + root ++ "src/idna.c", + root ++ "src/inet.c", + root ++ "src/random.c", + root ++ "src/strscpy.c", + root ++ "src/strtok.c", + root ++ "src/threadpool.c", + root ++ "src/timer.c", + root ++ "src/uv-common.c", + root ++ "src/uv-data-getter-setters.c", + root ++ "src/version.c", + }, + .flags = flags.items, + }); + + if (target.result.os.tag != .windows) { + lib.addCSourceFiles(.{ + .files = &.{ + root ++ "src/unix/async.c", + root ++ "src/unix/core.c", + root ++ "src/unix/dl.c", + root ++ "src/unix/fs.c", + root ++ "src/unix/getaddrinfo.c", + root ++ "src/unix/getnameinfo.c", + root ++ "src/unix/loop-watcher.c", + root ++ "src/unix/loop.c", + root ++ "src/unix/pipe.c", + root ++ "src/unix/poll.c", + root ++ "src/unix/process.c", + root ++ "src/unix/random-devurandom.c", + root ++ "src/unix/signal.c", + root ++ "src/unix/stream.c", + root ++ "src/unix/tcp.c", + root ++ "src/unix/thread.c", + root ++ "src/unix/tty.c", + root ++ "src/unix/udp.c", + }, + .flags = flags.items, + }); } - if (target.isLinux() or target.isDarwin()) { - lib.addCSourceFiles(&.{ - root ++ "src/unix/proctitle.c", - }, flags.items); + if (target.result.os.tag == .linux or target.result.os.tag == .macos) { + lib.addCSourceFiles(.{ + .files = &.{ + root ++ "src/unix/proctitle.c", + }, + .flags = flags.items, + }); } - if (target.isLinux()) { - lib.addCSourceFiles(&.{ - root ++ "src/unix/linux.c", - root ++ "src/unix/procfs-exepath.c", - root ++ "src/unix/random-getrandom.c", - root ++ "src/unix/random-sysctl-linux.c", - }, flags.items); + if (target.result.os.tag == .linux) { + lib.addCSourceFiles(.{ + .files = &.{ + root ++ "src/unix/linux.c", + root ++ "src/unix/procfs-exepath.c", + root ++ "src/unix/random-getrandom.c", + root ++ "src/unix/random-sysctl-linux.c", + }, + .flags = flags.items, + }); } - if (target.isDarwin() or - target.isOpenBSD() or - target.isNetBSD() or - target.isFreeBSD() or - target.isDragonFlyBSD()) + if (target.result.os.tag == .macos or + target.result.os.tag == .openbsd or + target.result.os.tag == .netbsd or + target.result.os.tag == .freebsd or + target.result.os.tag == .dragonfly) { - lib.addCSourceFiles(&.{ - root ++ "src/unix/bsd-ifaddrs.c", - root ++ "src/unix/kqueue.c", - }, flags.items); + lib.addCSourceFiles(.{ + .files = &.{ + root ++ "src/unix/bsd-ifaddrs.c", + root ++ "src/unix/kqueue.c", + }, + .flags = flags.items, + }); } - if (target.isDarwin() or target.isOpenBSD()) { - lib.addCSourceFiles(&.{ - root ++ "src/unix/random-getentropy.c", - }, flags.items); + if (target.result.os.tag == .macos or target.result.os.tag == .openbsd) { + lib.addCSourceFiles(.{ + .files = &.{ + root ++ "src/unix/random-getentropy.c", + }, + .flags = flags.items, + }); } - if (target.isDarwin()) { - lib.addCSourceFiles(&.{ - root ++ "src/unix/darwin-proctitle.c", - root ++ "src/unix/darwin.c", - root ++ "src/unix/fsevents.c", - }, flags.items); + if (target.result.os.tag == .macos) { + lib.addCSourceFiles(.{ + .files = &.{ + root ++ "src/unix/darwin-proctitle.c", + root ++ "src/unix/darwin.c", + root ++ "src/unix/fsevents.c", + }, + .flags = flags.items, + }); } return lib; diff --git a/src/Async.zig b/src/Async.zig index 943275b..a09ad9a 100644 --- a/src/Async.zig +++ b/src/Async.zig @@ -15,7 +15,7 @@ handle: *c.uv_async_t, pub usingnamespace Handle(Async); pub fn init(alloc: Allocator, loop: Loop, comptime cb: fn (*Async) void) !Async { - var handle = try alloc.create(c.uv_async_t); + const handle = try alloc.create(c.uv_async_t); errdefer alloc.destroy(handle); const Wrapper = struct { diff --git a/src/Idle.zig b/src/Idle.zig index 2a8c2ab..e743f41 100644 --- a/src/Idle.zig +++ b/src/Idle.zig @@ -15,7 +15,7 @@ handle: *c.uv_idle_t, pub usingnamespace Handle(Idle); pub fn init(alloc: Allocator, loop: Loop) !Idle { - var handle = try alloc.create(c.uv_idle_t); + const handle = try alloc.create(c.uv_idle_t); errdefer alloc.destroy(handle); try errors.convertError(c.uv_idle_init(loop.loop, handle)); diff --git a/src/Loop.zig b/src/Loop.zig index ea07099..050e37d 100644 --- a/src/Loop.zig +++ b/src/Loop.zig @@ -41,9 +41,9 @@ pub fn alive(self: Loop) !bool { /// /// This is not reentrant. It must not be called from a callback. pub fn run(self: Loop, mode: RunMode) !u32 { - const res = c.uv_run(self.loop, @enumToInt(mode)); + const res = c.uv_run(self.loop, @intFromEnum(mode)); try errors.convertError(res); - return @intCast(u32, res); + return @as(u32, @intCast(res)); } /// Stop the event loop, causing uv_run() to end as soon as possible. This @@ -98,7 +98,7 @@ pub fn setData(self: Loop, pointer: ?*anyopaque) void { /// Returns loop->data. pub fn getData(self: Loop, comptime DT: type) ?*DT { return if (c.uv_loop_get_data(self.loop)) |ptr| - @ptrCast(?*DT, @alignCast(@alignOf(DT), ptr)) + @as(?*DT, @ptrCast(@alignCast(ptr))) else null; } diff --git a/src/Pipe.zig b/src/Pipe.zig index 155b0b6..91182a3 100644 --- a/src/Pipe.zig +++ b/src/Pipe.zig @@ -26,7 +26,7 @@ pub const Flags = packed struct { _ignore_high: u1 = 0, pub inline fn toInt(self: Flags, comptime IntType: type) IntType { - return @intCast(IntType, @bitCast(u8, self)); + return @as(IntType, @intCast(@as(u8, @bitCast(self)))); } test "Flags: expected value" { @@ -55,9 +55,9 @@ pub fn pipe(read_flags: Flags, write_flags: Flags) !Pair { } pub fn init(alloc: Allocator, loop: Loop, ipc: bool) !Pipe { - var handle = try alloc.create(c.uv_pipe_t); + const handle = try alloc.create(c.uv_pipe_t); errdefer alloc.destroy(handle); - try errors.convertError(c.uv_pipe_init(loop.loop, handle, @boolToInt(ipc))); + try errors.convertError(c.uv_pipe_init(loop.loop, handle, @intFromBool(ipc))); return Pipe{ .handle = handle }; } @@ -167,7 +167,7 @@ const TestData = struct { var data = h.getData(TestData).?; data.data.appendSlice( testing.allocator, - buf[0..@intCast(usize, n)], + buf[0..@as(usize, @intCast(n))], ) catch unreachable; testing.allocator.free(buf); } diff --git a/src/Prepare.zig b/src/Prepare.zig index 98a6237..6e90e51 100644 --- a/src/Prepare.zig +++ b/src/Prepare.zig @@ -15,7 +15,7 @@ handle: *c.uv_prepare_t, pub usingnamespace Handle(Prepare); pub fn init(alloc: Allocator, loop: Loop) !Prepare { - var handle = try alloc.create(c.uv_prepare_t); + const handle = try alloc.create(c.uv_prepare_t); errdefer alloc.destroy(handle); try errors.convertError(c.uv_prepare_init(loop.loop, handle)); diff --git a/src/Thread.zig b/src/Thread.zig index bd14895..9ce43d0 100644 --- a/src/Thread.zig +++ b/src/Thread.zig @@ -38,12 +38,12 @@ pub fn initData( // to do the proper casts for the callback. const Data = @TypeOf(data); const dataInfo = @typeInfo(Data); - if (dataInfo != .Pointer) @compileError("data must be a pointer type"); + if (dataInfo != .pointer) @compileError("data must be a pointer type"); const CWrapper = struct { pub fn wrapper(arg: ?*anyopaque) callconv(.C) void { @call(.always_inline, callback, .{ - @ptrCast(Data, @alignCast(@alignOf(dataInfo.Pointer.child), arg)), + @as(Data, @ptrCast(@alignCast(arg))), }); } }; diff --git a/src/Timer.zig b/src/Timer.zig index 9cb3851..3a1127b 100644 --- a/src/Timer.zig +++ b/src/Timer.zig @@ -14,7 +14,7 @@ handle: *c.uv_timer_t, pub usingnamespace Handle(Timer); pub fn init(alloc: Allocator, loop: Loop) !Timer { - var timer = try alloc.create(c.uv_timer_t); + const timer = try alloc.create(c.uv_timer_t); errdefer alloc.destroy(timer); try errors.convertError(c.uv_timer_init(loop.loop, timer)); return Timer{ .handle = timer }; @@ -104,7 +104,7 @@ test "Timer: close callback" { timer.setData(&data); timer.close((struct { fn callback(v: *Timer) void { - var dataPtr = v.getData(u8).?; + const dataPtr = v.getData(u8).?; dataPtr.* = 24; } }).callback); diff --git a/src/Tty.zig b/src/Tty.zig index 8756ce0..e1ddecf 100644 --- a/src/Tty.zig +++ b/src/Tty.zig @@ -17,7 +17,7 @@ pub usingnamespace Handle(Tty); pub usingnamespace Stream(Tty); pub fn init(alloc: Allocator, loop: Loop, fd: fd_t) !Tty { - var tty = try alloc.create(c.uv_tty_t); + const tty = try alloc.create(c.uv_tty_t); errdefer alloc.destroy(tty); try errors.convertError(c.uv_tty_init(loop.loop, tty, fd, 0)); return Tty{ .handle = tty }; diff --git a/src/cimport_linux.zig b/src/cimport_linux.zig index 042cc96..a439f8a 100644 --- a/src/cimport_linux.zig +++ b/src/cimport_linux.zig @@ -333,27 +333,27 @@ pub const u_int32_t = __uint32_t; pub const u_int64_t = __uint64_t; pub const register_t = c_long; pub fn __bswap_16(arg___bsx: __uint16_t) callconv(.C) __uint16_t { - var __bsx = arg___bsx; - return @bitCast(__uint16_t, @truncate(c_short, ((@bitCast(c_int, @as(c_uint, __bsx)) >> @intCast(@import("std").math.Log2Int(c_int), 8)) & @as(c_int, 255)) | ((@bitCast(c_int, @as(c_uint, __bsx)) & @as(c_int, 255)) << @intCast(@import("std").math.Log2Int(c_int), 8)))); + const __bsx = arg___bsx; + return @as(__uint16_t, @bitCast(@as(c_short, @truncate(((@as(c_int, @bitCast(@as(c_uint, __bsx))) >> @as(@import("std").math.Log2Int(c_int), 8)) & @as(c_int, 255)) | ((@as(c_int, @bitCast(@as(c_uint, __bsx))) & @as(c_int, 255)) << @as(@import("std").math.Log2Int(c_int), 8)))))); } pub fn __bswap_32(arg___bsx: __uint32_t) callconv(.C) __uint32_t { - var __bsx = arg___bsx; - return ((((__bsx & @as(c_uint, 4278190080)) >> @intCast(@import("std").math.Log2Int(c_uint), 24)) | ((__bsx & @as(c_uint, 16711680)) >> @intCast(@import("std").math.Log2Int(c_uint), 8))) | ((__bsx & @as(c_uint, 65280)) << @intCast(@import("std").math.Log2Int(c_uint), 8))) | ((__bsx & @as(c_uint, 255)) << @intCast(@import("std").math.Log2Int(c_uint), 24)); + const __bsx = arg___bsx; + return ((((__bsx & @as(c_uint, 4278190080)) >> @as(@import("std").math.Log2Int(c_uint), @intCast(24))) | ((__bsx & @as(c_uint, 16711680)) >> @as(@import("std").math.Log2Int(c_uint), @intCast(8)))) | ((__bsx & @as(c_uint, 65280)) << @as(@import("std").math.Log2Int(c_uint), @intCast(8)))) | ((__bsx & @as(c_uint, 255)) << @as(@import("std").math.Log2Int(c_uint), @intCast(24))); } pub fn __bswap_64(arg___bsx: __uint64_t) callconv(.C) __uint64_t { - var __bsx = arg___bsx; - return @bitCast(__uint64_t, @truncate(c_ulong, ((((((((@bitCast(c_ulonglong, @as(c_ulonglong, __bsx)) & @as(c_ulonglong, 18374686479671623680)) >> @intCast(@import("std").math.Log2Int(c_ulonglong), 56)) | ((@bitCast(c_ulonglong, @as(c_ulonglong, __bsx)) & @as(c_ulonglong, 71776119061217280)) >> @intCast(@import("std").math.Log2Int(c_ulonglong), 40))) | ((@bitCast(c_ulonglong, @as(c_ulonglong, __bsx)) & @as(c_ulonglong, 280375465082880)) >> @intCast(@import("std").math.Log2Int(c_ulonglong), 24))) | ((@bitCast(c_ulonglong, @as(c_ulonglong, __bsx)) & @as(c_ulonglong, 1095216660480)) >> @intCast(@import("std").math.Log2Int(c_ulonglong), 8))) | ((@bitCast(c_ulonglong, @as(c_ulonglong, __bsx)) & @as(c_ulonglong, 4278190080)) << @intCast(@import("std").math.Log2Int(c_ulonglong), 8))) | ((@bitCast(c_ulonglong, @as(c_ulonglong, __bsx)) & @as(c_ulonglong, 16711680)) << @intCast(@import("std").math.Log2Int(c_ulonglong), 24))) | ((@bitCast(c_ulonglong, @as(c_ulonglong, __bsx)) & @as(c_ulonglong, 65280)) << @intCast(@import("std").math.Log2Int(c_ulonglong), 40))) | ((@bitCast(c_ulonglong, @as(c_ulonglong, __bsx)) & @as(c_ulonglong, 255)) << @intCast(@import("std").math.Log2Int(c_ulonglong), 56)))); + const __bsx = arg___bsx; + return @as(__uint64_t, @bitCast(@as(c_ulong, @truncate(((((((((@as(c_ulonglong, @bitCast(@as(c_ulonglong, __bsx))) & @as(c_ulonglong, 18374686479671623680)) >> @as(@import("std").math.Log2Int(c_ulonglong), @intCast(56))) | ((@as(c_ulonglong, @bitCast(@as(c_ulonglong, __bsx))) & @as(c_ulonglong, 71776119061217280)) >> @as(@import("std").math.Log2Int(c_ulonglong), @intCast(40)))) | ((@as(c_ulonglong, @bitCast(@as(c_ulonglong, __bsx))) & @as(c_ulonglong, 280375465082880)) >> @as(@import("std").math.Log2Int(c_ulonglong), @intCast(24)))) | ((@as(c_ulonglong, @bitCast(@as(c_ulonglong, __bsx))) & @as(c_ulonglong, 1095216660480)) >> @as(@import("std").math.Log2Int(c_ulonglong), @intCast(8)))) | ((@as(c_ulonglong, @bitCast(@as(c_ulonglong, __bsx))) & @as(c_ulonglong, 4278190080)) << @as(@import("std").math.Log2Int(c_ulonglong), @intCast(8)))) | ((@as(c_ulonglong, @bitCast(@as(c_ulonglong, __bsx))) & @as(c_ulonglong, 16711680)) << @as(@import("std").math.Log2Int(c_ulonglong), @intCast(24)))) | ((@as(c_ulonglong, @bitCast(@as(c_ulonglong, __bsx))) & @as(c_ulonglong, 65280)) << @as(@import("std").math.Log2Int(c_ulonglong), @intCast(40)))) | ((@as(c_ulonglong, @bitCast(@as(c_ulonglong, __bsx))) & @as(c_ulonglong, 255)) << @as(@import("std").math.Log2Int(c_ulonglong), @intCast(56))))))); } pub fn __uint16_identity(arg___x: __uint16_t) callconv(.C) __uint16_t { - var __x = arg___x; + const __x = arg___x; return __x; } pub fn __uint32_identity(arg___x: __uint32_t) callconv(.C) __uint32_t { - var __x = arg___x; + const __x = arg___x; return __x; } pub fn __uint64_identity(arg___x: __uint64_t) callconv(.C) __uint64_t { - var __x = arg___x; + const __x = arg___x; return __x; } pub const __sigset_t = extern struct { @@ -628,7 +628,7 @@ pub const struct_cmsghdr = extern struct { pub fn __cmsg_data(self: anytype) @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), u8) { const Intermediate = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), u8); const ReturnType = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), u8); - return @ptrCast(ReturnType, @alignCast(@alignOf(u8), @ptrCast(Intermediate, self) + 16)); + return @as(ReturnType, @ptrCast(@alignCast(@as(Intermediate, @ptrCast(self)) + 16))); } }; pub extern fn __cmsg_nxthdr(__mhdr: [*c]struct_msghdr, __cmsg: [*c]struct_cmsghdr) [*c]struct_cmsghdr; @@ -4228,8 +4228,8 @@ pub inline fn le64toh(x: anytype) @TypeOf(__uint64_identity(x)) { return __uint64_identity(x); } pub const _SYS_SELECT_H = @as(c_int, 1); -pub inline fn __FD_ISSET(d: anytype, s: anytype) @TypeOf((__FDS_BITS(s)[@intCast(usize, __FD_ELT(d))] & __FD_MASK(d)) != @as(c_int, 0)) { - return (__FDS_BITS(s)[@intCast(usize, __FD_ELT(d))] & __FD_MASK(d)) != @as(c_int, 0); +pub inline fn __FD_ISSET(d: anytype, s: anytype) @TypeOf((__FDS_BITS(s)[@as(usize, @intCast(__FD_ELT(d)))] & __FD_MASK(d)) != @as(c_int, 0)) { + return (__FDS_BITS(s)[@as(usize, @intCast(__FD_ELT(d)))] & __FD_MASK(d)) != @as(c_int, 0); } pub const __sigset_t_defined = @as(c_int, 1); pub const ____sigset_t_defined = ""; @@ -4489,8 +4489,8 @@ pub const _DIRENT_HAVE_D_RECLEN = ""; pub const _DIRENT_HAVE_D_OFF = ""; pub const _DIRENT_HAVE_D_TYPE = ""; pub const _DIRENT_MATCHES_DIRENT64 = @as(c_int, 1); -pub inline fn _D_ALLOC_NAMLEN(d: anytype) @TypeOf((@import("std").zig.c_translation.cast([*c]u8, d) + d.*.d_reclen) - (&d.*.d_name[@intCast(usize, @as(c_int, 0))])) { - return (@import("std").zig.c_translation.cast([*c]u8, d) + d.*.d_reclen) - (&d.*.d_name[@intCast(usize, @as(c_int, 0))]); +pub inline fn _D_ALLOC_NAMLEN(d: anytype) @TypeOf((@import("std").zig.c_translation.cast([*c]u8, d) + d.*.d_reclen) - (&d.*.d_name[@as(usize, @intCast(@as(c_int, 0)))])) { + return (@import("std").zig.c_translation.cast([*c]u8, d) + d.*.d_reclen) - (&d.*.d_name[@as(usize, @intCast(@as(c_int, 0)))]); } pub inline fn IFTODT(mode: anytype) @TypeOf((mode & @import("std").zig.c_translation.promoteIntLiteral(c_int, 0o170000, .octal)) >> @as(c_int, 12)) { return (mode & @import("std").zig.c_translation.promoteIntLiteral(c_int, 0o170000, .octal)) >> @as(c_int, 12); @@ -5567,11 +5567,11 @@ pub const CANBSIZ = MAX_CANON; pub const MAXPATHLEN = PATH_MAX; pub const NODEV = @import("std").zig.c_translation.cast(dev_t, -@as(c_int, 1)); pub const DEV_BSIZE = @as(c_int, 512); -pub inline fn isset(a: anytype, i: anytype) @TypeOf(a[@intCast(usize, i / NBBY)] & (@as(c_int, 1) << (i % NBBY))) { - return a[@intCast(usize, i / NBBY)] & (@as(c_int, 1) << (i % NBBY)); +pub inline fn isset(a: anytype, i: anytype) @TypeOf(a[@as(usize, @intCast(i / NBBY))] & (@as(c_int, 1) << (i % NBBY))) { + return a[@as(usize, @intCast(i / NBBY))] & (@as(c_int, 1) << (i % NBBY)); } -pub inline fn isclr(a: anytype, i: anytype) @TypeOf((a[@intCast(usize, i / NBBY)] & (@as(c_int, 1) << (i % NBBY))) == @as(c_int, 0)) { - return (a[@intCast(usize, i / NBBY)] & (@as(c_int, 1) << (i % NBBY))) == @as(c_int, 0); +pub inline fn isclr(a: anytype, i: anytype) @TypeOf((a[@as(usize, @intCast(i / NBBY))] & (@as(c_int, 1) << (i % NBBY))) == @as(c_int, 0)) { + return (a[@as(usize, @intCast(i / NBBY))] & (@as(c_int, 1) << (i % NBBY))) == @as(c_int, 0); } pub inline fn howmany(x: anytype, y: anytype) @TypeOf((x + (y - @as(c_int, 1))) / y) { return (x + (y - @as(c_int, 1))) / y; diff --git a/src/cimport_macos.zig b/src/cimport_macos.zig index 56441d6..66088bc 100644 --- a/src/cimport_macos.zig +++ b/src/cimport_macos.zig @@ -259,14 +259,14 @@ pub extern fn __srget([*c]FILE) c_int; pub extern fn __svfscanf([*c]FILE, [*c]const u8, va_list) c_int; pub extern fn __swbuf(c_int, [*c]FILE) c_int; pub inline fn __sputc(arg__c: c_int, arg__p: [*c]FILE) c_int { - var _c = arg__c; - var _p = arg__p; + const _c = arg__c; + const _p = arg__p; if (((blk: { const ref = &_p.*._w; ref.* -= 1; break :blk ref.*; - }) >= @as(c_int, 0)) or ((_p.*._w >= _p.*._lbfsize) and (@bitCast(c_int, @as(c_uint, @bitCast(u8, @truncate(i8, _c)))) != @as(c_int, '\n')))) return @bitCast(c_int, @as(c_uint, blk: { - const tmp = @bitCast(u8, @truncate(i8, _c)); + }) >= @as(c_int, 0)) or ((_p.*._w >= _p.*._lbfsize) and (@as(c_int, @bitCast(@as(c_uint, @as(u8, @bitCast(@as(i8, @truncate(_c))))))) != @as(c_int, '\n')))) return @as(c_int, @bitCast(@as(c_uint, blk: { + const tmp = @as(u8, @bitCast(@as(i8, @truncate(_c)))); (blk_1: { const ref = &_p.*._p; const tmp_2 = ref.*; @@ -274,7 +274,7 @@ pub inline fn __sputc(arg__c: c_int, arg__p: [*c]FILE) c_int { break :blk_1 tmp_2; }).* = tmp; break :blk tmp; - })) else return __swbuf(_c, _p); + }))) else return __swbuf(_c, _p); return 0; } pub extern fn flockfile([*c]FILE) void; @@ -335,8 +335,8 @@ pub const uint_fast64_t = u64; pub const intmax_t = c_long; pub const uintmax_t = c_ulong; pub fn _OSSwapInt16(arg__data: u16) callconv(.C) u16 { - var _data = arg__data; - return @bitCast(u16, @truncate(c_short, (@bitCast(c_int, @as(c_uint, _data)) << @intCast(@import("std").math.Log2Int(c_int), 8)) | (@bitCast(c_int, @as(c_uint, _data)) >> @intCast(@import("std").math.Log2Int(c_int), 8)))); + const _data = arg__data; + return @as(u16, @bitCast(@as(c_short, @truncate((@as(c_int, @bitCast(@as(c_uint, _data))) << @as(@import("std").math.Log2Int(c_int), @intCast(8))) | (@as(c_int, @bitCast(@as(c_uint, _data))) >> @as(@import("std").math.Log2Int(c_int), @intCast(8))))))); } pub fn _OSSwapInt32(arg__data: u32) callconv(.C) u32 { var _data = arg__data; @@ -344,7 +344,7 @@ pub fn _OSSwapInt32(arg__data: u32) callconv(.C) u32 { return _data; } pub fn _OSSwapInt64(arg__data: u64) callconv(.C) u64 { - var _data = arg__data; + const _data = arg__data; return __builtin_bswap64(_data); } pub const struct__OSUnalignedU16 = extern struct { @@ -357,37 +357,37 @@ pub const struct__OSUnalignedU64 = extern struct { __val: u64 align(1), }; pub fn OSReadSwapInt16(arg__base: ?*const volatile anyopaque, arg__offset: usize) callconv(.C) u16 { - var _base = arg__base; - var _offset = arg__offset; - return _OSSwapInt16(@intToPtr([*c]struct__OSUnalignedU16, @intCast(usize, @ptrToInt(_base)) +% _offset).*.__val); + const _base = arg__base; + const _offset = arg__offset; + return _OSSwapInt16(@as([*c]struct__OSUnalignedU16, @ptrFromInt(@as(usize, @intFromPtr(_base)) +% _offset)).*.__val); } pub fn OSReadSwapInt32(arg__base: ?*const volatile anyopaque, arg__offset: usize) callconv(.C) u32 { - var _base = arg__base; - var _offset = arg__offset; - return _OSSwapInt32(@intToPtr([*c]struct__OSUnalignedU32, @intCast(usize, @ptrToInt(_base)) +% _offset).*.__val); + const _base = arg__base; + const _offset = arg__offset; + return _OSSwapInt32(@as([*c]struct__OSUnalignedU32, @ptrFromInt(@as(usize, @intFromPtr(_base)) +% _offset)).*.__val); } pub fn OSReadSwapInt64(arg__base: ?*const volatile anyopaque, arg__offset: usize) callconv(.C) u64 { - var _base = arg__base; - var _offset = arg__offset; - return _OSSwapInt64(@intToPtr([*c]struct__OSUnalignedU64, @intCast(usize, @ptrToInt(_base)) +% _offset).*.__val); + const _base = arg__base; + const _offset = arg__offset; + return _OSSwapInt64(@as([*c]struct__OSUnalignedU64, @ptrFromInt(@as(usize, @intFromPtr(_base)) +% _offset)).*.__val); } pub fn OSWriteSwapInt16(arg__base: ?*volatile anyopaque, arg__offset: usize, arg__data: u16) callconv(.C) void { - var _base = arg__base; - var _offset = arg__offset; - var _data = arg__data; - @intToPtr([*c]struct__OSUnalignedU16, @intCast(usize, @ptrToInt(_base)) +% _offset).*.__val = _OSSwapInt16(_data); + const _base = arg__base; + const _offset = arg__offset; + const _data = arg__data; + @as([*c]struct__OSUnalignedU16, @ptrFromInt(@as(usize, @intFromPtr(_base)) +% _offset)).*.val = _OSSwapInt16(_data); } pub fn OSWriteSwapInt32(arg__base: ?*volatile anyopaque, arg__offset: usize, arg__data: u32) callconv(.C) void { - var _base = arg__base; - var _offset = arg__offset; - var _data = arg__data; - @intToPtr([*c]struct__OSUnalignedU32, @intCast(usize, @ptrToInt(_base)) +% _offset).*.__val = _OSSwapInt32(_data); + const _base = arg__base; + const _offset = arg__offset; + const _data = arg__data; + @as([*c]struct__OSUnalignedU32, @ptrFromInt(@as(usize, @intFromPtr(_base)) +% _offset)).*.val = _OSSwapInt32(_data); } pub fn OSWriteSwapInt64(arg__base: ?*volatile anyopaque, arg__offset: usize, arg__data: u64) callconv(.C) void { - var _base = arg__base; - var _offset = arg__offset; - var _data = arg__data; - @intToPtr([*c]struct__OSUnalignedU64, @intCast(usize, @ptrToInt(_base)) +% _offset).*.__val = _OSSwapInt64(_data); + const _base = arg__base; + const _offset = arg__offset; + const _data = arg__data; + @as([*c]struct__OSUnalignedU64, @ptrFromInt(@as(usize, @intCast(@intFromPtr(_base))) +% _offset)).*.__val = _OSSwapInt64(_data); } pub const u_char = u8; pub const u_short = c_ushort; @@ -427,9 +427,9 @@ pub const struct_fd_set = extern struct { pub const fd_set = struct_fd_set; pub extern fn __darwin_check_fd_set_overflow(c_int, ?*const anyopaque, c_int) c_int; pub inline fn __darwin_check_fd_set(arg__a: c_int, arg__b: ?*const anyopaque) c_int { - var _a = arg__a; - var _b = arg__b; - if (@intCast(usize, @ptrToInt(&__darwin_check_fd_set_overflow)) != @bitCast(usize, @as(c_long, @as(c_int, 0)))) { + const _a = arg__a; + const _b = arg__b; + if (@as(usize, @intCast(@intFromPtr(&__darwin_check_fd_set_overflow))) != @as(usize, @bitCast(@as(c_long, @as(c_int, 0))))) { return __darwin_check_fd_set_overflow(_a, _b, @as(c_int, 0)); } else { return 1; @@ -437,29 +437,29 @@ pub inline fn __darwin_check_fd_set(arg__a: c_int, arg__b: ?*const anyopaque) c_ return 0; } pub inline fn __darwin_fd_isset(arg__fd: c_int, arg__p: [*c]const struct_fd_set) c_int { - var _fd = arg__fd; - var _p = arg__p; - if (__darwin_check_fd_set(_fd, @ptrCast(?*const anyopaque, _p)) != 0) { - return _p.*.fds_bits[@bitCast(c_ulong, @as(c_long, _fd)) / (@sizeOf(__int32_t) *% @bitCast(c_ulong, @as(c_long, @as(c_int, 8))))] & @bitCast(__int32_t, @truncate(c_uint, @bitCast(c_ulong, @as(c_long, @as(c_int, 1))) << @intCast(@import("std").math.Log2Int(c_ulong), @bitCast(c_ulong, @as(c_long, _fd)) % (@sizeOf(__int32_t) *% @bitCast(c_ulong, @as(c_long, @as(c_int, 8))))))); + const _fd = arg__fd; + const _p = arg__p; + if (__darwin_check_fd_set(_fd, @as(?*const anyopaque, @ptrCast(_p))) != 0) { + return _p.*.fds_bits[@as(c_ulong, @bitCast(@as(c_long, _fd))) / (@sizeOf(__int32_t) *% @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 8)))))] & @as(__int32_t, @bitCast(@as(c_uint, @truncate(@as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1)))) << @as(@import("std").math.Log2Int(c_ulong), @intCast(@as(c_ulong, @bitCast(@as(c_long, _fd))) % (@sizeOf(__int32_t) *% @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 8))))))))))); } return 0; } pub inline fn __darwin_fd_set(arg__fd: c_int, _p: [*c]struct_fd_set) void { - var _fd = arg__fd; - if (__darwin_check_fd_set(_fd, @ptrCast(?*const anyopaque, _p)) != 0) { + const _fd = arg__fd; + if (__darwin_check_fd_set(_fd, @as(?*const anyopaque, @ptrCast(_p))) != 0) { _ = blk: { - const ref = &_p.*.fds_bits[@bitCast(c_ulong, @as(c_long, _fd)) / (@sizeOf(__int32_t) *% @bitCast(c_ulong, @as(c_long, @as(c_int, 8))))]; - ref.* |= @bitCast(__int32_t, @truncate(c_uint, @bitCast(c_ulong, @as(c_long, @as(c_int, 1))) << @intCast(@import("std").math.Log2Int(c_ulong), @bitCast(c_ulong, @as(c_long, _fd)) % (@sizeOf(__int32_t) *% @bitCast(c_ulong, @as(c_long, @as(c_int, 8))))))); + const ref = &_p.*.fds_bits[@as(c_ulong, @bitCast(@as(c_long, _fd))) / (@sizeOf(__int32_t) *% @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 8)))))]; + ref.* |= @as(__int32_t, @bitCast(@as(c_uint, @truncate(@as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1)))) << @as(@import("std").math.Log2Int(c_ulong), @intCast(@as(c_ulong, @bitCast(@as(c_long, _fd))) % (@sizeOf(__int32_t) *% @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 8))))))))))); break :blk ref.*; }; } } pub inline fn __darwin_fd_clr(arg__fd: c_int, _p: [*c]struct_fd_set) void { - var _fd = arg__fd; - if (__darwin_check_fd_set(_fd, @ptrCast(?*const anyopaque, _p)) != 0) { + const _fd = arg__fd; + if (__darwin_check_fd_set(_fd, @as(?*const anyopaque, @ptrCast(_p))) != 0) { _ = blk: { - const ref = &_p.*.fds_bits[@bitCast(c_ulong, @as(c_long, _fd)) / (@sizeOf(__int32_t) *% @bitCast(c_ulong, @as(c_long, @as(c_int, 8))))]; - ref.* &= ~@bitCast(__int32_t, @truncate(c_uint, @bitCast(c_ulong, @as(c_long, @as(c_int, 1))) << @intCast(@import("std").math.Log2Int(c_ulong), @bitCast(c_ulong, @as(c_long, _fd)) % (@sizeOf(__int32_t) *% @bitCast(c_ulong, @as(c_long, @as(c_int, 8))))))); + const ref = &_p.*.fds_bits[@as(c_ulong, @bitCast(@as(c_long, _fd))) / (@sizeOf(__int32_t) *% @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 8)))))]; + ref.* &= ~@as(__int32_t, @bitCast(@as(c_uint, @truncate(@as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1)))) << @as(@import("std").math.Log2Int(c_ulong), @intCast(@as(c_ulong, @bitCast(@as(c_long, _fd))) % (@sizeOf(__int32_t) *% @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 8))))))))))); break :blk ref.*; }; } @@ -1431,8 +1431,8 @@ pub extern fn sigblock(c_int) c_int; pub extern fn sigsetmask(c_int) c_int; pub extern fn sigvec(c_int, [*c]struct_sigvec, [*c]struct_sigvec) c_int; pub inline fn __sigbits(arg___signo: c_int) c_int { - var __signo = arg___signo; - return if (__signo > @as(c_int, 32)) @as(c_int, 0) else @as(c_int, 1) << @intCast(@import("std").math.Log2Int(c_int), __signo - @as(c_int, 1)); + const __signo = arg___signo; + return if (__signo > @as(c_int, 32)) @as(c_int, 0) else @as(c_int, 1) << @as(@import("std").math.Log2Int(c_int), @intCast(__signo - @as(c_int, 1))); } const union_unnamed_3 = extern union { unused: ?*anyopaque, @@ -2100,7 +2100,7 @@ pub const struct_mach_voucher_attr_recipe_data = extern struct { pub fn content(self: anytype) @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), u8) { const Intermediate = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), u8); const ReturnType = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), u8); - return @ptrCast(ReturnType, @alignCast(@alignOf(u8), @ptrCast(Intermediate, self) + 16)); + return @as(ReturnType, @ptrCast(@alignCast(@as(Intermediate, @ptrCast(self)) + 16))); } }; pub const mach_voucher_attr_recipe_data_t = struct_mach_voucher_attr_recipe_data; @@ -3012,37 +3012,37 @@ pub fn OSHostByteOrder() callconv(.C) i32 { return OSLittleEndian; } pub fn _OSReadInt16(arg_base: ?*const volatile anyopaque, arg_byteOffset: usize) callconv(.C) u16 { - var base = arg_base; - var byteOffset = arg_byteOffset; - return @intToPtr([*c]volatile u16, @intCast(usize, @ptrToInt(base)) +% byteOffset).*; + const base = arg_base; + const byteOffset = arg_byteOffset; + return @as([*c]volatile u16, @ptrFromInt(@as(usize, @intCast(@intFromPtr(base))) +% byteOffset)).*; } pub fn _OSReadInt32(arg_base: ?*const volatile anyopaque, arg_byteOffset: usize) callconv(.C) u32 { - var base = arg_base; - var byteOffset = arg_byteOffset; - return @intToPtr([*c]volatile u32, @intCast(usize, @ptrToInt(base)) +% byteOffset).*; + const base = arg_base; + const byteOffset = arg_byteOffset; + return @as([*c]volatile u32, @ptrFromInt(@as(usize, @intCast(@intFromPtr(base))) +% byteOffset)).*; } pub fn _OSReadInt64(arg_base: ?*const volatile anyopaque, arg_byteOffset: usize) callconv(.C) u64 { - var base = arg_base; - var byteOffset = arg_byteOffset; - return @intToPtr([*c]volatile u64, @intCast(usize, @ptrToInt(base)) +% byteOffset).*; + const base = arg_base; + const byteOffset = arg_byteOffset; + return @as([*c]volatile u64, @ptrFromInt(@as(usize, @intCast(@intFromPtr(base))) +% byteOffset)).*; } pub fn _OSWriteInt16(arg_base: ?*volatile anyopaque, arg_byteOffset: usize, arg_data: u16) callconv(.C) void { - var base = arg_base; - var byteOffset = arg_byteOffset; - var data = arg_data; - @intToPtr([*c]volatile u16, @intCast(usize, @ptrToInt(base)) +% byteOffset).* = data; + const base = arg_base; + const byteOffset = arg_byteOffset; + const data = arg_data; + @as([*c]volatile u16, @ptrFromInt(@as(usize, @intCast(@intFromPtr(base))) +% byteOffset)).* = data; } pub fn _OSWriteInt32(arg_base: ?*volatile anyopaque, arg_byteOffset: usize, arg_data: u32) callconv(.C) void { - var base = arg_base; - var byteOffset = arg_byteOffset; - var data = arg_data; - @intToPtr([*c]volatile u32, @intCast(usize, @ptrToInt(base)) +% byteOffset).* = data; + const base = arg_base; + const byteOffset = arg_byteOffset; + const data = arg_data; + @as([*c]volatile u32, @ptrFromInt(@as(usize, @intCast(@intFromPtr(base))) +% byteOffset)).* = data; } pub fn _OSWriteInt64(arg_base: ?*volatile anyopaque, arg_byteOffset: usize, arg_data: u64) callconv(.C) void { - var base = arg_base; - var byteOffset = arg_byteOffset; - var data = arg_data; - @intToPtr([*c]volatile u64, @intCast(usize, @ptrToInt(base)) +% byteOffset).* = data; + const base = arg_base; + const byteOffset = arg_byteOffset; + const data = arg_data; + @as([*c]volatile u64, @ptrFromInt(@as(usize, @intCast(@intFromPtr(base))) +% byteOffset)).* = data; } pub const NDR_record_t = extern struct { mig_vers: u8, @@ -3136,7 +3136,7 @@ pub const mig_reply_error_t = extern struct { RetCode: kern_return_t, }; pub fn __NDR_convert__mig_reply_error_t(arg_x: [*c]mig_reply_error_t) callconv(.C) void { - var x = arg_x; + const x = arg_x; _ = @TypeOf(x); } pub extern fn clock_set_time(clock_ctrl: clock_ctrl_t, new_time: mach_timespec_t) kern_return_t; @@ -3380,7 +3380,7 @@ pub const struct_mach_core_fileheader_v2 = extern struct { pub fn files(self: anytype) @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), struct_mach_core_details_v2) { const Intermediate = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), u8); const ReturnType = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), struct_mach_core_details_v2); - return @ptrCast(ReturnType, @alignCast(@alignOf(struct_mach_core_details_v2), @ptrCast(Intermediate, self) + 64)); + return @as(ReturnType, @ptrCast(@alignCast(@as(Intermediate, @ptrCast(self)) + 64))); } }; pub const kobject_description_t = [512]u8; @@ -11335,11 +11335,11 @@ pub const IPV6PORT_RESERVEDMIN = @as(c_int, 600); pub const IPV6PORT_RESERVEDMAX = IPV6PORT_RESERVED - @as(c_int, 1); pub const INET6_ADDRSTRLEN = @as(c_int, 46); pub const SIN6_LEN = ""; -pub inline fn IN6_ARE_ADDR_EQUAL(a: anytype, b: anytype) @TypeOf(memcmp(&a.*.s6_addr[@intCast(usize, @as(c_int, 0))], &b.*.s6_addr[@intCast(usize, @as(c_int, 0))], @import("std").zig.c_translation.sizeof(struct_in6_addr)) == @as(c_int, 0)) { - return memcmp(&a.*.s6_addr[@intCast(usize, @as(c_int, 0))], &b.*.s6_addr[@intCast(usize, @as(c_int, 0))], @import("std").zig.c_translation.sizeof(struct_in6_addr)) == @as(c_int, 0); +pub inline fn IN6_ARE_ADDR_EQUAL(a: anytype, b: anytype) @TypeOf(memcmp(&a.*.s6_addr[@as(usize, @intCast(@as(c_int, 0)))], &b.*.s6_addr[@as(usize, @intCast(@as(c_int, 0)))], @import("std").zig.c_translation.sizeof(struct_in6_addr)) == @as(c_int, 0)) { + return memcmp(&a.*.s6_addr[@as(usize, @intCast(@as(c_int, 0)))], &b.*.s6_addr[@as(usize, @intCast(@as(c_int, 0)))], @import("std").zig.c_translation.sizeof(struct_in6_addr)) == @as(c_int, 0); } -pub inline fn IN6_IS_ADDR_6TO4(x: anytype) @TypeOf(ntohs(x.*.s6_addr16[@intCast(usize, @as(c_int, 0))]) == @as(c_int, 0x2002)) { - return ntohs(x.*.s6_addr16[@intCast(usize, @as(c_int, 0))]) == @as(c_int, 0x2002); +pub inline fn IN6_IS_ADDR_6TO4(x: anytype) @TypeOf(ntohs(x.*.s6_addr16[@as(usize, @intCast(@as(c_int, 0)))]) == @as(c_int, 0x2002)) { + return ntohs(x.*.s6_addr16[@as(usize, @intCast(@as(c_int, 0)))]) == @as(c_int, 0x2002); } pub const __IPV6_ADDR_SCOPE_NODELOCAL = @as(c_int, 0x01); pub const __IPV6_ADDR_SCOPE_INTFACELOCAL = @as(c_int, 0x01); @@ -11347,17 +11347,17 @@ pub const __IPV6_ADDR_SCOPE_LINKLOCAL = @as(c_int, 0x02); pub const __IPV6_ADDR_SCOPE_SITELOCAL = @as(c_int, 0x05); pub const __IPV6_ADDR_SCOPE_ORGLOCAL = @as(c_int, 0x08); pub const __IPV6_ADDR_SCOPE_GLOBAL = @as(c_int, 0x0e); -pub inline fn IN6_IS_ADDR_LINKLOCAL(a: anytype) @TypeOf((a.*.s6_addr[@intCast(usize, @as(c_int, 0))] == @as(c_int, 0xfe)) and ((a.*.s6_addr[@intCast(usize, @as(c_int, 1))] & @as(c_int, 0xc0)) == @as(c_int, 0x80))) { - return (a.*.s6_addr[@intCast(usize, @as(c_int, 0))] == @as(c_int, 0xfe)) and ((a.*.s6_addr[@intCast(usize, @as(c_int, 1))] & @as(c_int, 0xc0)) == @as(c_int, 0x80)); +pub inline fn IN6_IS_ADDR_LINKLOCAL(a: anytype) @TypeOf((a.*.s6_addr[@as(usize, @intCast(@as(c_int, 0)))] == @as(c_int, 0xfe)) and ((a.*.s6_addr[@as(usize, @intCast(@as(c_int, 1)))] & @as(c_int, 0xc0)) == @as(c_int, 0x80))) { + return (a.*.s6_addr[@as(usize, @intCast(@as(c_int, 0)))] == @as(c_int, 0xfe)) and ((a.*.s6_addr[@as(usize, @intCast(@as(c_int, 1)))] & @as(c_int, 0xc0)) == @as(c_int, 0x80)); } -pub inline fn IN6_IS_ADDR_SITELOCAL(a: anytype) @TypeOf((a.*.s6_addr[@intCast(usize, @as(c_int, 0))] == @as(c_int, 0xfe)) and ((a.*.s6_addr[@intCast(usize, @as(c_int, 1))] & @as(c_int, 0xc0)) == @as(c_int, 0xc0))) { - return (a.*.s6_addr[@intCast(usize, @as(c_int, 0))] == @as(c_int, 0xfe)) and ((a.*.s6_addr[@intCast(usize, @as(c_int, 1))] & @as(c_int, 0xc0)) == @as(c_int, 0xc0)); +pub inline fn IN6_IS_ADDR_SITELOCAL(a: anytype) @TypeOf((a.*.s6_addr[@as(usize, @intCast(@as(c_int, 0)))] == @as(c_int, 0xfe)) and ((a.*.s6_addr[@as(usize, @intCast(@as(c_int, 1)))] & @as(c_int, 0xc0)) == @as(c_int, 0xc0))) { + return (a.*.s6_addr[@as(usize, @intCast(@as(c_int, 0)))] == @as(c_int, 0xfe)) and ((a.*.s6_addr[@as(usize, @intCast(@as(c_int, 1)))] & @as(c_int, 0xc0)) == @as(c_int, 0xc0)); } -pub inline fn IN6_IS_ADDR_MULTICAST(a: anytype) @TypeOf(a.*.s6_addr[@intCast(usize, @as(c_int, 0))] == @as(c_int, 0xff)) { - return a.*.s6_addr[@intCast(usize, @as(c_int, 0))] == @as(c_int, 0xff); +pub inline fn IN6_IS_ADDR_MULTICAST(a: anytype) @TypeOf(a.*.s6_addr[@as(usize, @intCast(@as(c_int, 0)))] == @as(c_int, 0xff)) { + return a.*.s6_addr[@as(usize, @intCast(@as(c_int, 0)))] == @as(c_int, 0xff); } -pub inline fn IPV6_ADDR_MC_FLAGS(a: anytype) @TypeOf(a.*.s6_addr[@intCast(usize, @as(c_int, 1))] & @as(c_int, 0xf0)) { - return a.*.s6_addr[@intCast(usize, @as(c_int, 1))] & @as(c_int, 0xf0); +pub inline fn IPV6_ADDR_MC_FLAGS(a: anytype) @TypeOf(a.*.s6_addr[@as(usize, @intCast(@as(c_int, 1)))] & @as(c_int, 0xf0)) { + return a.*.s6_addr[@as(usize, @intCast(@as(c_int, 1)))] & @as(c_int, 0xf0); } pub const IPV6_ADDR_MC_FLAGS_TRANSIENT = @as(c_int, 0x10); pub const IPV6_ADDR_MC_FLAGS_PREFIX = @as(c_int, 0x20); @@ -11365,11 +11365,11 @@ pub const IPV6_ADDR_MC_FLAGS_UNICAST_BASED = IPV6_ADDR_MC_FLAGS_TRANSIENT | IPV6 pub inline fn IN6_IS_ADDR_UNICAST_BASED_MULTICAST(a: anytype) @TypeOf((IN6_IS_ADDR_MULTICAST(a) != 0) and (IPV6_ADDR_MC_FLAGS(a) == IPV6_ADDR_MC_FLAGS_UNICAST_BASED)) { return (IN6_IS_ADDR_MULTICAST(a) != 0) and (IPV6_ADDR_MC_FLAGS(a) == IPV6_ADDR_MC_FLAGS_UNICAST_BASED); } -pub inline fn IN6_IS_ADDR_UNIQUE_LOCAL(a: anytype) @TypeOf((a.*.s6_addr[@intCast(usize, @as(c_int, 0))] == @as(c_int, 0xfc)) or (a.*.s6_addr[@intCast(usize, @as(c_int, 0))] == @as(c_int, 0xfd))) { - return (a.*.s6_addr[@intCast(usize, @as(c_int, 0))] == @as(c_int, 0xfc)) or (a.*.s6_addr[@intCast(usize, @as(c_int, 0))] == @as(c_int, 0xfd)); +pub inline fn IN6_IS_ADDR_UNIQUE_LOCAL(a: anytype) @TypeOf((a.*.s6_addr[@as(usize, @intCast(@as(c_int, 0)))] == @as(c_int, 0xfc)) or (a.*.s6_addr[@as(usize, @intCast(@as(c_int, 0)))] == @as(c_int, 0xfd))) { + return (a.*.s6_addr[@as(usize, @intCast(@as(c_int, 0)))] == @as(c_int, 0xfc)) or (a.*.s6_addr[@as(usize, @intCast(@as(c_int, 0)))] == @as(c_int, 0xfd)); } -pub inline fn __IPV6_ADDR_MC_SCOPE(a: anytype) @TypeOf(a.*.s6_addr[@intCast(usize, @as(c_int, 1))] & @as(c_int, 0x0f)) { - return a.*.s6_addr[@intCast(usize, @as(c_int, 1))] & @as(c_int, 0x0f); +pub inline fn __IPV6_ADDR_MC_SCOPE(a: anytype) @TypeOf(a.*.s6_addr[@as(usize, @intCast(@as(c_int, 1)))] & @as(c_int, 0x0f)) { + return a.*.s6_addr[@as(usize, @intCast(@as(c_int, 1)))] & @as(c_int, 0x0f); } pub inline fn IN6_IS_ADDR_MC_NODELOCAL(a: anytype) @TypeOf((IN6_IS_ADDR_MULTICAST(a) != 0) and (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL)) { return (IN6_IS_ADDR_MULTICAST(a) != 0) and (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL); @@ -12310,11 +12310,11 @@ pub const MAXFRAG = @as(c_int, 8); pub const MAXPHYSIO_WIRED = (@as(c_int, 16) * @as(c_int, 1024)) * @as(c_int, 1024); pub const MAXPATHLEN = PATH_MAX; pub const MAXSYMLINKS = @as(c_int, 32); -pub inline fn isset(a: anytype, i: anytype) @TypeOf(@import("std").zig.c_translation.cast([*c]u8, a)[@intCast(usize, i / NBBY)] & (@as(c_uint, 1) << (i % NBBY))) { - return @import("std").zig.c_translation.cast([*c]u8, a)[@intCast(usize, i / NBBY)] & (@as(c_uint, 1) << (i % NBBY)); +pub inline fn isset(a: anytype, i: anytype) @TypeOf(@import("std").zig.c_translation.cast([*c]u8, a)[@as(usize, @intCast(i / NBBY))] & (@as(c_uint, 1) << (i % NBBY))) { + return @import("std").zig.c_translation.cast([*c]u8, a)[@as(usize, @intCast(i / NBBY))] & (@as(c_uint, 1) << (i % NBBY)); } -pub inline fn isclr(a: anytype, i: anytype) @TypeOf((@import("std").zig.c_translation.cast([*c]u8, a)[@intCast(usize, i / NBBY)] & (@as(c_uint, 1) << (i % NBBY))) == @as(c_int, 0)) { - return (@import("std").zig.c_translation.cast([*c]u8, a)[@intCast(usize, i / NBBY)] & (@as(c_uint, 1) << (i % NBBY))) == @as(c_int, 0); +pub inline fn isclr(a: anytype, i: anytype) @TypeOf((@import("std").zig.c_translation.cast([*c]u8, a)[@as(usize, @intCast(i / NBBY))] & (@as(c_uint, 1) << (i % NBBY))) == @as(c_int, 0)) { + return (@import("std").zig.c_translation.cast([*c]u8, a)[@as(usize, @intCast(i / NBBY))] & (@as(c_uint, 1) << (i % NBBY))) == @as(c_int, 0); } pub inline fn roundup(x: anytype, y: anytype) @TypeOf(if ((x % y) == @as(c_int, 0)) x else x + (y - (x % y))) { return if ((x % y) == @as(c_int, 0)) x else x + (y - (x % y)); diff --git a/src/error.zig b/src/error.zig index 04864c7..08e8ef2 100644 --- a/src/error.zig +++ b/src/error.zig @@ -92,20 +92,20 @@ pub const Errno = enum(i32) { pub const Error = blk: { // We produce these from the Errno enum so that we can easily // keep it synced. - const info = @typeInfo(Errno).Enum; + const info = @typeInfo(Errno).@"enum"; var errors: [info.fields.len]std.builtin.Type.Error = undefined; - for (info.fields) |field, i| { + for (info.fields, 0..) |field, i| { errors[i] = .{ .name = field.name }; } - break :blk @Type(.{ .ErrorSet = &errors }); + break :blk @Type(.{ .error_set = &errors }); }; /// Convert the result of a libuv API call to an error (or no error). pub fn convertError(r: i32) !void { if (r >= 0) return; - return switch (@intToEnum(Errno, r)) { + return switch (@as(Errno, @enumFromInt(r))) { .E2BIG => Error.E2BIG, .EACCES => Error.EACCES, .EADDRINUSE => Error.EADDRINUSE, @@ -188,7 +188,6 @@ pub fn convertError(r: i32) !void { .ESOCKTNOSUPPORT => Error.ESOCKTNOSUPPORT, }; } - test { // This is mostly just forcing our error type and function to be // codegenned and run once to ensure we have all the types. diff --git a/src/handle.zig b/src/handle.zig index 616c25f..812a88f 100644 --- a/src/handle.zig +++ b/src/handle.zig @@ -13,7 +13,7 @@ pub fn Handle(comptime T: type) type { return struct { // note: this has to be here: https://github.com/ziglang/zig/issues/11367 - const tInfo = @typeInfo(T).Struct; + const tInfo = @typeInfo(T).@"struct"; const HandleType = tInfo.fields[0].type; // Request handle to be closed. close_cb will be called asynchronously @@ -35,19 +35,19 @@ pub fn Handle(comptime T: type) type { // We get the raw handle, so we need to reconstruct // the T. This is mutable because a lot of the libuv APIs // are non-const but modifying it makes no sense. - var param: T = .{ .handle = @ptrCast(HandleType, handle) }; + var param: T = .{ .handle = @as(HandleType, @ptrCast(handle)) }; @call(.always_inline, f, .{¶m}); } }).callback else null; - c.uv_close(@ptrCast(*c.uv_handle_t, self.handle), cbParam); + c.uv_close(@as(*c.uv_handle_t, @ptrCast(self.handle)), cbParam); } /// Loop returns the loop that this handle is a part of. pub fn loop(self: T) Loop { - const handle = @ptrCast(*c.uv_handle_t, self.handle); + const handle = @as(*c.uv_handle_t, @ptrCast(self.handle)); return .{ .loop = c.uv_handle_get_loop(handle) }; } @@ -56,7 +56,7 @@ pub fn Handle(comptime T: type) type { /// function, then it’s active from the moment that function is called. /// Likewise, uv_foo_stop() deactivates the handle again. pub fn isActive(self: T) !bool { - const res = c.uv_is_active(@ptrCast(*c.uv_handle_t, self.handle)); + const res = c.uv_is_active(@as(*c.uv_handle_t, @ptrCast(self.handle))); try errors.convertError(res); return res > 0; } @@ -64,15 +64,15 @@ pub fn Handle(comptime T: type) type { /// Sets handle->data to data. pub fn setData(self: T, pointer: ?*anyopaque) void { c.uv_handle_set_data( - @ptrCast(*c.uv_handle_t, self.handle), + @as(*c.uv_handle_t, @ptrCast(self.handle)), pointer, ); } /// Returns handle->data. pub fn getData(self: T, comptime DT: type) ?*DT { - return if (c.uv_handle_get_data(@ptrCast(*c.uv_handle_t, self.handle))) |ptr| - @ptrCast(?*DT, @alignCast(@alignOf(DT), ptr)) + return if (c.uv_handle_get_data(@as(*c.uv_handle_t, @ptrCast(self.handle)))) |ptr| + @as(?*DT, @alignCast(@ptrCast(ptr))) else null; } diff --git a/src/stream.zig b/src/stream.zig index d7d8fcb..8723a79 100644 --- a/src/stream.zig +++ b/src/stream.zig @@ -17,19 +17,19 @@ pub fn Stream(comptime T: type) type { return struct { // note: this has to be here: https://github.com/ziglang/zig/issues/11367 - const tInfo = @typeInfo(T).Struct; + const tInfo = @typeInfo(T).@"struct"; const HandleType = tInfo.fields[0].type; /// Returns 1 if the stream is readable, 0 otherwise. pub fn isReadable(self: T) !bool { - const res = c.uv_is_readable(@ptrCast(*c.uv_stream_t, self.handle)); + const res = c.uv_is_readable(@as(*c.uv_stream_t, @ptrCast(self.handle))); try errors.convertError(res); return res > 0; } /// Returns 1 if the stream is writable, 0 otherwise. pub fn isWritable(self: T) !bool { - const res = c.uv_is_writable(@ptrCast(*c.uv_stream_t, self.handle)); + const res = c.uv_is_writable(@as(*c.uv_stream_t, @ptrCast(self.handle))); try errors.convertError(res); return res > 0; } @@ -46,7 +46,7 @@ pub fn Stream(comptime T: type) type { var newreq: WriteReq = .{ .req = cbreq }; @call(.always_inline, cb, .{ &newreq, - @intCast(i32, status), + @as(i32, @intCast(status)), }); } }; @@ -56,9 +56,9 @@ pub fn Stream(comptime T: type) type { // unit test below that keeps this true. try errors.convertError(c.uv_write( req.req, - @ptrCast(*c.uv_stream_t, self.handle), - @ptrCast([*c]const c.uv_buf_t, bufs.ptr), - @intCast(c_uint, bufs.len), + @as(*c.uv_stream_t, @ptrCast(self.handle)), + @as([*c]const c.uv_buf_t, @ptrCast(bufs.ptr)), + @as(c_uint, @intCast(bufs.len)), Wrapper.callback, )); } @@ -67,12 +67,12 @@ pub fn Stream(comptime T: type) type { /// be completed immediately. pub fn tryWrite(self: T, bufs: []const []const u8) !usize { const res = c.uv_try_write( - @ptrCast(*c.uv_stream_t, self.handle), - @ptrCast([*c]const c.uv_buf_t, bufs.ptr), - @intCast(c_uint, bufs.len), + @as(*c.uv_stream_t, @ptrCast(self.handle)), + @as([*c]const c.uv_buf_t, @ptrCast(bufs.ptr)), + @as(c_uint, @intCast(bufs.len)), ); try errors.convertError(res); - return @intCast(usize, res); + return @as(usize, @intCast(res)); } /// Read data from an incoming stream. The uv_read_cb callback will @@ -89,7 +89,7 @@ pub fn Stream(comptime T: type) type { cbsize: usize, buf: [*c]c.uv_buf_t, ) callconv(.C) void { - var param: T = .{ .handle = @ptrCast(HandleType, cbhandle) }; + var param: T = .{ .handle = @as(HandleType, @ptrCast(cbhandle)) }; const result = @call(.always_inline, alloc_cb, .{ ¶m, cbsize, @@ -110,7 +110,7 @@ pub fn Stream(comptime T: type) type { cbnread: isize, cbbuf: [*c]const c.uv_buf_t, ) callconv(.C) void { - var param: T = .{ .handle = @ptrCast(HandleType, cbhandle) }; + var param: T = .{ .handle = @as(HandleType, @ptrCast(cbhandle)) }; @call(.always_inline, read_cb, .{ ¶m, cbnread, @@ -120,7 +120,7 @@ pub fn Stream(comptime T: type) type { }; try errors.convertError(c.uv_read_start( - @ptrCast(*c.uv_stream_t, self.handle), + @ptrCast(self.handle), Wrapper.alloc, Wrapper.read, )); @@ -133,11 +133,10 @@ pub fn Stream(comptime T: type) type { /// stream. pub fn readStop(self: T) void { // Docs say we can ignore this result. - _ = c.uv_read_stop(@ptrCast(*c.uv_stream_t, self.handle)); + _ = c.uv_read_stop(@as(*c.uv_stream_t, @ptrCast(self.handle))); } }; } - /// Write request type. Careful attention must be paid when reusing objects /// of this type. When a stream is in non-blocking mode, write requests sent /// with uv_write will be queued. Reusing objects at this point is undefined @@ -151,7 +150,7 @@ pub const WriteReq = struct { req: *T, pub fn init(alloc: Allocator) !WriteReq { - var req = try alloc.create(c.uv_write_t); + const req = try alloc.create(c.uv_write_t); errdefer alloc.destroy(req); return WriteReq{ .req = req }; } @@ -164,11 +163,11 @@ pub const WriteReq = struct { /// Pointer to the stream where this write request is running. /// T should be a high-level handle type such as "Pipe". pub fn handle(self: WriteReq, comptime HT: type) ?HT { - const tInfo = @typeInfo(HT).Struct; + const tInfo = @typeInfo(HT).@"struct"; const HandleType = tInfo.fields[0].type; return if (self.req.handle) |ptr| - return HT{ .handle = @ptrCast(HandleType, ptr) } + return HT{ .handle = @as(HandleType, @ptrCast(ptr)) } else null; }