authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-09 01:23:47-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-09 01:23:47-04:00
loga0c564d7621c1bf3f83be59d6f91056b0cfe1e16
treeab747d42e207bef97d76015dcfa45559fa6c9325
parent3ba451778fde48a5463180deea6d6539f91e1303

zig fmt


4 files changed, 237 insertions(+), 106 deletions(-)

std/c/darwin.zig+18-6
...@@ -7,11 +7,24 @@ pub extern "c" fn mach_absolute_time() u64;...@@ -7,11 +7,24 @@ pub extern "c" fn mach_absolute_time() u64;
7pub extern "c" fn mach_timebase_info(tinfo: ?*mach_timebase_info_data) void;7pub extern "c" fn mach_timebase_info(tinfo: ?*mach_timebase_info_data) void;
88
9pub extern "c" fn kqueue() c_int;9pub extern "c" fn kqueue() c_int;
10pub extern "c" fn kevent(kq: c_int, changelist: [*]const Kevent, nchanges: c_int,10pub extern "c" fn kevent(
11 eventlist: [*]Kevent, nevents: c_int, timeout: ?*const timespec) c_int;11 kq: c_int,
1212 changelist: [*]const Kevent,
13pub extern "c" fn kevent64(kq: c_int, changelist: [*]const kevent64_s, nchanges: c_int,13 nchanges: c_int,
14 eventlist: [*]kevent64_s, nevents: c_int, flags: c_uint, timeout: ?*const timespec) c_int;14 eventlist: [*]Kevent,
15 nevents: c_int,
16 timeout: ?*const timespec,
17) c_int;
18
19pub extern "c" fn kevent64(
20 kq: c_int,
21 changelist: [*]const kevent64_s,
22 nchanges: c_int,
23 eventlist: [*]kevent64_s,
24 nevents: c_int,
25 flags: c_uint,
26 timeout: ?*const timespec,
27) c_int;
1528
16pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;29pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
17pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;30pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
...@@ -145,4 +158,3 @@ comptime {...@@ -145,4 +158,3 @@ comptime {
145 assert(@offsetOf(kevent64_s, "udata") == 24);158 assert(@offsetOf(kevent64_s, "udata") == 24);
146 assert(@offsetOf(kevent64_s, "ext") == 32);159 assert(@offsetOf(kevent64_s, "ext") == 32);
147}160}
148
std/os/darwin.zig+191-75
...@@ -264,17 +264,32 @@ pub const SIGUSR1 = 30;...@@ -264,17 +264,32 @@ pub const SIGUSR1 = 30;
264/// user defined signal 2264/// user defined signal 2
265pub const SIGUSR2 = 31;265pub const SIGUSR2 = 31;
266266
267pub const KEVENT_FLAG_NONE = 0x000; /// no flag value267/// no flag value
268pub const KEVENT_FLAG_IMMEDIATE = 0x001; /// immediate timeout268pub const KEVENT_FLAG_NONE = 0x000;
269pub const KEVENT_FLAG_ERROR_EVENTS = 0x002; /// output events only include change
270269
271pub const EV_ADD = 0x0001; /// add event to kq (implies enable)270/// immediate timeout
272pub const EV_DELETE = 0x0002; /// delete event from kq271pub const KEVENT_FLAG_IMMEDIATE = 0x001;
273pub const EV_ENABLE = 0x0004; /// enable event
274pub const EV_DISABLE = 0x0008; /// disable event (not reported)
275272
276pub const EV_ONESHOT = 0x0010; /// only report one occurrence273/// output events only include change
277pub const EV_CLEAR = 0x0020; /// clear event state after reporting274pub const KEVENT_FLAG_ERROR_EVENTS = 0x002;
275
276/// add event to kq (implies enable)
277pub const EV_ADD = 0x0001;
278
279/// delete event from kq
280pub const EV_DELETE = 0x0002;
281
282/// enable event
283pub const EV_ENABLE = 0x0004;
284
285/// disable event (not reported)
286pub const EV_DISABLE = 0x0008;
287
288/// only report one occurrence
289pub const EV_ONESHOT = 0x0010;
290
291/// clear event state after reporting
292pub const EV_CLEAR = 0x0020;
278293
279/// force immediate event output294/// force immediate event output
280/// ... with or without EV_ERROR295/// ... with or without EV_ERROR
...@@ -282,8 +297,11 @@ pub const EV_CLEAR = 0x0020; /// clear event state after reporting...@@ -282,8 +297,11 @@ pub const EV_CLEAR = 0x0020; /// clear event state after reporting
282/// on syscalls supporting flags297/// on syscalls supporting flags
283pub const EV_RECEIPT = 0x0040;298pub const EV_RECEIPT = 0x0040;
284299
285pub const EV_DISPATCH = 0x0080; /// disable event after reporting300/// disable event after reporting
286pub const EV_UDATA_SPECIFIC = 0x0100; /// unique kevent per udata value301pub const EV_DISPATCH = 0x0080;
302
303/// unique kevent per udata value
304pub const EV_UDATA_SPECIFIC = 0x0100;
287305
288/// ... in combination with EV_DELETE306/// ... in combination with EV_DELETE
289/// will defer delete until udata-specific307/// will defer delete until udata-specific
...@@ -291,91 +309,178 @@ pub const EV_UDATA_SPECIFIC = 0x0100; /// unique kevent per udata value...@@ -291,91 +309,178 @@ pub const EV_UDATA_SPECIFIC = 0x0100; /// unique kevent per udata value
291/// returned to indicate the deferral309/// returned to indicate the deferral
292pub const EV_DISPATCH2 = EV_DISPATCH | EV_UDATA_SPECIFIC;310pub const EV_DISPATCH2 = EV_DISPATCH | EV_UDATA_SPECIFIC;
293311
294/// report that source has vanished 312/// report that source has vanished
295/// ... only valid with EV_DISPATCH2313/// ... only valid with EV_DISPATCH2
296pub const EV_VANISHED = 0x0200;314pub const EV_VANISHED = 0x0200;
297315
298pub const EV_SYSFLAGS = 0xF000; /// reserved by system316/// reserved by system
299pub const EV_FLAG0 = 0x1000; /// filter-specific flag317pub const EV_SYSFLAGS = 0xF000;
300pub const EV_FLAG1 = 0x2000; /// filter-specific flag318
301pub const EV_EOF = 0x8000; /// EOF detected319/// filter-specific flag
302pub const EV_ERROR = 0x4000; /// error, data contains errno320pub const EV_FLAG0 = 0x1000;
321
322/// filter-specific flag
323pub const EV_FLAG1 = 0x2000;
324
325/// EOF detected
326pub const EV_EOF = 0x8000;
327
328/// error, data contains errno
329pub const EV_ERROR = 0x4000;
303330
304pub const EV_POLL = EV_FLAG0;331pub const EV_POLL = EV_FLAG0;
305pub const EV_OOBAND = EV_FLAG1;332pub const EV_OOBAND = EV_FLAG1;
306333
307pub const EVFILT_READ = -1;334pub const EVFILT_READ = -1;
308pub const EVFILT_WRITE = -2;335pub const EVFILT_WRITE = -2;
309pub const EVFILT_AIO = -3; /// attached to aio requests336
310pub const EVFILT_VNODE = -4; /// attached to vnodes337/// attached to aio requests
311pub const EVFILT_PROC = -5; /// attached to struct proc338pub const EVFILT_AIO = -3;
312pub const EVFILT_SIGNAL = -6; /// attached to struct proc339
313pub const EVFILT_TIMER = -7; /// timers340/// attached to vnodes
314pub const EVFILT_MACHPORT = -8; /// Mach portsets341pub const EVFILT_VNODE = -4;
315pub const EVFILT_FS = -9; /// Filesystem events342
316pub const EVFILT_USER = -10; /// User events343/// attached to struct proc
317pub const EVFILT_VM = -12; /// Virtual memory events344pub const EVFILT_PROC = -5;
318345
319pub const EVFILT_EXCEPT = -15; /// Exception events346/// attached to struct proc
347pub const EVFILT_SIGNAL = -6;
348
349/// timers
350pub const EVFILT_TIMER = -7;
351
352/// Mach portsets
353pub const EVFILT_MACHPORT = -8;
354
355/// Filesystem events
356pub const EVFILT_FS = -9;
357
358/// User events
359pub const EVFILT_USER = -10;
360
361/// Virtual memory events
362pub const EVFILT_VM = -12;
363
364/// Exception events
365pub const EVFILT_EXCEPT = -15;
320366
321pub const EVFILT_SYSCOUNT = 17;367pub const EVFILT_SYSCOUNT = 17;
322368
323/// On input, NOTE_TRIGGER causes the event to be triggered for output.369/// On input, NOTE_TRIGGER causes the event to be triggered for output.
324pub const NOTE_TRIGGER = 0x01000000;370pub const NOTE_TRIGGER = 0x01000000;
325371
326pub const NOTE_FFNOP = 0x00000000; /// ignore input fflags372/// ignore input fflags
327pub const NOTE_FFAND = 0x40000000; /// and fflags373pub const NOTE_FFNOP = 0x00000000;
328pub const NOTE_FFOR = 0x80000000; /// or fflags374
329pub const NOTE_FFCOPY = 0xc0000000; /// copy fflags375/// and fflags
330pub const NOTE_FFCTRLMASK = 0xc0000000; /// mask for operations376pub const NOTE_FFAND = 0x40000000;
377
378/// or fflags
379pub const NOTE_FFOR = 0x80000000;
380
381/// copy fflags
382pub const NOTE_FFCOPY = 0xc0000000;
383
384/// mask for operations
385pub const NOTE_FFCTRLMASK = 0xc0000000;
331pub const NOTE_FFLAGSMASK = 0x00ffffff;386pub const NOTE_FFLAGSMASK = 0x00ffffff;
332387
333pub const NOTE_LOWAT = 0x00000001; /// low water mark388/// low water mark
389pub const NOTE_LOWAT = 0x00000001;
390
391/// OOB data
392pub const NOTE_OOB = 0x00000002;
393
394/// vnode was removed
395pub const NOTE_DELETE = 0x00000001;
396
397/// data contents changed
398pub const NOTE_WRITE = 0x00000002;
399
400/// size increased
401pub const NOTE_EXTEND = 0x00000004;
402
403/// attributes changed
404pub const NOTE_ATTRIB = 0x00000008;
405
406/// link count changed
407pub const NOTE_LINK = 0x00000010;
408
409/// vnode was renamed
410pub const NOTE_RENAME = 0x00000020;
411
412/// vnode access was revoked
413pub const NOTE_REVOKE = 0x00000040;
414
415/// No specific vnode event: to test for EVFILT_READ activation
416pub const NOTE_NONE = 0x00000080;
417
418/// vnode was unlocked by flock(2)
419pub const NOTE_FUNLOCK = 0x00000100;
420
421/// process exited
422pub const NOTE_EXIT = 0x80000000;
334423
335pub const NOTE_OOB = 0x00000002; /// OOB data424/// process forked
425pub const NOTE_FORK = 0x40000000;
336426
337pub const NOTE_DELETE = 0x00000001; /// vnode was removed427/// process exec'd
338pub const NOTE_WRITE = 0x00000002; /// data contents changed428pub const NOTE_EXEC = 0x20000000;
339pub const NOTE_EXTEND = 0x00000004; /// size increased
340pub const NOTE_ATTRIB = 0x00000008; /// attributes changed
341pub const NOTE_LINK = 0x00000010; /// link count changed
342pub const NOTE_RENAME = 0x00000020; /// vnode was renamed
343pub const NOTE_REVOKE = 0x00000040; /// vnode access was revoked
344pub const NOTE_NONE = 0x00000080; /// No specific vnode event: to test for EVFILT_READ activation
345pub const NOTE_FUNLOCK = 0x00000100; /// vnode was unlocked by flock(2)
346429
347pub const NOTE_EXIT = 0x80000000; /// process exited430/// shared with EVFILT_SIGNAL
348pub const NOTE_FORK = 0x40000000; /// process forked431pub const NOTE_SIGNAL = 0x08000000;
349pub const NOTE_EXEC = 0x20000000; /// process exec'd
350pub const NOTE_SIGNAL = 0x08000000; /// shared with EVFILT_SIGNAL
351pub const NOTE_EXITSTATUS = 0x04000000; /// exit status to be returned, valid for child process only
352pub const NOTE_EXIT_DETAIL = 0x02000000; /// provide details on reasons for exit
353432
354pub const NOTE_PDATAMASK = 0x000fffff; /// mask for signal & exit status433/// exit status to be returned, valid for child process only
355pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK);434pub const NOTE_EXITSTATUS = 0x04000000;
356435
357pub const NOTE_EXIT_DETAIL_MASK = 0x00070000;436/// provide details on reasons for exit
358pub const NOTE_EXIT_DECRYPTFAIL = 0x00010000;437pub const NOTE_EXIT_DETAIL = 0x02000000;
359pub const NOTE_EXIT_MEMORY = 0x00020000;
360pub const NOTE_EXIT_CSERROR = 0x00040000;
361438
439/// mask for signal & exit status
440pub const NOTE_PDATAMASK = 0x000fffff;
441pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK);
362442
363pub const NOTE_VM_PRESSURE = 0x80000000; /// will react on memory pressure443pub const NOTE_EXIT_DETAIL_MASK = 0x00070000;
364pub const NOTE_VM_PRESSURE_TERMINATE = 0x40000000; /// will quit on memory pressure, possibly after cleaning up dirty state444pub const NOTE_EXIT_DECRYPTFAIL = 0x00010000;
365pub const NOTE_VM_PRESSURE_SUDDEN_TERMINATE = 0x20000000; /// will quit immediately on memory pressure445pub const NOTE_EXIT_MEMORY = 0x00020000;
366pub const NOTE_VM_ERROR = 0x10000000; /// there was an error446pub const NOTE_EXIT_CSERROR = 0x00040000;
367447
368pub const NOTE_SECONDS = 0x00000001; /// data is seconds 448/// will react on memory pressure
369pub const NOTE_USECONDS = 0x00000002; /// data is microseconds 449pub const NOTE_VM_PRESSURE = 0x80000000;
370pub const NOTE_NSECONDS = 0x00000004; /// data is nanoseconds
371pub const NOTE_ABSOLUTE = 0x00000008; /// absolute timeout
372450
373pub const NOTE_LEEWAY = 0x00000010; /// ext[1] holds leeway for power aware timers451/// will quit on memory pressure, possibly after cleaning up dirty state
374pub const NOTE_CRITICAL = 0x00000020; /// system does minimal timer coalescing452pub const NOTE_VM_PRESSURE_TERMINATE = 0x40000000;
375pub const NOTE_BACKGROUND = 0x00000040; /// system does maximum timer coalescing
376pub const NOTE_MACH_CONTINUOUS_TIME = 0x00000080;
377pub const NOTE_MACHTIME = 0x00000100; /// data is mach absolute time units
378453
454/// will quit immediately on memory pressure
455pub const NOTE_VM_PRESSURE_SUDDEN_TERMINATE = 0x20000000;
456
457/// there was an error
458pub const NOTE_VM_ERROR = 0x10000000;
459
460/// data is seconds
461pub const NOTE_SECONDS = 0x00000001;
462
463/// data is microseconds
464pub const NOTE_USECONDS = 0x00000002;
465
466/// data is nanoseconds
467pub const NOTE_NSECONDS = 0x00000004;
468
469/// absolute timeout
470pub const NOTE_ABSOLUTE = 0x00000008;
471
472/// ext[1] holds leeway for power aware timers
473pub const NOTE_LEEWAY = 0x00000010;
474
475/// system does minimal timer coalescing
476pub const NOTE_CRITICAL = 0x00000020;
477
478/// system does maximum timer coalescing
479pub const NOTE_BACKGROUND = 0x00000040;
480pub const NOTE_MACH_CONTINUOUS_TIME = 0x00000080;
481
482/// data is mach absolute time units
483pub const NOTE_MACHTIME = 0x00000100;
379484
380fn wstatus(x: i32) i32 {485fn wstatus(x: i32) i32 {
381 return x & 0o177;486 return x & 0o177;
...@@ -503,12 +608,23 @@ pub fn kqueue() usize {...@@ -503,12 +608,23 @@ pub fn kqueue() usize {
503}608}
504609
505pub fn kevent(kq: i32, changelist: []const Kevent, eventlist: []Kevent, timeout: ?*const timespec) usize {610pub fn kevent(kq: i32, changelist: []const Kevent, eventlist: []Kevent, timeout: ?*const timespec) usize {
506 return errnoWrap(c.kevent(kq, changelist.ptr, @intCast(c_int, changelist.len), eventlist.ptr, @intCast(c_int, eventlist.len), timeout,));611 return errnoWrap(c.kevent(
507}612 kq,
508613 changelist.ptr,
509pub fn kevent64(kq: i32, changelist: []const kevent64_s, eventlist: []kevent64_s, flags: u32,614 @intCast(c_int, changelist.len),
510 timeout: ?*const timespec) usize615 eventlist.ptr,
511{616 @intCast(c_int, eventlist.len),
617 timeout,
618 ));
619}
620
621pub fn kevent64(
622 kq: i32,
623 changelist: []const kevent64_s,
624 eventlist: []kevent64_s,
625 flags: u32,
626 timeout: ?*const timespec,
627) usize {
512 return errnoWrap(c.kevent64(kq, changelist.ptr, changelist.len, eventlist.ptr, eventlist.len, flags, timeout));628 return errnoWrap(c.kevent64(kq, changelist.ptr, changelist.len, eventlist.ptr, eventlist.len, flags, timeout));
513}629}
514630
std/os/index.zig+8-5
...@@ -2810,7 +2810,7 @@ pub fn cpuCount(fallback_allocator: *mem.Allocator) CpuCountError!usize {...@@ -2810,7 +2810,7 @@ pub fn cpuCount(fallback_allocator: *mem.Allocator) CpuCountError!usize {
2810 }2810 }
2811}2811}
28122812
2813pub const BsdKQueueError = error {2813pub const BsdKQueueError = error{
2814 /// The per-process limit on the number of open file descriptors has been reached.2814 /// The per-process limit on the number of open file descriptors has been reached.
2815 ProcessFdQuotaExceeded,2815 ProcessFdQuotaExceeded,
28162816
...@@ -2831,7 +2831,7 @@ pub fn bsdKQueue() BsdKQueueError!i32 {...@@ -2831,7 +2831,7 @@ pub fn bsdKQueue() BsdKQueueError!i32 {
2831 }2831 }
2832}2832}
28332833
2834pub const BsdKEventError = error {2834pub const BsdKEventError = error{
2835 /// The process does not have permission to register a filter.2835 /// The process does not have permission to register a filter.
2836 AccessDenied,2836 AccessDenied,
28372837
...@@ -2845,9 +2845,12 @@ pub const BsdKEventError = error {...@@ -2845,9 +2845,12 @@ pub const BsdKEventError = error {
2845 ProcessNotFound,2845 ProcessNotFound,
2846};2846};
28472847
2848pub fn bsdKEvent(kq: i32, changelist: []const posix.Kevent, eventlist: []posix.Kevent,2848pub fn bsdKEvent(
2849 timeout: ?*const posix.timespec) BsdKEventError!usize2849 kq: i32,
2850{2850 changelist: []const posix.Kevent,
2851 eventlist: []posix.Kevent,
2852 timeout: ?*const posix.timespec,
2853) BsdKEventError!usize {
2851 while (true) {2854 while (true) {
2852 const rc = posix.kevent(kq, changelist, eventlist, timeout);2855 const rc = posix.kevent(kq, changelist, eventlist, timeout);
2853 const err = posix.getErrno(rc);2856 const err = posix.getErrno(rc);
std/special/compiler_rt/extendXfYf2_test.zig+20-20
...@@ -31,7 +31,7 @@ fn test__extendhfsf2(a: u16, expected: u32) void {...@@ -31,7 +31,7 @@ fn test__extendhfsf2(a: u16, expected: u32) void {
3131
32 if (rep == expected) {32 if (rep == expected) {
33 if (rep & 0x7fffffff > 0x7f800000) {33 if (rep & 0x7fffffff > 0x7f800000) {
34 return; // NaN is always unequal.34 return; // NaN is always unequal.
35 }35 }
36 if (x == @bitCast(f32, expected)) {36 if (x == @bitCast(f32, expected)) {
37 return;37 return;
...@@ -86,33 +86,33 @@ test "extenddftf2" {...@@ -86,33 +86,33 @@ test "extenddftf2" {
86}86}
8787
88test "extendhfsf2" {88test "extendhfsf2" {
89 test__extendhfsf2(0x7e00, 0x7fc00000); // qNaN89 test__extendhfsf2(0x7e00, 0x7fc00000); // qNaN
90 test__extendhfsf2(0x7f00, 0x7fe00000); // sNaN90 test__extendhfsf2(0x7f00, 0x7fe00000); // sNaN
91 test__extendhfsf2(0x7c01, 0x7f802000); // sNaN91 test__extendhfsf2(0x7c01, 0x7f802000); // sNaN
9292
93 test__extendhfsf2(0, 0); // 093 test__extendhfsf2(0, 0); // 0
94 test__extendhfsf2(0x8000, 0x80000000); // -094 test__extendhfsf2(0x8000, 0x80000000); // -0
9595
96 test__extendhfsf2(0x7c00, 0x7f800000); // inf96 test__extendhfsf2(0x7c00, 0x7f800000); // inf
97 test__extendhfsf2(0xfc00, 0xff800000); // -inf97 test__extendhfsf2(0xfc00, 0xff800000); // -inf
9898
99 test__extendhfsf2(0x0001, 0x33800000); // denormal (min), 2**-2499 test__extendhfsf2(0x0001, 0x33800000); // denormal (min), 2**-24
100 test__extendhfsf2(0x8001, 0xb3800000); // denormal (min), -2**-24100 test__extendhfsf2(0x8001, 0xb3800000); // denormal (min), -2**-24
101101
102 test__extendhfsf2(0x03ff, 0x387fc000); // denormal (max), 2**-14 - 2**-24102 test__extendhfsf2(0x03ff, 0x387fc000); // denormal (max), 2**-14 - 2**-24
103 test__extendhfsf2(0x83ff, 0xb87fc000); // denormal (max), -2**-14 + 2**-24103 test__extendhfsf2(0x83ff, 0xb87fc000); // denormal (max), -2**-14 + 2**-24
104104
105 test__extendhfsf2(0x0400, 0x38800000); // normal (min), 2**-14105 test__extendhfsf2(0x0400, 0x38800000); // normal (min), 2**-14
106 test__extendhfsf2(0x8400, 0xb8800000); // normal (min), -2**-14106 test__extendhfsf2(0x8400, 0xb8800000); // normal (min), -2**-14
107107
108 test__extendhfsf2(0x7bff, 0x477fe000); // normal (max), 65504108 test__extendhfsf2(0x7bff, 0x477fe000); // normal (max), 65504
109 test__extendhfsf2(0xfbff, 0xc77fe000); // normal (max), -65504109 test__extendhfsf2(0xfbff, 0xc77fe000); // normal (max), -65504
110110
111 test__extendhfsf2(0x3c01, 0x3f802000); // normal, 1 + 2**-10111 test__extendhfsf2(0x3c01, 0x3f802000); // normal, 1 + 2**-10
112 test__extendhfsf2(0xbc01, 0xbf802000); // normal, -1 - 2**-10112 test__extendhfsf2(0xbc01, 0xbf802000); // normal, -1 - 2**-10
113113
114 test__extendhfsf2(0x3555, 0x3eaaa000); // normal, approx. 1/3114 test__extendhfsf2(0x3555, 0x3eaaa000); // normal, approx. 1/3
115 test__extendhfsf2(0xb555, 0xbeaaa000); // normal, approx. -1/3115 test__extendhfsf2(0xb555, 0xbeaaa000); // normal, approx. -1/3
116}116}
117117
118test "extendsftf2" {118test "extendsftf2" {