Skip to content
Open
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
18 changes: 15 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ rustpython-compiler-core = { path = "crates/compiler-core", version = "0.5.0" }
rustpython-compiler = { path = "crates/compiler", version = "0.5.0" }
rustpython-codegen = { path = "crates/codegen", version = "0.5.0" }
rustpython-common = { path = "crates/common", version = "0.5.0" }
rustpython-host_env = { path = "crates/host_env", version = "0.5.0" }
rustpython-derive = { path = "crates/derive", version = "0.5.0" }
rustpython-derive-impl = { path = "crates/derive-impl", version = "0.5.0" }
rustpython-jit = { path = "crates/jit", version = "0.5.0" }
Expand Down
14 changes: 0 additions & 14 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,5 @@ lock_api = "0.4"
siphasher = "1"
num-complex.workspace = true

[target.'cfg(unix)'.dependencies]
nix = { workspace = true }

[target.'cfg(windows)'.dependencies]
widestring = { workspace = true }
windows-sys = { workspace = true, features = [
"Win32_Foundation",
"Win32_Networking_WinSock",
"Win32_Storage_FileSystem",
"Win32_System_Ioctl",
"Win32_System_LibraryLoader",
"Win32_System_SystemServices",
] }

[lints]
workspace = true
12 changes: 0 additions & 12 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,22 @@

extern crate alloc;

#[macro_use]
mod macros;
pub use macros::*;

pub mod atomic;
pub mod borrow;
pub mod boxvec;
pub mod cformat;
#[cfg(all(feature = "std", any(unix, windows, target_os = "wasi")))]
pub mod crt_fd;
pub mod encodings;
#[cfg(all(feature = "std", any(not(target_arch = "wasm32"), target_os = "wasi")))]
pub mod fileutils;
pub mod float_ops;
pub mod format;
pub mod hash;
pub mod int;
pub mod linked_list;
pub mod lock;
#[cfg(feature = "std")]
pub mod os;
pub mod rand;
pub mod rc;
pub mod refcount;
pub mod static_cell;
pub mod str;
#[cfg(all(feature = "std", windows))]
pub mod windows;

pub use rustpython_wtf8 as wtf8;

Expand Down
41 changes: 41 additions & 0 deletions crates/host_env/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[package]
name = "rustpython-host_env"
description = "Host OS API abstractions for RustPython"
version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
repository.workspace = true
license.workspace = true

[dependencies]
rustpython-wtf8 = { workspace = true }

libc = { workspace = true }
num-traits = { workspace = true }

[target.'cfg(unix)'.dependencies]
nix = { workspace = true }

[target.'cfg(all(unix, not(target_os = "ios"), not(target_os = "redox")))'.dependencies]
termios = "0.3.3"

[target.'cfg(windows)'.dependencies]
widestring = { workspace = true }
windows-sys = { workspace = true, features = [
"Win32_Foundation",
"Win32_Globalization",
"Win32_Networking_WinSock",
"Win32_Storage_FileSystem",
"Win32_System_Console",
"Win32_System_Diagnostics_Debug",
"Win32_System_Ioctl",
"Win32_System_LibraryLoader",
"Win32_System_SystemInformation",
"Win32_System_SystemServices",
"Win32_System_Threading",
"Win32_System_Time",
] }

[lints]
workspace = true
File renamed without changes.
75 changes: 75 additions & 0 deletions crates/host_env/src/fcntl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use std::io;

pub fn fcntl_int(fd: i32, cmd: i32, arg: i32) -> io::Result<i32> {
let ret = unsafe { libc::fcntl(fd, cmd, arg) };
if ret < 0 {
Err(io::Error::last_os_error())
} else {
Ok(ret)
}
}

pub fn fcntl_with_bytes(fd: i32, cmd: i32, arg: &mut [u8]) -> io::Result<i32> {
let ret = unsafe { libc::fcntl(fd, cmd, arg.as_mut_ptr()) };
if ret < 0 {
Err(io::Error::last_os_error())
} else {
Ok(ret)
}
}

/// # Safety
///
/// `arg` must be a valid pointer for the `request` passed to `ioctl` and must
/// satisfy the platform ABI requirements for that request.
pub unsafe fn ioctl_ptr(
fd: i32,
request: libc::c_ulong,
arg: *mut libc::c_void,
) -> io::Result<i32> {
let ret = unsafe { libc::ioctl(fd, request as _, arg) };
if ret < 0 {
Err(io::Error::last_os_error())
} else {
Ok(ret)
}
}

pub fn ioctl_int(fd: i32, request: libc::c_ulong, arg: i32) -> io::Result<i32> {
let ret = unsafe { libc::ioctl(fd, request as _, arg) };
if ret < 0 {
Err(io::Error::last_os_error())
} else {
Ok(ret)
}
}

#[cfg(not(any(target_os = "wasi", target_os = "redox")))]
pub fn flock(fd: i32, operation: i32) -> io::Result<i32> {
let ret = unsafe { libc::flock(fd, operation) };
if ret < 0 {
Err(io::Error::last_os_error())
} else {
Ok(ret)
}
}

#[cfg(not(any(target_os = "wasi", target_os = "redox")))]
pub fn lockf(fd: i32, cmd: i32, lock: &libc::flock) -> io::Result<i32> {
let ret = unsafe {
libc::fcntl(
fd,
if (cmd & libc::LOCK_NB) != 0 {
libc::F_SETLK
} else {
libc::F_SETLKW
},
lock,
)
};
if ret < 0 {
Err(io::Error::last_os_error())
} else {
Ok(ret)
}
}
File renamed without changes.
40 changes: 40 additions & 0 deletions crates/host_env/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
extern crate alloc;

#[macro_use]
mod macros;
pub use macros::*;

pub mod os;

#[cfg(any(unix, windows, target_os = "wasi"))]
pub mod crt_fd;

#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
pub mod fileutils;

#[cfg(windows)]
pub mod windows;

#[cfg(any(unix, target_os = "wasi"))]
pub mod fcntl;
#[cfg(any(unix, windows, target_os = "wasi"))]
pub mod select;
#[cfg(unix)]
pub mod syslog;
#[cfg(all(unix, not(target_os = "redox"), not(target_os = "ios")))]
pub mod termios;

#[cfg(unix)]
pub mod posix;
#[cfg(all(unix, not(target_os = "redox"), not(target_os = "android")))]
pub mod shm;
#[cfg(unix)]
pub mod signal;
pub mod time;

#[cfg(windows)]
pub mod msvcrt;
#[cfg(windows)]
pub mod nt;
#[cfg(windows)]
pub mod winapi;
File renamed without changes.
Loading
Loading