diff --git a/crates/stdlib/src/compression.rs b/crates/stdlib/src/compression.rs index 8cc48b74782..ae47ebbff70 100644 --- a/crates/stdlib/src/compression.rs +++ b/crates/stdlib/src/compression.rs @@ -296,7 +296,8 @@ impl DecompressState { self.eof } - pub fn decompressor(&self) -> &D { + #[cfg_attr(target_os = "android", allow(dead_code))] + pub const fn decompressor(&self) -> &D { &self.decompress } diff --git a/crates/vm/src/stdlib/os.rs b/crates/vm/src/stdlib/os.rs index fd03be9175e..0736ca18032 100644 --- a/crates/vm/src/stdlib/os.rs +++ b/crates/vm/src/stdlib/os.rs @@ -1226,12 +1226,15 @@ pub(super) mod _os { pub st_gid: PyIntRef, pub st_size: PyIntRef, // Indices 7-9: integer seconds + #[cfg_attr(target_env = "musl", allow(deprecated))] #[pyarg(positional, default)] #[pystruct_sequence(unnamed)] pub st_atime_int: libc::time_t, + #[cfg_attr(target_env = "musl", allow(deprecated))] #[pyarg(positional, default)] #[pystruct_sequence(unnamed)] pub st_mtime_int: libc::time_t, + #[cfg_attr(target_env = "musl", allow(deprecated))] #[pyarg(positional, default)] #[pystruct_sequence(unnamed)] pub st_ctime_int: libc::time_t, diff --git a/crates/vm/src/stdlib/posix.rs b/crates/vm/src/stdlib/posix.rs index 961f0c6fe0d..69b727d09dd 100644 --- a/crates/vm/src/stdlib/posix.rs +++ b/crates/vm/src/stdlib/posix.rs @@ -51,7 +51,6 @@ pub mod module { use nix::{ errno::Errno, fcntl, - sys::signal, unistd::{self, Gid, Pid, Uid}, }; use rustpython_common::os::ffi::OsStringExt; @@ -1530,6 +1529,8 @@ pub mod module { #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))] impl PosixSpawnArgs { fn spawn(self, spawnp: bool, vm: &VirtualMachine) -> PyResult { + use nix::sys::signal; + use crate::TryFromBorrowedObject; let path = self @@ -2566,11 +2567,8 @@ pub mod module { #[pymodule(sub)] mod posix_sched { use crate::{ - AsObject, Py, PyObjectRef, PyResult, VirtualMachine, - builtins::{PyInt, PyTupleRef}, - convert::ToPyObject, - function::FuncArgs, - types::PyStructSequence, + AsObject, Py, PyObjectRef, PyResult, VirtualMachine, builtins::PyTupleRef, + convert::ToPyObject, function::FuncArgs, types::PyStructSequence, }; #[derive(FromArgs)] @@ -2629,7 +2627,10 @@ mod posix_sched { #[cfg(not(target_env = "musl"))] fn convert_sched_param(obj: &PyObjectRef, vm: &VirtualMachine) -> PyResult { - use crate::{builtins::PyTuple, class::StaticType}; + use crate::{ + builtins::{PyInt, PyTuple}, + class::StaticType, + }; if !obj.fast_isinstance(PySchedParam::static_type()) { return Err(vm.new_type_error("must have a sched_param object".to_owned())); } @@ -2653,6 +2654,7 @@ mod posix_sched { } } + #[cfg(not(target_env = "musl"))] #[derive(FromArgs)] struct SchedSetschedulerArgs { #[pyarg(positional)] @@ -2692,6 +2694,7 @@ mod posix_sched { )) } + #[cfg(not(target_env = "musl"))] #[derive(FromArgs)] struct SchedSetParamArgs { #[pyarg(positional)] diff --git a/crates/vm/src/stdlib/time.rs b/crates/vm/src/stdlib/time.rs index ee19fce7dac..3477648c4a7 100644 --- a/crates/vm/src/stdlib/time.rs +++ b/crates/vm/src/stdlib/time.rs @@ -998,6 +998,7 @@ mod decl { } #[cfg(any(unix, windows))] + #[cfg_attr(target_env = "musl", allow(deprecated))] fn pyobj_to_time_t(value: Either, vm: &VirtualMachine) -> PyResult { match value { Either::A(float) => { @@ -1005,14 +1006,17 @@ mod decl { return Err(vm.new_value_error("Invalid value for timestamp")); } let secs = float.floor(); + #[cfg_attr(target_env = "musl", allow(deprecated))] if secs < libc::time_t::MIN as f64 || secs > libc::time_t::MAX as f64 { return Err(vm.new_overflow_error("timestamp out of range for platform time_t")); } + #[cfg_attr(target_env = "musl", allow(deprecated))] Ok(secs as libc::time_t) } Either::B(int) => { // try_into is needed on 32-bit platforms where time_t != i64 #[allow(clippy::useless_conversion)] + #[cfg_attr(target_env = "musl", allow(deprecated))] let ts: libc::time_t = int.try_into().map_err(|_| { vm.new_overflow_error("timestamp out of range for platform time_t") })?; @@ -1052,6 +1056,7 @@ mod platform { convert::IntoPyException, }; use core::time::Duration; + #[cfg_attr(target_env = "musl", allow(deprecated))] use libc::time_t; use nix::{sys::time::TimeSpec, time::ClockId}; @@ -1116,10 +1121,12 @@ mod platform { } } + #[cfg_attr(target_env = "musl", allow(deprecated))] pub(super) fn current_time_t() -> time_t { unsafe { libc::time(core::ptr::null_mut()) } } + #[cfg_attr(target_env = "musl", allow(deprecated))] pub(super) fn gmtime_from_timestamp( when: time_t, vm: &VirtualMachine, @@ -1132,6 +1139,7 @@ mod platform { Ok(struct_time_from_tm(vm, unsafe { out.assume_init() })) } + #[cfg_attr(target_env = "musl", allow(deprecated))] pub(super) fn localtime_from_timestamp( when: time_t, vm: &VirtualMachine, @@ -1200,6 +1208,7 @@ mod platform { #[cfg(not(target_os = "redox"))] #[cfg(any(not(target_vendor = "apple"), target_os = "macos"))] + #[cfg_attr(target_env = "musl", allow(deprecated))] #[pyfunction] fn clock_settime_ns(clk_id: ClockId, time: libc::time_t, vm: &VirtualMachine) -> PyResult<()> { let ts = Duration::from_nanos(time as _).into(); @@ -1369,10 +1378,12 @@ mod platform { } } + #[cfg_attr(target_env = "musl", allow(deprecated))] pub(super) fn current_time_t() -> libc::time_t { unsafe { libc::time(core::ptr::null_mut()) } } + #[cfg_attr(target_env = "musl", allow(deprecated))] pub(super) fn gmtime_from_timestamp( when: libc::time_t, vm: &VirtualMachine, @@ -1390,6 +1401,7 @@ mod platform { )) } + #[cfg_attr(target_env = "musl", allow(deprecated))] pub(super) fn localtime_from_timestamp( when: libc::time_t, vm: &VirtualMachine, diff --git a/extra_tests/snippets/stdlib_io.py b/extra_tests/snippets/stdlib_io.py index f1e682b5d24..25985e08968 100644 --- a/extra_tests/snippets/stdlib_io.py +++ b/extra_tests/snippets/stdlib_io.py @@ -41,6 +41,7 @@ nres = fio.read(2) assert len(nres) == 2 + # Test that IOBase.isatty() raises ValueError when called on a closed file. # Minimal subclass that inherits IOBase.isatty() without overriding it. class MinimalRaw(RawIOBase):