Skip to content
Merged
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
12 changes: 12 additions & 0 deletions crates/host_env/src/ctypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,18 @@ pub const RTLD_LOCAL: i32 = 0;
pub const RTLD_GLOBAL: i32 = 0;
pub const SIZEOF_TIME_T: usize = core::mem::size_of::<TimeT>();

/// `_ctypes` call flags (`_flags_` on a function pointer).
pub const FUNCFLAG_STDCALL: u32 = 0x0;
pub const FUNCFLAG_CDECL: u32 = 0x1;
pub const FUNCFLAG_HRESULT: u32 = 0x2;
pub const FUNCFLAG_PYTHONAPI: u32 = 0x4;
pub const FUNCFLAG_USE_ERRNO: u32 = 0x8;
pub const FUNCFLAG_USE_LASTERROR: u32 = 0x10;
pub const TYPEFLAG_ISPOINTER: u32 = 0x100;
pub const TYPEFLAG_HASPOINTER: u32 = 0x200;
pub const DICTFLAG_FINAL: u32 = 0x1000;
pub const CTYPES_MAX_ARGCOUNT: usize = 1024;

#[cfg(all(unix, not(target_os = "wasi")))]
pub fn dlopen_mode(load_flags: Option<i32>) -> i32 {
load_flags.unwrap_or(libc::RTLD_NOW | libc::RTLD_LOCAL) | libc::RTLD_NOW
Expand Down
25 changes: 25 additions & 0 deletions crates/host_env/src/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,31 @@ pub const R_OK: u8 = 4;
pub const W_OK: u8 = 2;
pub const X_OK: u8 = 1;

#[cfg(any(unix, target_os = "wasi"))]
pub use libc::AT_FDCWD;
#[cfg(not(any(unix, target_os = "wasi")))]
pub const AT_FDCWD: i32 = -100;

/// BSD `chflags` bits the `libc` crate does not bind. Published by `_stat`
/// on every platform.
pub const UF_SETTABLE: u32 = 0x0000ffff;
pub const UF_NOUNLINK: u32 = 0x00000010;
pub const UF_TRACKED: u32 = 0x00000040;
pub const UF_DATAVAULT: u32 = 0x00000080;
pub const SF_NOUNLINK: u32 = 0x00100000;
pub const SF_SNAPSHOT: u32 = 0x00200000;
pub const SF_FIRMLINK: u32 = 0x00800000;
pub const SF_DATALESS: u32 = 0x40000000;
pub const SF_SETTABLE: u32 = if cfg!(target_os = "macos") {
0x3fff0000
} else {
0xffff0000
};
#[cfg(target_os = "macos")]
pub const SF_SUPPORTED: u32 = 0x009f0000;
#[cfg(target_os = "macos")]
pub const SF_SYNTHETIC: u32 = 0xc0000000;

#[cfg(not(any(unix, windows, target_os = "wasi")))]
pub fn rename(
from: impl AsRef<std::path::Path>,
Expand Down
10 changes: 10 additions & 0 deletions crates/host_env/src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ use crate::os::CheckLibcZero;
#[cfg(any(unix, windows))]
pub use libc::sighandler_t;

#[cfg(unix)]
pub use libc::{SIG_DFL, SIG_ERR, SIG_IGN};

#[cfg(not(unix))]
pub const SIG_DFL: libc::sighandler_t = 0;
#[cfg(not(unix))]
pub const SIG_IGN: libc::sighandler_t = 1;
#[cfg(not(unix))]
pub const SIG_ERR: libc::sighandler_t = -1 as _;

#[cfg(all(unix, not(target_os = "android")))]
pub use libc::{ITIMER_PROF, ITIMER_REAL, ITIMER_VIRTUAL};

Expand Down
27 changes: 5 additions & 22 deletions crates/vm/src/stdlib/_ctypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,28 +248,11 @@ pub(crate) mod _ctypes {
const SIZEOF_TIME_T: usize = rustpython_host_env::ctypes::SIZEOF_TIME_T;

#[pyattr]
const CTYPES_MAX_ARGCOUNT: usize = 1024;

#[pyattr]
const FUNCFLAG_STDCALL: u32 = 0x0;
#[pyattr]
const FUNCFLAG_CDECL: u32 = 0x1;
#[pyattr]
const FUNCFLAG_HRESULT: u32 = 0x2;
#[pyattr]
const FUNCFLAG_PYTHONAPI: u32 = 0x4;
#[pyattr]
const FUNCFLAG_USE_ERRNO: u32 = 0x8;
#[pyattr]
const FUNCFLAG_USE_LASTERROR: u32 = 0x10;

#[pyattr]
const TYPEFLAG_ISPOINTER: u32 = 0x100;
#[pyattr]
const TYPEFLAG_HASPOINTER: u32 = 0x200;

#[pyattr]
const DICTFLAG_FINAL: u32 = 0x1000;
use rustpython_host_env::ctypes::{
CTYPES_MAX_ARGCOUNT, DICTFLAG_FINAL, FUNCFLAG_CDECL, FUNCFLAG_HRESULT, FUNCFLAG_PYTHONAPI,
FUNCFLAG_STDCALL, FUNCFLAG_USE_ERRNO, FUNCFLAG_USE_LASTERROR, TYPEFLAG_HASPOINTER,
TYPEFLAG_ISPOINTER,
};

#[pyattr(name = "ArgumentError", once)]
fn argument_error(vm: &VirtualMachine) -> PyTypeRef {
Expand Down
14 changes: 7 additions & 7 deletions crates/vm/src/stdlib/_signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,28 @@ pub(crate) mod _signal {
}
}

#[cfg(unix)]
#[cfg(any(unix, windows))]
#[allow(unused_imports)]
pub use libc::SIG_ERR;
pub use host_signal::SIG_ERR;

#[cfg(unix)]
#[cfg(any(unix, windows))]
#[pyattr]
pub use libc::{SIG_DFL, SIG_IGN};
pub use host_signal::{SIG_DFL, SIG_IGN};

// pthread_sigmask 'how' constants
#[cfg(unix)]
#[pyattr]
use libc::{SIG_BLOCK, SIG_SETMASK, SIG_UNBLOCK};

#[cfg(not(unix))]
#[cfg(not(any(unix, windows)))]
#[pyattr]
pub const SIG_DFL: sighandler_t = 0;

#[cfg(not(unix))]
#[cfg(not(any(unix, windows)))]
#[pyattr]
pub const SIG_IGN: sighandler_t = 1;

#[cfg(not(unix))]
#[cfg(not(any(unix, windows)))]
#[allow(dead_code)]
pub const SIG_ERR: sighandler_t = -1 as _;

Expand Down
39 changes: 4 additions & 35 deletions crates/vm/src/stdlib/_stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,45 +319,14 @@ mod _stat {
);

#[pyattr]
pub const SF_SETTABLE: u32 = if cfg!(target_os = "macos") {
0x3fff0000
} else {
0xffff0000
pub use rustpython_host_env::os::{
SF_DATALESS, SF_FIRMLINK, SF_NOUNLINK, SF_SETTABLE, SF_SNAPSHOT, UF_DATAVAULT, UF_NOUNLINK,
UF_SETTABLE, UF_TRACKED,
};

#[pyattr]
pub const UF_SETTABLE: u32 = 0x0000ffff;

#[pyattr]
pub const UF_NOUNLINK: u32 = 0x00000010;

#[pyattr]
pub const UF_TRACKED: u32 = 0x00000040;

#[pyattr]
pub const UF_DATAVAULT: u32 = 0x00000080;

#[pyattr]
pub const SF_NOUNLINK: u32 = 0x00100000;

#[pyattr]
pub const SF_SNAPSHOT: u32 = 0x00200000;

#[pyattr]
pub const SF_FIRMLINK: u32 = 0x00800000;

#[pyattr]
pub const SF_DATALESS: u32 = 0x40000000;

// MacOS specific

#[cfg(target_os = "macos")]
#[pyattr]
pub const SF_SUPPORTED: u32 = 0x009f0000;

#[cfg(target_os = "macos")]
#[pyattr]
pub const SF_SYNTHETIC: u32 = 0xc0000000;
pub use rustpython_host_env::os::{SF_SUPPORTED, SF_SYNTHETIC};

// Stat result indices

Expand Down
9 changes: 1 addition & 8 deletions crates/vm/src/stdlib/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ pub struct TargetIsDirectory {
pub(crate) target_is_directory: bool,
}

cfg_select! {
any(unix, target_os = "wasi") => {
use libc::AT_FDCWD;
}
_ => {
const AT_FDCWD: i32 = -100;
}
}
use crate::host_env::os::AT_FDCWD;

const DEFAULT_DIR_FD: crt_fd::Borrowed<'static> = unsafe { crt_fd::Borrowed::borrow_raw(AT_FDCWD) };

Expand Down
Loading