Skip to content

Commit be74fb9

Browse files
authored
Merge pull request #3111 from youknowone/posix
split `posix` and `nt` files from `os`
2 parents 0bb0946 + 56fb733 commit be74fb9

File tree

9 files changed

+2366
-2307
lines changed

9 files changed

+2366
-2307
lines changed

vm/src/stdlib/io.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ cfg_if::cfg_if! {
99
}
1010
}
1111

12-
#[cfg(unix)]
13-
use crate::stdlib::os::{errno_err, PathOrFd};
1412
use crate::{PyObjectRef, PyResult, TryFromObject, VirtualMachine};
1513
pub(crate) use _io::io_open as open;
1614

@@ -89,7 +87,7 @@ mod _io {
8987
PyThreadMutex, PyThreadMutexGuard,
9088
};
9189
use crate::common::rc::PyRc;
92-
use crate::exceptions::{self, IntoPyException, PyBaseExceptionRef};
90+
use crate::exceptions::{self, PyBaseExceptionRef};
9391
use crate::function::{ArgIterable, FuncArgs, OptionalArg, OptionalOption};
9492
use crate::slots::SlotConstructor;
9593
use crate::utils::Either;
@@ -159,6 +157,7 @@ mod _io {
159157
fn os_err(vm: &VirtualMachine, err: io::Error) -> PyBaseExceptionRef {
160158
#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
161159
{
160+
use crate::exceptions::IntoPyException;
162161
err.into_pyexception(vm)
163162
}
164163
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
@@ -3530,8 +3529,11 @@ mod _io {
35303529

35313530
// check file descriptor validity
35323531
#[cfg(unix)]
3533-
if let Ok(PathOrFd::Fd(fd)) = PathOrFd::try_from_object(vm, file.clone()) {
3534-
nix::fcntl::fcntl(fd, nix::fcntl::F_GETFD).map_err(|_| errno_err(vm))?;
3532+
if let Ok(crate::stdlib::os::PathOrFd::Fd(fd)) =
3533+
TryFromObject::try_from_object(vm, file.clone())
3534+
{
3535+
nix::fcntl::fcntl(fd, nix::fcntl::F_GETFD)
3536+
.map_err(|_| crate::stdlib::os::errno_err(vm))?;
35353537
}
35363538

35373539
// Construct a FileIO (subclass of RawIOBase)

vm/src/stdlib/mod.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
use crate::vm::VirtualMachine;
2-
use crate::PyObjectRef;
3-
use std::borrow::Cow;
4-
use std::collections::HashMap;
5-
61
mod array;
72
#[cfg(feature = "rustpython-ast")]
83
pub(crate) mod ast;
@@ -52,6 +47,16 @@ mod zlib;
5247
#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
5348
#[macro_use]
5449
pub(crate) mod os;
50+
#[cfg(windows)]
51+
pub(crate) mod nt;
52+
#[cfg(unix)]
53+
pub(crate) mod posix;
54+
#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
55+
#[cfg(not(any(unix, windows)))]
56+
pub(crate) mod posix_compat;
57+
#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
58+
#[cfg(not(any(unix, windows)))]
59+
pub(crate) use posix_compat as posix;
5560

5661
#[cfg(not(target_arch = "wasm32"))]
5762
mod faulthandler;
@@ -83,6 +88,11 @@ mod winapi;
8388
#[cfg(windows)]
8489
mod winreg;
8590

91+
use crate::vm::VirtualMachine;
92+
use crate::PyObjectRef;
93+
use std::borrow::Cow;
94+
use std::collections::HashMap;
95+
8696
pub type StdlibInitFunc = Box<py_dyn_fn!(dyn Fn(&VirtualMachine) -> PyObjectRef)>;
8797

8898
pub type StdlibMap = HashMap<Cow<'static, str>, StdlibInitFunc, ahash::RandomState>;
@@ -152,12 +162,9 @@ pub fn get_module_inits() -> StdlibMap {
152162
{
153163
"symtable" => symtable::make_module,
154164
}
155-
#[cfg(any(unix, windows, target_os = "wasi"))]
156-
{
157-
os::MODULE_NAME => os::make_module,
158-
}
159165
#[cfg(any(unix, target_os = "wasi"))]
160166
{
167+
"posix" => posix::make_module,
161168
"fcntl" => fcntl::make_module,
162169
}
163170
// disable some modules on WASM
@@ -195,6 +202,7 @@ pub fn get_module_inits() -> StdlibMap {
195202
// Windows-only
196203
#[cfg(windows)]
197204
{
205+
"nt" => nt::make_module,
198206
"msvcrt" => msvcrt::make_module,
199207
"_winapi" => winapi::make_module,
200208
"winreg" => winreg::make_module,

vm/src/stdlib/msvcrt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::os::errno_err;
22
use crate::{
33
builtins::{PyBytes, PyStrRef},
4-
PyObjectRef, PyRef, PyResult, VirtualMachine,
4+
suppress_iph, PyObjectRef, PyRef, PyResult, VirtualMachine,
55
};
66
use itertools::Itertools;
77
use winapi::{

0 commit comments

Comments
 (0)