authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-27 14:12:50-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-27 14:12:50-04:00
log06435535d3e40e4676e98009fad136f98fffbf2e
treea72055c4cce2869fa81f12d621560d6bec436f62
parentf1610f6c1ddbb5c2b42d2ecac433b8eff11d5a3a
signature Commit is signed but in an unrecognized format.

fixes for darwin


7 files changed, 46 insertions(+), 55 deletions(-)

std/child_process.zig+2-2
......@@ -47,7 +47,7 @@ pub const ChildProcess = struct {
4747 /// Set to change the current working directory when spawning the child process.
4848 pub cwd: ?[]const u8,
4949
50 err_pipe: if (os.windows.is_the_target) void else [2]i32,
50 err_pipe: if (os.windows.is_the_target) void else [2]os.fd_t,
5151 llnode: if (os.windows.is_the_target) void else LinkedList(*ChildProcess).Node,
5252
5353 pub const SpawnError = error{OutOfMemory} || os.ExecveError || os.SetIdError ||
......@@ -701,7 +701,7 @@ fn windowsMakePipeOut(rd: *?windows.HANDLE, wr: *?windows.HANDLE, sattr: *const
701701 wr.* = wr_h;
702702}
703703
704fn destroyPipe(pipe: [2]i32) void {
704fn destroyPipe(pipe: [2]os.fd_t) void {
705705 os.close(pipe[0]);
706706 os.close(pipe[1]);
707707}
std/event/loop.zig+12-12
......@@ -222,10 +222,10 @@ pub const Loop = struct {
222222 }
223223 },
224224 .macosx, .freebsd, .netbsd => {
225 self.os_data.kqfd = try os.bsdKQueue();
225 self.os_data.kqfd = try os.kqueue();
226226 errdefer os.close(self.os_data.kqfd);
227227
228 self.os_data.fs_kqfd = try os.bsdKQueue();
228 self.os_data.fs_kqfd = try os.kqueue();
229229 errdefer os.close(self.os_data.fs_kqfd);
230230
231231 self.os_data.fs_queue = std.atomic.Queue(fs.Request).init();
......@@ -264,7 +264,7 @@ pub const Loop = struct {
264264 };
265265 self.available_eventfd_resume_nodes.push(eventfd_node);
266266 const kevent_array = (*const [1]os.Kevent)(&eventfd_node.data.kevent);
267 _ = try os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null);
267 _ = try os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null);
268268 eventfd_node.data.kevent.flags = os.EV_CLEAR | os.EV_ENABLE;
269269 eventfd_node.data.kevent.fflags = os.NOTE_TRIGGER;
270270 }
......@@ -280,7 +280,7 @@ pub const Loop = struct {
280280 .udata = @ptrToInt(&self.final_resume_node),
281281 };
282282 const final_kev_arr = (*const [1]os.Kevent)(&self.os_data.final_kevent);
283 _ = try os.bsdKEvent(self.os_data.kqfd, final_kev_arr, empty_kevs, null);
283 _ = try os.kevent(self.os_data.kqfd, final_kev_arr, empty_kevs, null);
284284 self.os_data.final_kevent.flags = os.EV_ENABLE;
285285 self.os_data.final_kevent.fflags = os.NOTE_TRIGGER;
286286
......@@ -315,7 +315,7 @@ pub const Loop = struct {
315315
316316 var extra_thread_index: usize = 0;
317317 errdefer {
318 _ = os.bsdKEvent(self.os_data.kqfd, final_kev_arr, empty_kevs, null) catch unreachable;
318 _ = os.kevent(self.os_data.kqfd, final_kev_arr, empty_kevs, null) catch unreachable;
319319 while (extra_thread_index != 0) {
320320 extra_thread_index -= 1;
321321 self.extra_threads[extra_thread_index].wait();
......@@ -474,7 +474,7 @@ pub const Loop = struct {
474474 };
475475 const kevent_array = (*const [1]os.Kevent)(&kev);
476476 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
477 _ = try os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null);
477 _ = try os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null);
478478 }
479479
480480 pub fn bsdRemoveKev(self: *Loop, ident: usize, filter: i16) void {
......@@ -488,7 +488,7 @@ pub const Loop = struct {
488488 };
489489 const kevent_array = (*const [1]os.Kevent)(&kev);
490490 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
491 _ = os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch undefined;
491 _ = os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch undefined;
492492 self.finishOneEvent();
493493 }
494494
......@@ -504,7 +504,7 @@ pub const Loop = struct {
504504 .macosx, .freebsd, .netbsd => {
505505 const kevent_array = (*const [1]os.Kevent)(&eventfd_node.kevent);
506506 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
507 _ = os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch {
507 _ = os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch {
508508 self.next_tick_queue.unget(next_tick_node);
509509 self.available_eventfd_resume_nodes.push(resume_stack_node);
510510 return;
......@@ -634,7 +634,7 @@ pub const Loop = struct {
634634 const final_kevent = (*const [1]os.Kevent)(&self.os_data.final_kevent);
635635 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
636636 // cannot fail because we already added it and this just enables it
637 _ = os.bsdKEvent(self.os_data.kqfd, final_kevent, empty_kevs, null) catch unreachable;
637 _ = os.kevent(self.os_data.kqfd, final_kevent, empty_kevs, null) catch unreachable;
638638 return;
639639 },
640640 .windows => {
......@@ -690,7 +690,7 @@ pub const Loop = struct {
690690 .macosx, .freebsd, .netbsd => {
691691 var eventlist: [1]os.Kevent = undefined;
692692 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
693 const count = os.bsdKEvent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable;
693 const count = os.kevent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable;
694694 for (eventlist[0..count]) |ev| {
695695 const resume_node = @intToPtr(*ResumeNode, ev.udata);
696696 const handle = resume_node.handle;
......@@ -753,7 +753,7 @@ pub const Loop = struct {
753753 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
754754 const fs_kevs = (*const [1]os.Kevent)(&self.os_data.fs_kevent_wake);
755755 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
756 _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable;
756 _ = os.kevent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable;
757757 },
758758 builtin.Os.linux => {
759759 _ = @atomicRmw(i32, &self.os_data.fs_queue_item, AtomicRmwOp.Xchg, 1, AtomicOrder.SeqCst);
......@@ -823,7 +823,7 @@ pub const Loop = struct {
823823 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
824824 const fs_kevs = (*const [1]os.Kevent)(&self.os_data.fs_kevent_wait);
825825 var out_kevs: [1]os.Kevent = undefined;
826 _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable;
826 _ = os.kevent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable;
827827 },
828828 else => @compileError("Unsupported OS"),
829829 }
std/fs.zig+6-6
......@@ -509,7 +509,7 @@ pub const Dir = struct {
509509 }
510510 }
511511 self.handle.index = 0;
512 self.handle.end_index = @intCast(usize, result);
512 self.handle.end_index = @intCast(usize, rc);
513513 break;
514514 }
515515 }
......@@ -694,7 +694,7 @@ pub fn readLinkC(pathname: [*]const u8, buffer: *[os.PATH_MAX]u8) ![]u8 {
694694 return os.readlinkC(pathname, buffer);
695695}
696696
697pub const OpenSelfExeError = os.OpenError || os.windows.CreateFileError;
697pub const OpenSelfExeError = os.OpenError || os.windows.CreateFileError || SelfExePathError;
698698
699699pub fn openSelfExe() OpenSelfExeError!File {
700700 if (os.linux.is_the_target) {
......@@ -730,10 +730,10 @@ pub const SelfExePathError = os.ReadLinkError || os.SysCtlError;
730730/// On Linux, depends on procfs being mounted. If the currently executing binary has
731731/// been deleted, the file path looks something like `/a/b/c/exe (deleted)`.
732732/// TODO make the return type of this a null terminated pointer
733pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 {
733pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]u8 {
734734 if (os.darwin.is_the_target) {
735735 var u32_len: u32 = out_buffer.len;
736 const rc = c._NSGetExecutablePath(out_buffer, &u32_len);
736 const rc = std.c._NSGetExecutablePath(out_buffer, &u32_len);
737737 if (rc != 0) return error.NameTooLong;
738738 return mem.toSlice(u8, out_buffer);
739739 }
......@@ -765,13 +765,13 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 {
765765}
766766
767767/// Same as `selfExePath` except the result is UTF16LE-encoded.
768pub fn selfExePathW(out_buffer: *[os.windows.PATH_MAX_WIDE]u16) ![]u16 {
768pub fn selfExePathW(out_buffer: *[os.windows.PATH_MAX_WIDE]u16) SelfExePathError![]u16 {
769769 return os.windows.GetModuleFileNameW(null, out_buffer, out_buffer.len);
770770}
771771
772772/// `selfExeDirPath` except allocates the result on the heap.
773773/// Caller owns returned memory.
774pub fn selfExeDirPathAlloc(allocator: *Allocator) ![]u8 {
774pub fn selfExeDirPathAlloc(allocator: *Allocator) SelfExePathError![]u8 {
775775 var buf: [MAX_PATH_BYTES]u8 = undefined;
776776 return mem.dupe(allocator, u8, try selfExeDirPath(&buf));
777777}
std/os.zig+23-10
......@@ -297,8 +297,9 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) ReadError!usize {
297297 const err = darwin.getErrno(rc);
298298 switch (err) {
299299 0 => {
300 off += rc;
301 inner_off += rc;
300 const amt_read = @bitCast(usize, rc);
301 off += amt_read;
302 inner_off += amt_read;
302303 if (inner_off == v.iov_len) {
303304 iov_i += 1;
304305 inner_off = 0;
......@@ -421,8 +422,9 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) WriteError!void
421422 const err = darwin.getErrno(rc);
422423 switch (err) {
423424 0 => {
424 off += rc;
425 inner_off += rc;
425 const amt_written = @bitCast(usize, rc);
426 off += amt_written;
427 inner_off += amt_written;
426428 if (inner_off == v.iov_len) {
427429 iov_i += 1;
428430 inner_off = 0;
......@@ -1205,8 +1207,8 @@ pub fn isatty(handle: fd_t) bool {
12051207 @compileError("TODO implement std.os.isatty for WASI");
12061208 }
12071209 if (linux.is_the_target) {
1208 var wsz: system.winsize = undefined;
1209 return system.syscall3(system.SYS_ioctl, @bitCast(usize, isize(handle)), TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
1210 var wsz: linux.winsize = undefined;
1211 return linux.syscall3(linux.SYS_ioctl, @bitCast(usize, isize(handle)), linux.TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
12101212 }
12111213 unreachable;
12121214}
......@@ -1778,6 +1780,10 @@ pub const KEventError = error{
17781780
17791781 /// The specified process to attach to does not exist.
17801782 ProcessNotFound,
1783
1784 /// changelist or eventlist had too many items on it.
1785 /// TODO remove this possibility
1786 Overflow,
17811787};
17821788
17831789pub fn kevent(
......@@ -1787,9 +1793,16 @@ pub fn kevent(
17871793 timeout: ?*const timespec,
17881794) KEventError!usize {
17891795 while (true) {
1790 const rc = system.kevent(kq, changelist, eventlist, timeout);
1796 const rc = system.kevent(
1797 kq,
1798 changelist.ptr,
1799 try math.cast(c_int, changelist.len),
1800 eventlist.ptr,
1801 try math.cast(c_int, eventlist.len),
1802 timeout,
1803 );
17911804 switch (errno(rc)) {
1792 0 => return rc,
1805 0 => return @intCast(usize, rc),
17931806 EACCES => return error.AccessDenied,
17941807 EFAULT => unreachable,
17951808 EBADF => unreachable, // Always a race condition.
......@@ -2028,7 +2041,7 @@ pub const PipeError = error{
20282041
20292042/// Creates a unidirectional data channel that can be used for interprocess communication.
20302043pub fn pipe() PipeError![2]fd_t {
2031 var fds: [2]i32 = undefined;
2044 var fds: [2]fd_t = undefined;
20322045 switch (errno(system.pipe(&fds))) {
20332046 0 => return fds,
20342047 EINVAL => unreachable, // Invalid parameters to pipe()
......@@ -2040,7 +2053,7 @@ pub fn pipe() PipeError![2]fd_t {
20402053}
20412054
20422055pub fn pipe2(flags: u32) PipeError![2]fd_t {
2043 var fds: [2]i32 = undefined;
2056 var fds: [2]fd_t = undefined;
20442057 switch (errno(system.pipe2(&fds, flags))) {
20452058 0 => return fds,
20462059 EINVAL => unreachable, // Invalid flags
std/os/bits/darwin.zig+1-23
......@@ -1,32 +1,10 @@
11const std = @import("../../std.zig");
22const assert = std.debug.assert;
3const maxInt = std.math.maxInt;
34
45pub const fd_t = c_int;
56pub const pid_t = c_int;
67
7pub fn sigaction(sig: u5, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize {
8 assert(sig != SIGKILL);
9 assert(sig != SIGSTOP);
10 var cact = c.Sigaction{
11 .handler = @ptrCast(extern fn (c_int) void, act.handler),
12 .sa_flags = @bitCast(c_int, act.flags),
13 .sa_mask = act.mask,
14 };
15 var coact: c.Sigaction = undefined;
16 const result = errnoWrap(c.sigaction(sig, &cact, &coact));
17 if (result != 0) {
18 return result;
19 }
20 if (oact) |old| {
21 old.* = Sigaction{
22 .handler = @ptrCast(extern fn (i32) void, coact.handler),
23 .flags = @bitCast(u32, coact.sa_flags),
24 .mask = coact.sa_mask,
25 };
26 }
27 return result;
28}
29
308pub const in_port_t = u16;
319pub const sa_family_t = u8;
3210pub const socklen_t = u32;
std/os/bits/windows.zig-1
......@@ -159,5 +159,4 @@ pub const EWOULDBLOCK = 140;
159159// for if branches that aren't taken.
160160pub const SIGKILL = @compileError("Windows libc does not have this");
161161pub const EDQUOT = @compileError("Windows libc does not have this");
162pub const TIOCGWINSZ = @compileError("Windows libc does not have this");
163162pub const F_OK = 0;
std/thread.zig+2-1
......@@ -323,6 +323,7 @@ pub const Thread = struct {
323323 pub const CpuCountError = error{
324324 OutOfMemory,
325325 PermissionDenied,
326 SystemResources,
326327 Unexpected,
327328 };
328329
......@@ -339,7 +340,7 @@ pub const Thread = struct {
339340 var count: c_int = undefined;
340341 var count_len: usize = @sizeOf(c_int);
341342 const name = if (os.darwin.is_the_target) c"hw.logicalcpu" else c"hw.ncpu";
342 try os.sysctlbyname(name, @ptrCast(*c_void, &count), &count_len, null, 0);
343 try os.sysctlbynameC(name, @ptrCast(*c_void, &count), &count_len, null, 0);
343344 return @intCast(usize, count);
344345 }
345346};