mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
no more extend_module_platform_specific in os.rs
This commit is contained in:
@@ -914,7 +914,6 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
|
||||
let module = platform::make_module(vm);
|
||||
|
||||
_os::extend_module(&vm, &module);
|
||||
platform::extend_module_platform_specific(&vm, &module);
|
||||
|
||||
let support_funcs = _os::support_funcs(vm);
|
||||
let supports_fd = PySet::default().into_ref(vm);
|
||||
@@ -980,8 +979,103 @@ mod posix {
|
||||
pub(super) use std::os::unix::fs::OpenOptionsExt;
|
||||
use std::os::unix::io::RawFd;
|
||||
|
||||
#[pyattr]
|
||||
const WNOHANG: libc::c_int = libc::WNOHANG;
|
||||
#[pyattr]
|
||||
const EX_OK: i8 = exitcode::OK as i8;
|
||||
#[pyattr]
|
||||
const EX_USAGE: i8 = exitcode::USAGE as i8;
|
||||
#[pyattr]
|
||||
const EX_DATAERR: i8 = exitcode::DATAERR as i8;
|
||||
#[pyattr]
|
||||
const EX_NOINPUT: i8 = exitcode::NOINPUT as i8;
|
||||
#[pyattr]
|
||||
const EX_NOUSER: i8 = exitcode::NOUSER as i8;
|
||||
#[pyattr]
|
||||
const EX_NOHOST: i8 = exitcode::NOHOST as i8;
|
||||
#[pyattr]
|
||||
const EX_UNAVAILABLE: i8 = exitcode::UNAVAILABLE as i8;
|
||||
#[pyattr]
|
||||
const EX_SOFTWARE: i8 = exitcode::SOFTWARE as i8;
|
||||
#[pyattr]
|
||||
const EX_OSERR: i8 = exitcode::OSERR as i8;
|
||||
#[pyattr]
|
||||
const EX_OSFILE: i8 = exitcode::OSFILE as i8;
|
||||
#[pyattr]
|
||||
const EX_CANTCREAT: i8 = exitcode::CANTCREAT as i8;
|
||||
#[pyattr]
|
||||
const EX_IOERR: i8 = exitcode::IOERR as i8;
|
||||
#[pyattr]
|
||||
const EX_TEMPFAIL: i8 = exitcode::TEMPFAIL as i8;
|
||||
#[pyattr]
|
||||
const EX_PROTOCOL: i8 = exitcode::PROTOCOL as i8;
|
||||
#[pyattr]
|
||||
const EX_NOPERM: i8 = exitcode::NOPERM as i8;
|
||||
#[pyattr]
|
||||
const EX_CONFIG: i8 = exitcode::CONFIG as i8;
|
||||
#[pyattr]
|
||||
const O_NONBLOCK: libc::c_int = libc::O_NONBLOCK;
|
||||
#[pyattr]
|
||||
const O_CLOEXEC: libc::c_int = libc::O_CLOEXEC;
|
||||
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
#[pyattr]
|
||||
const O_DSYNC: libc::c_int = libc::O_DSYNC;
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
#[pyattr]
|
||||
const O_NDELAY: libc::c_int = libc::O_NDELAY;
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
#[pyattr]
|
||||
const O_NOCTTY: libc::c_int = libc::O_NOCTTY;
|
||||
|
||||
// cfg taken from nix
|
||||
#[cfg(any(
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd",
|
||||
all(
|
||||
target_os = "linux",
|
||||
not(any(target_env = "musl", target_arch = "mips", target_arch = "mips64"))
|
||||
)
|
||||
))]
|
||||
#[pyattr]
|
||||
const SEEK_DATA: i8 = unistd::Whence::SeekData as i8;
|
||||
#[cfg(any(
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd",
|
||||
all(
|
||||
target_os = "linux",
|
||||
not(any(target_env = "musl", target_arch = "mips", target_arch = "mips64"))
|
||||
)
|
||||
))]
|
||||
#[pyattr]
|
||||
const SEEK_HOLE: i8 = unistd::Whence::SeekHole as i8;
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
|
||||
#[pyattr]
|
||||
const POSIX_SPAWN_OPEN: i32 = PosixSpawnFileActionIdentifier::Open as i32;
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
|
||||
#[pyattr]
|
||||
const POSIX_SPAWN_CLOSE: i32 = PosixSpawnFileActionIdentifier::Close as i32;
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
|
||||
#[pyattr]
|
||||
const POSIX_SPAWN_DUP2: i32 = PosixSpawnFileActionIdentifier::Dup2 as i32;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[pyattr]
|
||||
const _COPYFILE_DATA: u32 = 1 << 3;
|
||||
|
||||
pub(super) type OpenFlags = i32;
|
||||
|
||||
// Flags for os_access
|
||||
bitflags! {
|
||||
pub struct AccessFlags: u8{
|
||||
const F_OK = super::_os::F_OK;
|
||||
const R_OK = super::_os::R_OK;
|
||||
const W_OK = super::_os::W_OK;
|
||||
const X_OK = super::_os::X_OK;
|
||||
}
|
||||
}
|
||||
|
||||
impl PyPathLike {
|
||||
pub fn into_bytes(self) -> Vec<u8> {
|
||||
use std::os::unix::ffi::OsStringExt;
|
||||
@@ -1008,16 +1102,6 @@ mod posix {
|
||||
}
|
||||
}
|
||||
|
||||
// Flags for os_access
|
||||
bitflags! {
|
||||
pub struct AccessFlags: u8{
|
||||
const F_OK = super::_os::F_OK;
|
||||
const R_OK = super::_os::R_OK;
|
||||
const W_OK = super::_os::W_OK;
|
||||
const X_OK = super::_os::X_OK;
|
||||
}
|
||||
}
|
||||
|
||||
struct Permissions {
|
||||
is_readable: bool,
|
||||
is_writable: bool,
|
||||
@@ -2027,8 +2111,7 @@ mod posix {
|
||||
flags: u32, // copyfile_flags_t
|
||||
) -> libc::c_int;
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
const COPYFILE_DATA: u32 = 1 << 3;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[pyfunction]
|
||||
fn _fcopyfile(in_fd: i32, out_fd: i32, flags: i32, vm: &VirtualMachine) -> PyResult<()> {
|
||||
@@ -2040,75 +2123,6 @@ mod posix {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn extend_module_platform_specific(vm: &VirtualMachine, module: &PyObjectRef) {
|
||||
let ctx = &vm.ctx;
|
||||
|
||||
extend_module!(vm, module, {
|
||||
"WNOHANG" => ctx.new_int(libc::WNOHANG),
|
||||
"EX_OK" => ctx.new_int(exitcode::OK as i8),
|
||||
"EX_USAGE" => ctx.new_int(exitcode::USAGE as i8),
|
||||
"EX_DATAERR" => ctx.new_int(exitcode::DATAERR as i8),
|
||||
"EX_NOINPUT" => ctx.new_int(exitcode::NOINPUT as i8),
|
||||
"EX_NOUSER" => ctx.new_int(exitcode::NOUSER as i8),
|
||||
"EX_NOHOST" => ctx.new_int(exitcode::NOHOST as i8),
|
||||
"EX_UNAVAILABLE" => ctx.new_int(exitcode::UNAVAILABLE as i8),
|
||||
"EX_SOFTWARE" => ctx.new_int(exitcode::SOFTWARE as i8),
|
||||
"EX_OSERR" => ctx.new_int(exitcode::OSERR as i8),
|
||||
"EX_OSFILE" => ctx.new_int(exitcode::OSFILE as i8),
|
||||
"EX_CANTCREAT" => ctx.new_int(exitcode::CANTCREAT as i8),
|
||||
"EX_IOERR" => ctx.new_int(exitcode::IOERR as i8),
|
||||
"EX_TEMPFAIL" => ctx.new_int(exitcode::TEMPFAIL as i8),
|
||||
"EX_PROTOCOL" => ctx.new_int(exitcode::PROTOCOL as i8),
|
||||
"EX_NOPERM" => ctx.new_int(exitcode::NOPERM as i8),
|
||||
"EX_CONFIG" => ctx.new_int(exitcode::CONFIG as i8),
|
||||
"O_NONBLOCK" => ctx.new_int(libc::O_NONBLOCK),
|
||||
"O_CLOEXEC" => ctx.new_int(libc::O_CLOEXEC),
|
||||
});
|
||||
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
extend_module!(vm, module, {
|
||||
|
||||
"O_DSYNC" => ctx.new_int(libc::O_DSYNC),
|
||||
"O_NDELAY" => ctx.new_int(libc::O_NDELAY),
|
||||
"O_NOCTTY" => ctx.new_int(libc::O_NOCTTY),
|
||||
});
|
||||
|
||||
// cfg taken from nix
|
||||
#[cfg(any(
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd",
|
||||
all(
|
||||
target_os = "linux",
|
||||
not(any(target_env = "musl", target_arch = "mips", target_arch = "mips64"))
|
||||
)
|
||||
))]
|
||||
extend_module!(vm, module, {
|
||||
"SEEK_DATA" => ctx.new_int(unistd::Whence::SeekData as i8),
|
||||
"SEEK_HOLE" => ctx.new_int(unistd::Whence::SeekHole as i8)
|
||||
});
|
||||
// cfg from nix
|
||||
#[cfg(any(
|
||||
target_os = "android",
|
||||
target_os = "dragonfly",
|
||||
target_os = "emscripten",
|
||||
target_os = "freebsd",
|
||||
target_os = "linux",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
|
||||
extend_module!(vm, module, {
|
||||
"POSIX_SPAWN_OPEN" => ctx.new_int(i32::from(PosixSpawnFileActionIdentifier::Open)),
|
||||
"POSIX_SPAWN_CLOSE" => ctx.new_int(i32::from(PosixSpawnFileActionIdentifier::Close)),
|
||||
"POSIX_SPAWN_DUP2" => ctx.new_int(i32::from(PosixSpawnFileActionIdentifier::Dup2)),
|
||||
});
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
extend_module!(vm, module, {
|
||||
"_COPYFILE_DATA" => ctx.new_int(COPYFILE_DATA),
|
||||
});
|
||||
}
|
||||
|
||||
pub(super) fn support_funcs(vm: &VirtualMachine) -> Vec<SupportFunc> {
|
||||
vec![
|
||||
SupportFunc::new(vm, "chmod", chmod, Some(false), Some(false), Some(false)),
|
||||
@@ -2137,6 +2151,9 @@ mod nt {
|
||||
#[cfg(target_env = "msvc")]
|
||||
use winapi::vc::vcruntime::intptr_t;
|
||||
|
||||
#[pyattr]
|
||||
const O_BINARY: libc::c_int = libc::O_BINARY;
|
||||
|
||||
pub(super) type OpenFlags = u32;
|
||||
|
||||
pub fn raw_file_number(handle: File) -> i64 {
|
||||
@@ -2479,13 +2496,6 @@ mod nt {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn extend_module_platform_specific(vm: &VirtualMachine, module: &PyObjectRef) {
|
||||
let ctx = &vm.ctx;
|
||||
extend_module!(vm, module, {
|
||||
"O_BINARY" => ctx.new_int(libc::O_BINARY),
|
||||
});
|
||||
}
|
||||
|
||||
pub(super) fn support_funcs(_vm: &VirtualMachine) -> Vec<SupportFunc> {
|
||||
Vec::new()
|
||||
}
|
||||
@@ -2555,8 +2565,6 @@ mod minor {
|
||||
vm.ctx.new_dict()
|
||||
}
|
||||
|
||||
pub fn extend_module_platform_specific(_vm: &VirtualMachine, _module: &PyObjectRef) {}
|
||||
|
||||
pub(super) fn support_funcs(_vm: &VirtualMachine) -> Vec<SupportFunc> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user