X Tutup
Skip to content
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ jobs:
name: Ensure compilation on various targets
runs-on: ubuntu-latest
timeout-minutes: 30
env:
RUSTFLAGS: -D warnings
steps:
- uses: actions/checkout@v6.0.2
- uses: dtolnay/rust-toolchain@stable
Expand Down
3 changes: 2 additions & 1 deletion crates/stdlib/src/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ impl<D: Decompressor> DecompressState<D> {
self.eof
}

pub fn decompressor(&self) -> &D {
#[cfg_attr(target_os = "android", allow(dead_code))]
pub const fn decompressor(&self) -> &D {
&self.decompress
}

Expand Down
4 changes: 4 additions & 0 deletions crates/vm/src/stdlib/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,7 @@ pub(super) mod _os {
}
}

#[cfg_attr(target_env = "musl", allow(deprecated))]
#[derive(Debug, FromArgs)]
#[pystruct_sequence_data]
struct StatResultData {
Expand All @@ -1226,12 +1227,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,
Expand Down
17 changes: 10 additions & 7 deletions crates/vm/src/stdlib/posix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<libc::pid_t> {
use nix::sys::signal;

use crate::TryFromBorrowedObject;

let path = self
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -2629,7 +2627,10 @@ mod posix_sched {

#[cfg(not(target_env = "musl"))]
fn convert_sched_param(obj: &PyObjectRef, vm: &VirtualMachine) -> PyResult<libc::sched_param> {
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()));
}
Expand All @@ -2653,6 +2654,7 @@ mod posix_sched {
}
}

#[cfg(not(target_env = "musl"))]
#[derive(FromArgs)]
struct SchedSetschedulerArgs {
#[pyarg(positional)]
Expand Down Expand Up @@ -2692,6 +2694,7 @@ mod posix_sched {
))
}

#[cfg(not(target_env = "musl"))]
#[derive(FromArgs)]
struct SchedSetParamArgs {
#[pyarg(positional)]
Expand Down
12 changes: 12 additions & 0 deletions crates/vm/src/stdlib/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,21 +998,25 @@ mod decl {
}

#[cfg(any(unix, windows))]
#[cfg_attr(target_env = "musl", allow(deprecated))]
fn pyobj_to_time_t(value: Either<f64, i64>, vm: &VirtualMachine) -> PyResult<libc::time_t> {
match value {
Either::A(float) => {
if !float.is_finite() {
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")
})?;
Expand Down Expand Up @@ -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};

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions extra_tests/snippets/stdlib_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading
X Tutup