Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
corelib only expose pymodules
  • Loading branch information
youknowone committed Sep 28, 2021
commit f2b8699cc70f1b7620ca2b8cfd45dda492ea2632
2 changes: 1 addition & 1 deletion vm/src/builtins/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use crate::common::{
};
use crate::{
bytesinner::bytes_to_hex,
corelib::_struct::FormatSpec,
function::{FuncArgs, OptionalArg},
protocol::{BufferInternal, BufferOptions, PyBuffer},
sliceable::{convert_slice, wrap_index, SequenceIndex},
slots::{AsBuffer, Comparable, Hashable, PyComparisonOp, SlotConstructor},
stdlib::pystruct::_struct::FormatSpec,
utils::Either,
IdProtocol, IntoPyObject, PyClassImpl, PyComparisonValue, PyContext, PyObjectRef, PyRef,
PyResult, PyValue, TryFromBorrowedObject, TryFromObject, TypeProtocol, VirtualMachine,
Expand Down
5 changes: 5 additions & 0 deletions vm/src/corelib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[cfg(windows)]
pub use super::stdlib::nt::module as nt;
#[cfg(unix)]
pub use super::stdlib::posix::module as posix;
pub use super::stdlib::{pystruct::_struct, time::time};
1 change: 1 addition & 0 deletions vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ mod bytesinner;
pub mod byteslike;
pub mod cformat;
mod codecs;
pub mod corelib;
mod coroutine;
#[cfg(any(unix, windows, target_os = "wasi"))]
mod crt_fd;
Expand Down
2 changes: 1 addition & 1 deletion vm/src/stdlib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mod sysconfigdata;
mod syslog;
#[cfg(feature = "threading")]
mod thread;
mod time;
pub(crate) mod time;
mod unicodedata;
mod warnings;
mod weakref;
Expand Down
6 changes: 3 additions & 3 deletions vm/src/stdlib/nt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,11 @@ pub(crate) mod module {
#[macro_export]
macro_rules! suppress_iph {
($e:expr) => {{
let old = $crate::stdlib::nt::module::_set_thread_local_invalid_parameter_handler(
$crate::stdlib::nt::module::silent_iph_handler,
let old = $crate::corelib::nt::_set_thread_local_invalid_parameter_handler(
$crate::corelib::nt::silent_iph_handler,
);
let ret = $e;
$crate::stdlib::nt::module::_set_thread_local_invalid_parameter_handler(old);
$crate::corelib::nt::_set_thread_local_invalid_parameter_handler(old);
ret
}};
}
2 changes: 1 addition & 1 deletion vm/src/stdlib/pystruct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

#[pymodule]
pub(crate) mod _struct {
pub mod _struct {
use crate::{
builtins::{
bytes::PyBytesRef, float, pybool::IntoPyBool, pystr::PyStr, pystr::PyStrRef,
Expand Down
6 changes: 3 additions & 3 deletions vm/src/stdlib/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fn sec_to_timeval(sec: f64) -> timeval {
mod decl {
use super::*;
use crate::{
exceptions::IntoPyException, function::OptionalOption, stdlib::time, utils::Either,
corelib::time, exceptions::IntoPyException, function::OptionalOption, utils::Either,
PyObjectRef, PyResult, VirtualMachine,
};

Expand All @@ -171,7 +171,7 @@ mod decl {
return Err(vm.new_value_error("timeout must be positive".to_owned()));
}
}
let deadline = timeout.map(|s| time::get_time(vm).unwrap() + s);
let deadline = timeout.map(|s| time::time(vm).unwrap() + s);

let seq2set = |list| -> PyResult<(Vec<Selectable>, FdSet)> {
let v = vm.extract_elements::<Selectable>(list)?;
Expand Down Expand Up @@ -210,7 +210,7 @@ mod decl {
vm.check_signals()?;

if let Some(ref mut timeout) = timeout {
*timeout = deadline.unwrap() - time::get_time(vm).unwrap();
*timeout = deadline.unwrap() - time::time(vm).unwrap();
if *timeout < 0.0 {
r.clear();
w.clear();
Expand Down
8 changes: 4 additions & 4 deletions vm/src/stdlib/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyObjectRef {
}

#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
pub(crate) fn get_time(vm: &VirtualMachine) -> PyResult<f64> {
fn get_time(vm: &VirtualMachine) -> PyResult<f64> {
Ok(duration_since_system_now(vm)?.as_secs_f64())
}

#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
pub(crate) fn get_time(_vm: &VirtualMachine) -> PyResult<f64> {
fn get_time(_vm: &VirtualMachine) -> PyResult<f64> {
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
Expand All @@ -41,7 +41,7 @@ fn duration_since_system_now(vm: &VirtualMachine) -> PyResult<std::time::Duratio
}

#[pymodule(name = "time")]
mod time {
pub mod time {
use crate::{
builtins::{PyStrRef, PyTypeRef},
function::{FuncArgs, OptionalArg},
Expand Down Expand Up @@ -84,7 +84,7 @@ mod time {

#[pyfunction(name = "perf_counter")] // TODO: fix
#[pyfunction]
fn time(vm: &VirtualMachine) -> PyResult<f64> {
pub fn time(vm: &VirtualMachine) -> PyResult<f64> {
super::get_time(vm)
}

Expand Down