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
4 changes: 0 additions & 4 deletions Cargo.lock

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

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ rustpython-pylib = { workspace = true, optional = true }
rustpython-stdlib = { workspace = true, optional = true, features = ["compiler"] }
rustpython-vm = { workspace = true, features = ["compiler", "gc"] }

cfg-if = { workspace = true }
log = { workspace = true }
flame = { workspace = true, optional = true }

Expand Down Expand Up @@ -136,7 +135,7 @@ exclude = ["pymath"]
version = "0.5.0"
authors = ["RustPython Team"]
edition = "2024"
rust-version = "1.94.0"
rust-version = "1.95.0"
repository = "https://github.com/RustPython/RustPython"
license = "MIT"

Expand Down Expand Up @@ -177,7 +176,6 @@ ascii = "1.1"
bitflags = "2.11.0"
bitflagset = "0.0.3"
bstr = "1"
cfg-if = "1.0"
chrono = { version = "0.4.44", default-features = false, features = ["clock", "oldtime", "std"] }
constant_time_eq = "0.4"
criterion = { version = "0.8", features = ["html_reports"] }
Expand Down
1 change: 0 additions & 1 deletion crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ rustpython-wtf8 = { workspace = true }

ascii = { workspace = true }
bitflags = { workspace = true }
cfg-if = { workspace = true }
getrandom = { workspace = true }
itertools = { workspace = true }
libc = { workspace = true }
Expand Down
15 changes: 8 additions & 7 deletions crates/common/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use lock_api::{
RwLockReadGuard, RwLockUpgradableReadGuard, RwLockWriteGuard,
};

