From b5ff175b45f359c0933daf3d65b1ee476d8a8e0a Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Tue, 14 Feb 2023 16:25:53 -0600 Subject: [PATCH] Fix timer.rs cross-platform compilation * macOS does not have RUSAGE_THREAD * tv_sec and tv_usec may be i32 instead of i64 --- fish-rust/src/nix.rs | 2 +- fish-rust/src/timer.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/fish-rust/src/nix.rs b/fish-rust/src/nix.rs index 32afc0d1f..e7b0bda8a 100644 --- a/fish-rust/src/nix.rs +++ b/fish-rust/src/nix.rs @@ -3,7 +3,7 @@ use std::time::Duration; pub const fn timeval_to_duration(val: &libc::timeval) -> Duration { - let micros = val.tv_sec * (1E6 as i64) + val.tv_usec; + let micros = val.tv_sec as i64 * (1E6 as i64) + val.tv_usec as i64; Duration::from_micros(micros as u64) } diff --git a/fish-rust/src/timer.rs b/fish-rust/src/timer.rs index 0d61b20d9..5dc17eb43 100644 --- a/fish-rust/src/timer.rs +++ b/fish-rust/src/timer.rs @@ -68,10 +68,10 @@ fn push_timer_ffi(enabled: bool) -> Box { } /// An enumeration of supported libc rusage types used by [`getrusage()`]. +/// NB: RUSAGE_THREAD is not supported on macOS. enum RUsage { RSelf, // "Self" is a reserved keyword RChildren, - RThread, } /// A safe wrapper around `libc::getrusage()` @@ -81,7 +81,6 @@ fn getrusage(resource: RUsage) -> libc::rusage { match resource { RUsage::RSelf => libc::getrusage(libc::RUSAGE_SELF, rusage.as_mut_ptr()), RUsage::RChildren => libc::getrusage(libc::RUSAGE_CHILDREN, rusage.as_mut_ptr()), - RUsage::RThread => libc::getrusage(libc::RUSAGE_THREAD, rusage.as_mut_ptr()), } };