From 2cd5b8a86dd18418ddb00788969884866001ee14 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 31 Jul 2023 11:02:10 +0300 Subject: [PATCH] time: reduce the diff for `v run cmd/tools/check_os_api_parity time` --- vlib/time/time.c.v | 12 ++++++++++++ vlib/time/time_darwin.c.v | 4 ++-- vlib/time/time_linux.c.v | 8 ++++---- vlib/time/time_nix.c.v | 25 ++----------------------- vlib/time/time_solaris.c.v | 4 ++-- vlib/time/time_windows.c.v | 26 +++++++------------------- 6 files changed, 29 insertions(+), 50 deletions(-) diff --git a/vlib/time/time.c.v b/vlib/time/time.c.v index 8e993dfa9375c6..ce1a72d53c268b 100644 --- a/vlib/time/time.c.v +++ b/vlib/time/time.c.v @@ -135,3 +135,15 @@ pub fn (t Time) strftime(fmt string) string { C.strftime(&buf[0], usize(sizeof(buf)), fmt_c, tm) return unsafe { cstring_to_vstring(&char(&buf[0])) } } + +// some *nix system functions (e.g. `C.poll()`, C.epoll_wait()) accept an `int` +// value as *timeout in milliseconds* with the special value `-1` meaning "infinite" +pub fn (d Duration) sys_milliseconds() int { + if d > 2147483647 * millisecond { // treat 2147483647000001 .. C.INT64_MAX as "infinite" + return -1 + } else if d <= 0 { + return 0 // treat negative timeouts as 0 - consistent with Unix behaviour + } else { + return int(d / millisecond) + } +} diff --git a/vlib/time/time_darwin.c.v b/vlib/time/time_darwin.c.v index 45976080d016ec..3de9657c0e82b5 100644 --- a/vlib/time/time_darwin.c.v +++ b/vlib/time/time_darwin.c.v @@ -88,11 +88,11 @@ fn darwin_utc() Time { } // dummy to compile with all compilers -pub fn solaris_now() Time { +fn solaris_now() Time { return Time{} } // dummy to compile with all compilers -pub fn solaris_utc() Time { +fn solaris_utc() Time { return Time{} } diff --git a/vlib/time/time_linux.c.v b/vlib/time/time_linux.c.v index b0ab7ad7ce02a7..090a3494d46ce5 100644 --- a/vlib/time/time_linux.c.v +++ b/vlib/time/time_linux.c.v @@ -6,21 +6,21 @@ fn sys_mono_now_darwin() u64 { } // darwin_now - dummy fn to compile on all platforms/compilers -pub fn darwin_now() Time { +fn darwin_now() Time { return Time{} } // solaris_now - dummy fn to compile on all platforms/compilers -pub fn solaris_now() Time { +fn solaris_now() Time { return Time{} } // darwin_utc - dummy fn to compile on all platforms/compilers -pub fn darwin_utc() Time { +fn darwin_utc() Time { return Time{} } // solaris_utc - dummy fn to compile on all platforms/compilers -pub fn solaris_utc() Time { +fn solaris_utc() Time { return Time{} } diff --git a/vlib/time/time_nix.c.v b/vlib/time/time_nix.c.v index 117493425fdef4..0b2d24b25741aa 100644 --- a/vlib/time/time_nix.c.v +++ b/vlib/time/time_nix.c.v @@ -95,12 +95,12 @@ fn linux_utc() Time { } // dummy to compile with all compilers -pub fn win_now() Time { +fn win_now() Time { return Time{} } // dummy to compile with all compilers -pub fn win_utc() Time { +fn win_utc() Time { return Time{} } @@ -125,15 +125,6 @@ pub fn (d Duration) timespec() C.timespec { return ts } -// zero_timespec returns the calendar time in seconds and nanoseconds of the beginning of the Unix epoch. -pub fn zero_timespec() C.timespec { - ts := C.timespec{ - tv_sec: 0 - tv_nsec: 0 - } - return ts -} - // sleep suspends the execution of the calling thread for a given duration (in nanoseconds). pub fn sleep(duration Duration) { mut req := C.timespec{duration / second, duration % second} @@ -147,15 +138,3 @@ pub fn sleep(duration Duration) { } } } - -// some *nix system functions (e.g. `C.poll()`, C.epoll_wait()) accept an `int` -// value as *timeout in milliseconds* with the special value `-1` meaning "infinite" -pub fn (d Duration) sys_milliseconds() int { - if d > C.INT32_MAX * millisecond { // treat 2147483647000001 .. C.INT64_MAX as "infinite" - return -1 - } else if d <= 0 { - return 0 // treat negative timeouts as 0 - consistent with Unix behaviour - } else { - return int(d / millisecond) - } -} diff --git a/vlib/time/time_solaris.c.v b/vlib/time/time_solaris.c.v index b87f1c81d6ef01..fd037f46dc97ba 100644 --- a/vlib/time/time_solaris.c.v +++ b/vlib/time/time_solaris.c.v @@ -22,11 +22,11 @@ fn solaris_utc() Time { } // dummy to compile with all compilers -pub fn darwin_now() Time { +fn darwin_now() Time { return Time{} } // dummy to compile with all compilers -pub fn darwin_utc() Time { +fn darwin_utc() Time { return Time{} } diff --git a/vlib/time/time_windows.c.v b/vlib/time/time_windows.c.v index b14e011a15badb..0d76b4e8d1b5b1 100644 --- a/vlib/time/time_windows.c.v +++ b/vlib/time/time_windows.c.v @@ -171,7 +171,7 @@ fn win_utc() Time { } // unix_time returns Unix time. -pub fn (st SystemTime) unix_time() i64 { +fn (st SystemTime) unix_time() i64 { tt := C.tm{ tm_sec: st.second tm_min: st.minute @@ -184,32 +184,32 @@ pub fn (st SystemTime) unix_time() i64 { } // dummy to compile with all compilers -pub fn darwin_now() Time { +fn darwin_now() Time { return Time{} } // dummy to compile with all compilers -pub fn linux_now() Time { +fn linux_now() Time { return Time{} } // dummy to compile with all compilers -pub fn solaris_now() Time { +fn solaris_now() Time { return Time{} } // dummy to compile with all compilers -pub fn darwin_utc() Time { +fn darwin_utc() Time { return Time{} } // dummy to compile with all compilers -pub fn linux_utc() Time { +fn linux_utc() Time { return Time{} } // dummy to compile with all compilers -pub fn solaris_utc() Time { +fn solaris_utc() Time { return Time{} } @@ -223,15 +223,3 @@ pub struct C.timeval { pub fn sleep(duration Duration) { C.Sleep(int(duration / millisecond)) } - -// some Windows system functions (e.g. `C.WaitForSingleObject()`) accept an `u32` -// value as *timeout in milliseconds* with the special value `u32(-1)` meaning "infinite" -pub fn (d Duration) sys_milliseconds() u32 { - if d >= u32(-1) * millisecond { // treat 4294967295000000 .. C.INT64_MAX as "infinite" - return u32(-1) - } else if d <= 0 { - return 0 // treat negative timeouts as 0 - consistent with Unix behaviour - } else { - return u32(d / millisecond) - } -}