cfg_if::cfg_if! {
if #[cfg(feature = "threading")] {
cfg_select! {
feature = "threading" => {
pub use parking_lot::{RawMutex, RawRwLock, RawThreadId};

pub use std::sync::OnceLock as OnceCell;
pub use core::cell::LazyCell;
} else {
}
_ => {
mod cell_lock;
pub use cell_lock::{RawCellMutex as RawMutex, RawCellRwLock as RawRwLock, SingleThreadId as RawThreadId};

Expand All @@ -23,10 +23,11 @@ cfg_if::cfg_if! {
// LazyLock: uses std::sync::LazyLock when std is available (even without
// threading, because Rust test runner uses parallel threads).
// Without std, uses a LazyCell wrapper (truly single-threaded only).
cfg_if::cfg_if! {
if #[cfg(any(feature = "threading", feature = "std"))] {
cfg_select! {
any(feature = "threading", feature = "std") => {
pub use std::sync::LazyLock;
} else {
}
_ => {
pub struct LazyLock<T, F = fn() -> T>(core::cell::LazyCell<T, F>);
// SAFETY: This branch is only active when both "std" and "threading"
// features are absent — i.e., truly single-threaded no_std environments
Expand Down
1 change: 0 additions & 1 deletion crates/stdlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ ruff_source_file = { workspace = true }

ahash = { workspace = true }
ascii = { workspace = true }
cfg-if = { workspace = true }
crossbeam-utils = { workspace = true }
flame = { workspace = true, optional = true }
hex = { workspace = true }
Expand Down
5 changes: 3 additions & 2 deletions crates/stdlib/src/_sqlite3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2819,14 +2819,15 @@ mod _sqlite3 {
db: *mut sqlite3,
}

cfg_if::cfg_if! {
if #[cfg(feature = "threading")] {
cfg_select! {
feature = "threading" => {
unsafe impl Send for SqliteStatement {}
// unsafe impl Sync for SqliteStatement {}
unsafe impl Send for Sqlite {}
// unsafe impl Sync for Sqlite {}
unsafe impl Send for SqliteBlob {}
}
_ => {}
}

impl From<SqliteStatementRaw> for SqliteRaw {
Expand Down
34 changes: 17 additions & 17 deletions crates/stdlib/src/openssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ mod cert;
mod ssl_error;

// Conditional compilation for OpenSSL version-specific error codes
cfg_if::cfg_if! {
if #[cfg(ossl310)] {
// OpenSSL 3.1.0+
cfg_select! {
// OpenSSL 3.1.0+
ossl310 => {
mod ssl_data_31;
use ssl_data_31 as ssl_data;
} else if #[cfg(ossl300)] {
// OpenSSL 3.0.0+
}
// OpenSSL 3.0.0+
ossl300 => {
mod ssl_data_300;
use ssl_data_300 as ssl_data;
} else {
// OpenSSL 1.1.1+ (fallback)
}
// OpenSSL 1.1.1+ (fallback)
_ => {
mod ssl_data_111;
use ssl_data_111 as ssl_data;
}
Expand All @@ -30,13 +32,10 @@ use rustpython_common::lock::LazyLock;

// define our own copy of ProbeResult so we can handle the vendor case
// easily, without having to have a bunch of cfgs
cfg_if::cfg_if! {
if #[cfg(openssl_vendored)] {
static PROBE: LazyLock<ProbeResult> = LazyLock::new(openssl_probe::probe);
} else {
static PROBE: LazyLock<ProbeResult> = LazyLock::new(|| ProbeResult { cert_file: None, cert_dir: vec![] });
}
}
static PROBE: LazyLock<ProbeResult> = cfg_select! {
openssl_vendored => LazyLock::new(openssl_probe::probe)
_ => LazyLock::new(|| ProbeResult { cert_file: None, cert_dir: vec![] })
};

fn probe() -> &'static ProbeResult {
&PROBE
Expand Down Expand Up @@ -1349,13 +1348,14 @@ mod _ssl {

#[pymethod]
fn set_default_verify_paths(&self, vm: &VirtualMachine) -> PyResult<()> {
cfg_if::cfg_if! {
if #[cfg(openssl_vendored)] {
cfg_select! {
openssl_vendored => {
let (cert_file, cert_dir) = get_cert_file_dir();
self.builder()
.load_verify_locations(Some(cert_file), Some(cert_dir))
.map_err(|e| convert_openssl_error(vm, e))
} else {
}
_ => {
self.builder()
.set_default_verify_paths()
.map_err(|e| convert_openssl_error(vm, e))
Expand Down
15 changes: 8 additions & 7 deletions crates/stdlib/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ mod resource {
use core::mem;
use std::io;

cfg_if::cfg_if! {
if #[cfg(target_os = "android")] {
#[expect(deprecated)]
const RLIM_NLIMITS: i32 = libc::RLIM_NLIMITS;
} else {
#[cfg_attr(target_os = "android", expect(deprecated))]
const RLIM_NLIMITS: i32 = cfg_select! {
target_os = "android" => {
libc::RLIM_NLIMITS
}
_ => {
// This constant isn't abi-stable across os versions, so we just
// pick a high number so we don't get false positive ValueErrors and just bubble up the
// EINVAL that get/setrlimit return on an invalid resource
const RLIM_NLIMITS: i32 = 256;
256
}
}
};

// TODO: RLIMIT_OFILE,
#[pyattr]
Expand Down
22 changes: 10 additions & 12 deletions crates/stdlib/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1568,20 +1568,23 @@ mod _socket {
if socket_kind == -1 {
socket_kind = sock.r#type().map_err(|e| e.into_pyexception(vm))?.into();
}
cfg_if::cfg_if! {
if #[cfg(any(

cfg_select! {
any(
target_os = "android",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "linux",
))] {
) => {
if proto == -1 {
proto = sock.protocol()?.map_or(0, Into::into);
}
} else {
}
_ => {
proto = 0;
}
}

return Ok(zelf.init_inner(family, socket_kind, proto, sock)?);
}

Expand Down Expand Up @@ -3259,14 +3262,9 @@ mod _socket {
}

fn sock_from_raw(fileno: RawSocket, vm: &VirtualMachine) -> PyResult<Socket> {
let invalid = {
cfg_if::cfg_if! {
if #[cfg(windows)] {
fileno == INVALID_SOCKET
} else {
fileno < 0
}
}
let invalid = cfg_select! {
windows => fileno == INVALID_SOCKET,
_ => fileno < 0
};
if invalid {
return Err(vm.new_value_error("negative file descriptor"));
Expand Down
1 change: 0 additions & 1 deletion crates/vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ ascii = { workspace = true }
ahash = { workspace = true }
bitflags = { workspace = true }
bstr = { workspace = true }
cfg-if = { workspace = true }
crossbeam-utils = { workspace = true }
chrono = { workspace = true }
constant_time_eq = { workspace = true }
Expand Down
5 changes: 3 additions & 2 deletions crates/vm/src/builtins/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,12 @@ impl<T> AsRef<T> for PointerSlot<T> {

pub type PyTypeRef = PyRef<PyType>;

cfg_if::cfg_if! {
if #[cfg(feature = "threading")] {
cfg_select! {
feature = "threading" => {
unsafe impl Send for PyType {}
unsafe impl Sync for PyType {}
}
_ => {}
}

/// For attributes we do not use a dict, but an IndexMap, which is an Hash Table
Expand Down
19 changes: 8 additions & 11 deletions crates/vm/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,15 @@ macro_rules! named_function {

// can't use PyThreadingConstraint for stuff like this since it's not an auto trait, and
// therefore we can't add it ad-hoc to a trait object
cfg_if::cfg_if! {
if #[cfg(feature = "threading")] {
macro_rules! py_dyn_fn {
(dyn Fn($($arg:ty),*$(,)*) -> $ret:ty) => {
macro_rules! py_dyn_fn {
(dyn Fn($($arg:ty),*$(,)*) -> $ret:ty) => {
cfg_select! {
feature = "threading" => {
dyn Fn($($arg),*) -> $ret + Send + Sync + 'static
};
}
} else {
macro_rules! py_dyn_fn {
(dyn Fn($($arg:ty),*$(,)*) -> $ret:ty) => {
}
_ => {
dyn Fn($($arg),*) -> $ret + 'static
};
}
}
}
};
}
20 changes: 12 additions & 8 deletions crates/vm/src/object/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,11 +817,12 @@ pub struct PyWeak {
pub(crate) hash: PyAtomic<crate::common::hash::PyHash>,
}

cfg_if::cfg_if! {
if #[cfg(feature = "threading")] {
cfg_select! {
feature = "threading" => {
unsafe impl Send for PyWeak {}
unsafe impl Sync for PyWeak {}
}
_ => {}
}

impl PyWeak {
Expand Down Expand Up @@ -1193,11 +1194,12 @@ impl Clone for PyObjectRef {
}
}

cfg_if::cfg_if! {
if #[cfg(feature = "threading")] {
cfg_select! {
feature = "threading" => {
unsafe impl Send for PyObjectRef {}
unsafe impl Sync for PyObjectRef {}
}
_ => {}
}

#[repr(transparent)]
Expand Down Expand Up @@ -2014,11 +2016,12 @@ impl fmt::Debug for PyStackRef {
}
}

cfg_if::cfg_if! {
if #[cfg(feature = "threading")] {
cfg_select! {
feature = "threading" => {
unsafe impl Send for PyStackRef {}
unsafe impl Sync for PyStackRef {}
}
_ => {}
}

// Ensure Option<PyStackRef> uses niche optimization and matches Option<PyObjectRef> in size
Expand Down Expand Up @@ -2129,11 +2132,12 @@ pub struct PyRef<T> {
ptr: NonNull<Py<T>>,
}

cfg_if::cfg_if! {
if #[cfg(feature = "threading")] {
cfg_select! {
feature = "threading" => {
unsafe impl<T> Send for PyRef<T> {}
unsafe impl<T> Sync for PyRef<T> {}
}
_ => {}
}

impl<T: fmt::Debug> fmt::Debug for PyRef<T> {
Expand Down
5 changes: 3 additions & 2 deletions crates/vm/src/object/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ impl<T> Drop for PyAtomicRef<T> {
}
}

cfg_if::cfg_if! {
if #[cfg(feature = "threading")] {
cfg_select! {
feature = "threading" => {
unsafe impl<T: Send + PyPayload> Send for PyAtomicRef<T> {}
unsafe impl<T: Sync + PyPayload> Sync for PyAtomicRef<T> {}
unsafe impl<T: Send + PyPayload> Send for PyAtomicRef<Option<T>> {}
Expand All @@ -270,6 +270,7 @@ cfg_if::cfg_if! {
unsafe impl Send for PyAtomicRef<Option<PyObject>> {}
unsafe impl Sync for PyAtomicRef<Option<PyObject>> {}
}
_ => {}
}

impl<T: fmt::Debug> fmt::Debug for PyAtomicRef<T> {
Expand Down
Loading
Loading