Fix unsatisfied times import on wasi

This commit is contained in:
Noa authored and Noa committed 2022-01-26 13:01:35 -06:00
1 parent 5aef92cf4f
commit 8c9fb2c775
3 files changed
+18 -9

No files matched your search

Generated
+2 -2
View File
@@ -993,9 +993,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.107"
version = "0.2.112"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbe5e23404da5b4f555ef85ebed98fb4083e55a00c317800bc2a50ede9f3d219"
checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125"
[[package]]
name = "libffi"
+1 -1
View File
@@ -48,7 +48,7 @@ hexf-parse = "0.2.1"
indexmap = "1.0.2"
ahash = "0.7.2"
bitflags = "1.3"
libc = "0.2.99"
libc = "0.2.107"
nix = "0.23"
paste = "1.0.5"
is-macro = "0.1"
+15 -6
View File
@@ -248,7 +248,7 @@ mod time {
Ok(get_thread_time(vm)?.as_nanos() as u64)
}
#[cfg(any(windows, all(target_arch = "wasm32", not(target_os = "unknown"))))]
#[cfg(any(windows, all(target_arch = "wasm32", target_arch = "emscripten")))]
pub(super) fn time_muldiv(ticks: i64, mul: i64, div: i64) -> u64 {
let intpart = ticks / div;
let ticks = ticks % div;
@@ -256,7 +256,7 @@ mod time {
(intpart * mul + remaining) as u64
}
#[cfg(all(target_arch = "wasm32", not(target_os = "unknown")))]
#[cfg(all(target_arch = "wasm32", target_os = "emscripten"))]
fn get_process_time(vm: &VirtualMachine) -> PyResult<Duration> {
let t: libc::tms = unsafe {
let mut t = std::mem::MaybeUninit::uninit();
@@ -265,10 +265,6 @@ mod time {
}
t.assume_init()
};
#[cfg(target_os = "wasi")]
let freq = 60;
#[cfg(not(target_os = "wasi"))]
let freq = unsafe { libc::sysconf(libc::_SC_CLK_TCK) };
Ok(Duration::from_nanos(
@@ -276,6 +272,19 @@ mod time {
))
}
// same as the get_process_time impl for most unixes
#[cfg(all(target_arch = "wasm32", target_os = "wasi"))]
pub(super) fn get_process_time(vm: &VirtualMachine) -> PyResult<Duration> {
let time: libc::timespec = unsafe {
let mut time = std::mem::MaybeUninit::uninit();
if libc::clock_gettime(libc::CLOCK_PROCESS_CPUTIME_ID, time.as_mut_ptr()) == -1 {
return Err(vm.new_os_error("Failed to get clock time".to_owned()));
}
time.assume_init()
};
Ok(Duration::new(time.tv_sec as u64, time.tv_nsec as u32))
}
#[cfg(not(any(
windows,
target_os = "macos",