authorgravatar for tgschultz@gmail.comtgschultz <tgschultz@gmail.com> 2018-04-18 15:46:50-05:00
committergravatar for tgschultz@gmail.comtgschultz <tgschultz@gmail.com> 2018-04-18 15:46:50-05:00
logbf9cf28322bf19aef72cbc5876e2ca083f762d7c
treed80b14afe0c211b2620e3cfe6da424fc8bff29ff
parent8b66dd8c7d2809c3ec86f1eec8acc0a1c184c8c2

Fixed compiler errors around darwin code.


4 files changed, 21 insertions(+), 13 deletions(-)

std/c/darwin.zig+1-1
...@@ -4,7 +4,7 @@ pub extern "c" fn _NSGetExecutablePath(buf: &u8, bufsize: &u32) c_int;...@@ -4,7 +4,7 @@ pub extern "c" fn _NSGetExecutablePath(buf: &u8, bufsize: &u32) c_int;
4pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: &u8, buf_len: usize, basep: &i64) usize;4pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: &u8, buf_len: usize, basep: &i64) usize;
55
6pub extern "c" fn mach_absolute_time() u64;6pub extern "c" fn mach_absolute_time() u64;
7pub extern "c" fn mach_timebase_info(&mach_timebase_info_data) void;7pub extern "c" fn mach_timebase_info(tinfo: ?&mach_timebase_info_data) void;
88
9pub use @import("../os/darwin_errno.zig");9pub use @import("../os/darwin_errno.zig");
1010
std/c/index.zig+1-1
...@@ -40,7 +40,7 @@ pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) c_int;...@@ -40,7 +40,7 @@ pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) c_int;
40pub extern "c" fn readlink(noalias path: &const u8, noalias buf: &u8, bufsize: usize) isize;40pub extern "c" fn readlink(noalias path: &const u8, noalias buf: &u8, bufsize: usize) isize;
41pub extern "c" fn realpath(noalias file_name: &const u8, noalias resolved_name: &u8) ?&u8;41pub extern "c" fn realpath(noalias file_name: &const u8, noalias resolved_name: &u8) ?&u8;
42pub extern "c" fn sigprocmask(how: c_int, noalias set: &const sigset_t, noalias oset: ?&sigset_t) c_int;42pub extern "c" fn sigprocmask(how: c_int, noalias set: &const sigset_t, noalias oset: ?&sigset_t) c_int;
43pub extern "c" fn gettimeofday(&timeval, ?&timezone) c_int;43pub extern "c" fn gettimeofday(tv: ?&timeval, tz: ?&timezone) c_int;
44pub extern "c" fn sigaction(sig: c_int, noalias act: &const Sigaction, noalias oact: ?&Sigaction) c_int;44pub extern "c" fn sigaction(sig: c_int, noalias act: &const Sigaction, noalias oact: ?&Sigaction) c_int;
45pub extern "c" fn nanosleep(rqtp: &const timespec, rmtp: ?&timespec) c_int;45pub extern "c" fn nanosleep(rqtp: &const timespec, rmtp: ?&timespec) c_int;
46pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;46pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;
std/os/darwin.zig+10-2
...@@ -251,8 +251,8 @@ pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) u...@@ -251,8 +251,8 @@ pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) u
251 return errnoWrap(c.readlink(path, buf_ptr, buf_len));251 return errnoWrap(c.readlink(path, buf_ptr, buf_len));
252}252}
253253
254pub fn gettimeofday(&timeval, ?&timezone) usize {254pub fn gettimeofday(tv: ?&timeval, tz: ?&timezone) usize {
255 return errnoWrap(c.gettimeofday(timeval, timezone));255 return errnoWrap(c.gettimeofday(tv, tz));
256}256}
257257
258pub fn nanosleep(req: &const timespec, rem: ?&timespec) usize {258pub fn nanosleep(req: &const timespec, rem: ?&timespec) usize {
...@@ -322,3 +322,11 @@ pub fn sigaddset(set: &sigset_t, signo: u5) void {...@@ -322,3 +322,11 @@ pub fn sigaddset(set: &sigset_t, signo: u5) void {
322fn errnoWrap(value: isize) usize {322fn errnoWrap(value: isize) usize {
323 return @bitCast(usize, if (value == -1) -isize(*c._errno()) else value);323 return @bitCast(usize, if (value == -1) -isize(*c._errno()) else value);
324}324}
325
326
327pub const timezone = c.timezone;
328pub const timeval = c.timeval;
329pub const mach_timebase_info_data = c.mach_timebase_info_data;
330
331pub const mach_absolute_time = c.mach_absolute_time;
332pub const mach_timebase_info = c.mach_timebase_info;
\ No newline at end of file
std/os/time.zig+9-9
...@@ -79,8 +79,9 @@ fn miliTimestampDarwin() u64 {...@@ -79,8 +79,9 @@ fn miliTimestampDarwin() u64 {
79 var tv: darwin.timeval = undefined;79 var tv: darwin.timeval = undefined;
80 var err = darwin.gettimeofday(&tv, null);80 var err = darwin.gettimeofday(&tv, null);
81 debug.assert(err == 0);81 debug.assert(err == 0);
82 return tv.tv_sec * ms_per_s + ts.tv_usec82 const sec_ms = tv.tv_sec * ms_per_s;
83 * (us_per_s / ms_per_s);83 const usec_ms = @divFloor(tv.tv_usec, (us_per_s / ms_per_s));
84 return u64(sec_ms) + u64(usec_ms);
84}85}
8586
86fn miliTimestampPosix() u64 {87fn miliTimestampPosix() u64 {
...@@ -136,7 +137,8 @@ pub const Timer = struct {...@@ -136,7 +137,8 @@ pub const Timer = struct {
136 // impossible here barring cosmic rays or other such occurances of137 // impossible here barring cosmic rays or other such occurances of
137 // incredibly bad luck.138 // incredibly bad luck.
138 //On Darwin: This cannot fail, as far as I am able to tell.139 //On Darwin: This cannot fail, as far as I am able to tell.
139 pub fn start() !Timer {140 const TimerError = error{TimerUnsupported};
141 pub fn start() TimerError!Timer {
140 var self: Timer = undefined;142 var self: Timer = undefined;
141 143
142 switch(builtin.os) {144 switch(builtin.os) {
...@@ -163,9 +165,9 @@ pub const Timer = struct {...@@ -163,9 +165,9 @@ pub const Timer = struct {
163 self.start_time = u64(ts.tv_sec * ns_per_s + ts.tv_nsec);165 self.start_time = u64(ts.tv_sec * ns_per_s + ts.tv_nsec);
164 },166 },
165 Os.macosx, Os.ios => {167 Os.macosx, Os.ios => {
166 darwin.c.mach_timebase_info(&self.frequency);168 darwin.mach_timebase_info(&self.frequency);
167 self.resolution = @divFloor(self.frequency.numer, self.denom);169 self.resolution = @divFloor(self.frequency.numer, self.frequency.denom);
168 self.start_time = darwin.c.mach_absolute_time();170 self.start_time = darwin.mach_absolute_time();
169 },171 },
170 else => @compileError("Unsupported OS"),172 else => @compileError("Unsupported OS"),
171 }173 }
...@@ -213,9 +215,7 @@ pub const Timer = struct {...@@ -213,9 +215,7 @@ pub const Timer = struct {
213 }215 }
214 216
215 fn clockDarwin() u64 {217 fn clockDarwin() u64 {
216 var result: u64 = undefined;218 return darwin.mach_absolute_time();
217 darwin.c.mach_absolute_time(&result);
218 return result;
219 }219 }
220 220
221 fn clockLinux() u64 {221 fn clockLinux() u64 {