diff --git a/stdlib/src/resource.rs b/stdlib/src/resource.rs index 1d3513f47d..37247196bd 100644 --- a/stdlib/src/resource.rs +++ b/stdlib/src/resource.rs @@ -149,7 +149,7 @@ mod resource { #[pyfunction] fn getrlimit(resource: i32, vm: &VirtualMachine) -> PyResult { - if resource < 0 || resource >= RLIM_NLIMITS as _ { + if resource < 0 || resource >= RLIM_NLIMITS as i32 { return Err(vm.new_value_error("invalid resource specified".to_owned())); } let rlimit = unsafe { @@ -164,7 +164,7 @@ mod resource { #[pyfunction] fn setrlimit(resource: i32, limits: Limits, vm: &VirtualMachine) -> PyResult<()> { - if resource < 0 || resource >= RLIM_NLIMITS as _ { + if resource < 0 || resource >= RLIM_NLIMITS as i32 { return Err(vm.new_value_error("invalid resource specified".to_owned())); } let res = unsafe { diff --git a/vm/Cargo.toml b/vm/Cargo.toml index e84739db3a..299807cacc 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -38,11 +38,11 @@ num-traits = "0.2.14" num-integer = "0.1.44" num-rational = "0.4.0" rand = "0.8.5" -getrandom = { version = "0.2.6", features = ["js"] } +getrandom = { version = "0.2.6", features = ["custom"] } log = "0.4.16" serde = { version = "1.0.136", features = ["derive"] } caseless = "0.2.1" -chrono = { version = "0.4.19", features = ["wasmbind"] } +chrono = { version = "=0.4.19" } itertools = "0.10.3" hex = "0.4.3" hexf-parse = "0.2.1" @@ -71,6 +71,7 @@ flate2 = "1.0.23" once_cell = "1.10.0" memoffset = "0.6.5" optional = "0.5.0" +ic-cdk = "0.6.8" # RustPython crates implementing functionality based on CPython sre-engine = "0.4.1" @@ -126,8 +127,8 @@ features = [ "impl-default", "vcruntime", "ifdef", "netioapi", "memoryapi", ] -[target.'cfg(target_arch = "wasm32")'.dependencies] -wasm-bindgen = "0.2.80" +# [target.'cfg(target_arch = "wasm32")'.dependencies] +# wasm-bindgen = "0.2.80" [build-dependencies] itertools = "0.10.3" diff --git a/vm/src/stdlib/time.rs b/vm/src/stdlib/time.rs index ce1f4d88a0..bb40baa3b9 100644 --- a/vm/src/stdlib/time.rs +++ b/vm/src/stdlib/time.rs @@ -91,15 +91,17 @@ mod time { #[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] fn _time(_vm: &VirtualMachine) -> PyResult { - use wasm_bindgen::prelude::*; - #[wasm_bindgen] - extern "C" { - type Date; - #[wasm_bindgen(static_method_of = Date)] - fn now() -> f64; - } - // Date.now returns unix time in milliseconds, we want it in seconds - Ok(Date::now() / 1000.0) + // use wasm_bindgen::prelude::*; + // #[wasm_bindgen] + // extern "C" { + // type Date; + // #[wasm_bindgen(static_method_of = Date)] + // fn now() -> f64; + // } + // // Date.now returns unix time in milliseconds, we want it in seconds + // Ok(Date::now() / 1000.0) + + Ok(ic_cdk::api::time() as f64 / 1_000_000_000 as f64) } #[pyfunction] @@ -144,14 +146,20 @@ mod time { fn naive_or_local(self, vm: &VirtualMachine) -> PyResult { Ok(match self { OptionalArg::Present(secs) => pyobj_to_naive_date_time(secs, vm)?, - OptionalArg::Missing => chrono::offset::Local::now().naive_local(), + OptionalArg::Missing => chrono::NaiveDateTime::from_timestamp( + (ic_cdk::api::time() / 1_000_000_000) as i64, + 0, + ), }) } fn naive_or_utc(self, vm: &VirtualMachine) -> PyResult { Ok(match self { OptionalArg::Present(secs) => pyobj_to_naive_date_time(secs, vm)?, - OptionalArg::Missing => chrono::offset::Utc::now().naive_utc(), + OptionalArg::Missing => chrono::NaiveDateTime::from_timestamp( + (ic_cdk::api::time() / 1_000_000_000) as i64, + 0, + ), }) } } @@ -160,7 +168,10 @@ mod time { fn naive_or_local(self, vm: &VirtualMachine) -> PyResult { Ok(match self { OptionalArg::Present(t) => t.to_date_time(vm)?, - OptionalArg::Missing => chrono::offset::Local::now().naive_local(), + OptionalArg::Missing => chrono::NaiveDateTime::from_timestamp( + (ic_cdk::api::time() / 1_000_000_000) as i64, + 0, + ), }) } } diff --git a/vm/src/vm/interpreter.rs b/vm/src/vm/interpreter.rs index 8d0d85ea5c..75f4d4eb31 100644 --- a/vm/src/vm/interpreter.rs +++ b/vm/src/vm/interpreter.rs @@ -22,7 +22,7 @@ use std::sync::atomic::Ordering; /// }); /// ``` pub struct Interpreter { - vm: VirtualMachine, + pub vm: VirtualMachine, } impl Interpreter { diff --git a/vm/src/vm/vm_object.rs b/vm/src/vm/vm_object.rs index b20c446b96..2a948abed2 100644 --- a/vm/src/vm/vm_object.rs +++ b/vm/src/vm/vm_object.rs @@ -42,16 +42,17 @@ impl VirtualMachine { } #[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] { - use wasm_bindgen::prelude::*; - #[wasm_bindgen] - extern "C" { - #[wasm_bindgen(js_namespace = console)] - fn error(s: &str); - } - let mut s = String::new(); - self.write_exception(&mut s, &exc).unwrap(); - error(&s); - panic!("{}; exception backtrace above", msg) + // use wasm_bindgen::prelude::*; + // #[wasm_bindgen] + // extern "C" { + // #[wasm_bindgen(js_namespace = console)] + // fn error(s: &str); + // } + // let mut s = String::new(); + // self.write_exception(&mut s, &exc).unwrap(); + // error(&s); + // panic!("{}; exception backtrace above", msg) + panic!("{}", msg) } }