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;
44pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: &u8, buf_len: usize, basep: &i64) usize;
55
66pub 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
99pub 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;
4040pub extern "c" fn readlink(noalias path: &const u8, noalias buf: &u8, bufsize: usize) isize;
4141pub extern "c" fn realpath(noalias file_name: &const u8, noalias resolved_name: &u8) ?&u8;
4242pub 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;
4444pub extern "c" fn sigaction(sig: c_int, noalias act: &const Sigaction, noalias oact: ?&Sigaction) c_int;
4545pub extern "c" fn nanosleep(rqtp: &const timespec, rmtp: ?&timespec) c_int;
4646pub 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
251251 return errnoWrap(c.readlink(path, buf_ptr, buf_len));
252252}
253253
254pub fn gettimeofday(&timeval, ?&timezone) usize {
255 return errnoWrap(c.gettimeofday(timeval, timezone));
254pub fn gettimeofday(tv: ?&timeval, tz: ?&timezone) usize {
255 return errnoWrap(c.gettimeofday(tv, tz));
256256}
257257
258258pub fn nanosleep(req: &const timespec, rem: ?&timespec) usize {
......@@ -322,3 +322,11 @@ pub fn sigaddset(set: &sigset_t, signo: u5) void {
322322fn errnoWrap(value: isize) usize {
323323 return @bitCast(usize, if (value == -1) -isize(*c._errno()) else value);
324324}
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 {
7979 var tv: darwin.timeval = undefined;
8080 var err = darwin.gettimeofday(&tv, null);
8181 debug.assert(err == 0);
82 return tv.tv_sec * ms_per_s + ts.tv_usec
83 * (us_per_s / ms_per_s);
82 const sec_ms = tv.tv_sec * 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);
8485}
8586
8687fn miliTimestampPosix() u64 {
......@@ -136,7 +137,8 @@ pub const Timer = struct {
136137 // impossible here barring cosmic rays or other such occurances of
137138 // incredibly bad luck.
138139 //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 {
140142 var self: Timer = undefined;
141143
142144 switch(builtin.os) {
......@@ -163,9 +165,9 @@ pub const Timer = struct {
163165 self.start_time = u64(ts.tv_sec * ns_per_s + ts.tv_nsec);
164166 },
165167 Os.macosx, Os.ios => {
166 darwin.c.mach_timebase_info(&self.frequency);
167 self.resolution = @divFloor(self.frequency.numer, self.denom);
168 self.start_time = darwin.c.mach_absolute_time();
168 darwin.mach_timebase_info(&self.frequency);
169 self.resolution = @divFloor(self.frequency.numer, self.frequency.denom);
170 self.start_time = darwin.mach_absolute_time();
169171 },
170172 else => @compileError("Unsupported OS"),
171173 }
......@@ -213,9 +215,7 @@ pub const Timer = struct {
213215 }
214216
215217 fn clockDarwin() u64 {
216 var result: u64 = undefined;
217 darwin.c.mach_absolute_time(&result);
218 return result;
218 return darwin.mach_absolute_time();
219219 }
220220
221221 fn clockLinux() u64 {