8000 Update deps (#5417) · RustPython/RustPython@37dc28a · GitHub
[go: up one dir, main page]

Skip to content

Commit 37dc28a

Browse files
authored
Update deps (#5417)
* Upgrade nix * Update deps * Upgrade pyo3, winreg * Fix errors from upgrading
1 parent 7623668 commit 37dc28a

File tree

17 files changed

+575
-705
lines changed

17 files changed

+575
-705
lines changed

Cargo.lock

Lines changed: 491 additions & 639 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ rustyline = { workspace = true }
4949

5050
[dev-dependencies]
5151
criterion = { version = "0.3.5", features = ["html_reports"] }
52-
pyo3 = { version = "0.20.2", features = ["auto-initialize"] }
52+
pyo3 = { version = "0.22", features = ["auto-initialize"] }
5353

5454
[[bench]]
5555
name = "execution"
@@ -105,7 +105,7 @@ members = [
105105
version = "0.4.0"
106106
authors = ["RustPython Team"]
107107
edition = "2021"
108-
rust-version = "1.78.0"
108+
rust-version = "1.80.0"
109109
repository = "https://github.com/RustPython/RustPython"
110110
license = "MIT"
111111

@@ -143,7 +143,7 @@ ahash = "0.8.11"
143143
ascii = "1.0"
144144
atty = "0.2.14"
145145
bitflags = "2.4.1"
146-
bstr = "0.2.17"
146+
bstr = "1"
147147
cfg-if = "1.0"
148148
chrono = "0.4.37"
149149
crossbeam-utils = "0.8.19"
@@ -158,7 +158,7 @@ is-macro = "0.3.0"
158158
junction = "1.0.0"
159159
libc = "0.2.153"
160160
log = "0.4.16"
161-
nix = { version = "0.27", features = ["fs", "user", "process", "term", "time", "signal", "ioctl", "socket", "sched", "zerocopy", "dir", "hostname", "net", "poll"] }
161+
nix = { version = "0.29", features = ["fs", "user", "process", "term", "time", "signal", "ioctl", "socket", "sched", "zerocopy", "dir", "hostname", "net", "poll"] }
162162
malachite-bigint = "0.2.0"
163163
malachite-q = "0.4.4"
164164
malachite-base = "0.4.4"
@@ -176,6 +176,8 @@ rustyline = "14.0.0"
176176
serde = { version = "1.0.133", default-features = false }
177177
schannel = "0.1.22"
178178
static_assertions = "1.1"
179+
strum = "0.26"
180+
strum_macros = "0.26"
179181
syn = "1.0.109"
180182
thiserror = "1.0"
181183
thread_local = "1.1.4"

benches/execution.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use std::path::Path;
1313
fn bench_cpython_code(b: &mut Bencher, source: &str) {
1414
pyo3::Python::with_gil(|py| {
1515
b.iter(|| {
16-
let module =
17-
pyo3::types::PyModule::from_code(py, source, "", "").expect("Error running source");
16+
let module = pyo3::types::PyModule::from_code_bound(py, source, "", "")
17+
.expect("Error running source");
1818
black_box(module);
1919
})
2020
})
@@ -53,9 +53,10 @@ pub fn benchmark_file_parsing(group: &mut BenchmarkGroup<WallTime>, name: &str,
5353
b.iter(|| ast::Suite::parse(contents, name).unwrap())
5454
});
5555
group.bench_function(BenchmarkId::new("cpython", name), |b| {
56+
use pyo3::types::PyAnyMethods;
5657
pyo3::Python::with_gil(|py| {
57-
let builtins =
58-
pyo3::types::PyModule::import(py, "builtins").expect("Failed to import builtins");
58+
let builtins = pyo3::types::PyModule::import_bound(py, "builtins")
59+
.expect("Failed to import builtins");
5960
let compile = builtins.getattr("compile").expect("no compile in builtins");
6061
b.iter(|| {
6162
let x = compile

benches/microbenchmarks.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use criterion::{
22
criterion_group, criterion_main, measurement::WallTime, BatchSize, BenchmarkGroup, BenchmarkId,
33
Criterion, Throughput,
44
};
5+
use pyo3::types::PyAnyMethods;
56
use rustpython_compiler::Mode;
67
use rustpython_vm::{AsObject, Interpreter, PyResult, Settings};
78
use std::{
@@ -44,25 +45,28 @@ fn bench_cpython_code(group: &mut BenchmarkGroup<WallTime>, bench: &MicroBenchma
4445

4546
// Grab the exec function in advance so we don't have lookups in the hot code
4647
let builtins =
47-
pyo3::types::PyModule::import(py, "builtins").expect("Failed to import builtins");
48+
pyo3::types::PyModule::import_bound(py, "builtins").expect("Failed to import builtins");
4849
let exec = builtins.getattr("exec").expect("no exec in builtins");
4950

50-
let bench_func = |(globals, locals): &mut (&pyo3::types::PyDict, &pyo3::types::PyDict)| {
51-
let res = exec.call((code, &*globals, &*locals), None);
51+
let bench_func = |(globals, locals): &mut (
52+
pyo3::Bound<pyo3::types::PyDict>,
53+
pyo3::Bound<pyo3::types::PyDict>,
54+
)| {
55+
let res = exec.call((&code, &*globals, &*locals), None);
5256
if let Err(e) = res {
5357
e.print(py);
5458
panic!("Error running microbenchmark")
5559
}
5660
};
5761

5862
let bench_setup = |iterations| {
59-
let globals = pyo3::types::PyDict::new(py);
60-
let locals = pyo3::types::PyDict::new(py);
63+
let globals = pyo3::types::PyDict::new_bound(py);
64+
let locals = pyo3::types::PyDict::new_bound(py);
6165
if let Some(idx) = iterations {
6266
globals.set_item("ITERATIONS", idx).unwrap();
6367
}
6468

65-
let res = exec.call((setup_code, &globals, &locals), None);
69+
let res = exec.call((&setup_code, &globals, &locals), None);
6670
if let Err(e) = res {
6771
e.print(py);
6872
panic!("Error running microbenchmark setup code")
@@ -93,9 +97,9 @@ fn cpy_compile_code<'a>(
9397
py: pyo3::Python<'a>,
9498
code: &str,
9599
name: &str,
96-
) -> pyo3::PyResult<&'a pyo3::types::PyCode> {
100+
) -> pyo3::PyResult<pyo3::Bound<'a, pyo3::types::PyCode>> {
97101
let builtins =
98-
pyo3::types::PyModule::import(py, "builtins").expect("Failed to import builtins");
102+
pyo3::types::PyModule::import_bound(py, "builtins").expect("Failed to import builtins");
99103
let compile = builtins.getattr("compile").expect("no compile in builtins");
100104
compile.call1((code, name, "exec"))?.extract()
101105
}

common/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ rustpython-format = { workspace = true }
1616

1717
ascii = { workspace = true }
1818
bitflags = { workspace = true }
19-
bstr = { workspace = true }
2019
cfg-if = { workspace = true }
2120
itertools = { workspace = true }
2221
libc = { workspace = true }

common/src/int.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use bstr::ByteSlice;
21
use malachite_base::{num::conversion::traits::RoundingInto, rounding_modes::RoundingMode};
32
use malachite_bigint::{BigInt, BigUint, Sign};
43
use malachite_q::Rational;
@@ -32,7 +31,7 @@ pub fn float_to_ratio(value: f64) -> Option<(BigInt, BigInt)> {
3231

3332
pub fn bytes_to_int(lit: &[u8], mut base: u32) -> Option<BigInt> {
3433
// split sign
35-
let mut lit = lit.trim();
34+
let mut lit = lit.trim_ascii();
3635
let sign = match lit.first()? {
3736
b'+' => Some(Sign::Plus),
3837
b'-' => Some(Sign::Minus),

common/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! A crate to hold types and functions common to all rustpython components.
22
3+
#![cfg_attr(target_os = "redox", feature(byte_slice_trim_ascii))]
4+
35
#[macro_use]
46
mod macros;
57
pub use macros::*;

stdlib/src/socket.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,15 +1842,16 @@ mod _socket {
18421842
#[cfg(unix)]
18431843
{
18441844
use nix::poll::*;
1845+
use std::os::fd::AsFd;
18451846
let events = match kind {
18461847
SelectKind::Read => PollFlags::POLLIN,
18471848
SelectKind::Write => PollFlags::POLLOUT,
18481849
SelectKind::Connect => PollFlags::POLLOUT | PollFlags::POLLERR,
18491850
};
1850-
let mut pollfd = [PollFd::new(sock, events)];
1851+
let mut pollfd = [PollFd::new(sock.as_fd(), events)];
18511852
let timeout = match interval {
1852-
Some(d) => d.as_millis() as _,
1853-
None => -1,
1853+
Some(d) => d.try_into().unwrap_or(PollTimeout::MAX),
1854+
None => PollTimeout::NONE,
18541855
};
18551856
let ret = poll(&mut pollfd, timeout)?;
18561857
Ok(ret == 0)

vm/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ memchr = { workspace = true }
7474

7575
caseless = "0.2.1"
7676
flamer = { version = "0.4", optional = true }
77-
half = "1.8.2"
77+
half = "2"
7878
memoffset = "0.9.1"
7979
optional = "0.5.0"
8080
result-like = "0.4.6"
@@ -94,12 +94,12 @@ unic-ucd-ident = "0.9.0"
9494
rustix = { workspace = true }
9595
exitcode = "1.1.2"
9696
uname = "0.1.1"
97-
strum = "0.24.0"
98-
strum_macros = "0.24.0"
97+
strum = { workspace = true }
98+
strum_macros = { workspace = true }
9999

100100
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
101101
rustyline = { workspace = true }
102-
which = "4.2.5"
102+
which = "6"
103103

104104
[target.'cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))'.dependencies]
105105
num_cpus = "1.13.1"
@@ -108,7 +108,7 @@ num_cpus = "1.13.1"
108108
junction = { workspace = true }
109109
schannel = { workspace = true }
110110
widestring = { workspace = true }
111-
winreg = "0.10.1"
111+
winreg = "0.52"
112112

113113
[target.'cfg(windows)'.dependencies.windows]
114114
version = "0.52.0"
@@ -152,4 +152,4 @@ itertools = { workspace = true }
152152
rustc_version = "0.4.0"
153153

154154
[lints]
155-
workspace = true
155+
workspace = true

vm/src/buffer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,8 @@ make_pack_float!(f64);
540540
impl Packable for f16 {
541541
fn pack<E: ByteOrder>(vm: &VirtualMachine, arg: PyObjectRef, data: &mut [u8]) -> PyResult<()> {
542542
let f_64 = *ArgIntoFloat::try_from_object(vm, arg)?;
543-
let f_16 = f16::from_f64(f_64);
543+
// "from_f64 should be preferred in any non-`const` context" except it gives the wrong result :/
544+
let f_16 = f16::from_f64_const(f_64);
544545
if f_16.is_infinite() != f_64.is_infinite() {
545546
return Err(vm.new_overflow_error("float too large to pack with e format".to_owned()));
546547
}

vm/src/builtins/complex.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,27 @@ fn inner_pow(v1: Complex64, v2: Complex64, vm: &VirtualMachine) -> PyResult<Comp
131131
};
132132
}
133133

134-
let ans = v1.powc(v2);
134+
let ans = powc(v1, v2);
135135
if ans.is_infinite() && !(v1.is_infinite() || v2.is_infinite()) {
136136
Err(vm.new_overflow_error("complex exponentiation overflow".to_owned()))
137137
} else {
138138
Ok(ans)
139139
}
140140
}
141141

142+
// num-complex changed their powc() implementation in 0.4.4, making it incompatible
143+
// with what the regression tests expect. this is that old formula.
144+
fn powc(a: Complex64, exp: Complex64) -> Complex64 {
145+
let (r, theta) = a.to_polar();
146+
if r.is_zero() {
147+
return Complex64::new(r, r);
148+
}
149+
Complex64::from_polar(
150+
r.powf(exp.re) * (-exp.im * theta).exp(),
151+
exp.re * theta + exp.im * r.ln(),
152+
)
153+
}
154+
142155
impl Constructor for PyComplex {
143156
type Args = ComplexArgs;
144157

vm/src/builtins/int.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ fn try_int_radix(obj: &PyObject, base: u32, vm: &VirtualMachine) -> PyResult<Big
855855

856856
let opt = match_class!(match obj.to_owned() {
857857
string @ PyStr => {
858-
let s = string.as_str();
858+
let s = string.as_str().trim();
859859
bytes_to_int(s.as_bytes(), base)
860860
}
861861
bytes @ PyBytes => {

vm/src/protocol/number.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl PyObject {
7777
))
7878
})
7979
} else if let Some(s) = self.payload::<PyStr>() {
80-
try_convert(self, s.as_str().as_bytes(), vm)
80+
try_convert(self, s.as_str().trim().as_bytes(), vm)
8181
} else if let Some(bytes) = self.payload::<PyBytes>() {
8282
try_convert(self, bytes, vm)
8383
} else if let Some(bytearray) = self.payload::<PyByteArray>() {

vm/src/stdlib/posix.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,9 @@ pub mod module {
406406
};
407407

408408
let flag = if follow_symlinks.0 {
409-
nix::unistd::FchownatFlags::FollowSymlink
409+
nix::fcntl::AtFlags::empty()
410410
} else {
411-
nix::unistd::FchownatFlags::NoFollowSymlink
411+
nix::fcntl::AtFlags::AT_SYMLINK_NOFOLLOW
412412
};
413413

414414
let dir_fd = dir_fd.get_opt();
@@ -631,10 +631,10 @@ pub mod module {
631631
#[cfg(not(target_os = "redox"))]
632632
#[pyfunction]
633633
fn nice(increment: i32, vm: &VirtualMachine) -> PyResult<i32> {
634-
use nix::errno::{errno, Errno};
634+
use nix::errno::Errno;
635635
Errno::clear();
636636
let res = unsafe { libc::nice(increment) };
637-
if res == -1 && errno() != 0 {
637+
if res == -1 && Errno::last_raw() != 0 {
638638
Err(errno_err(vm))
639639
} else {
640640
Ok(res)
@@ -877,16 +877,11 @@ pub mod module {
877877
}
878878

879879
#[pyfunction]
880-
fn pipe(vm: &VirtualMachine) -> PyResult<(RawFd, RawFd)> {
881-
use nix::unistd::close;
880+
fn pipe(vm: &VirtualMachine) -> PyResult<(OwnedFd, OwnedFd)> {
882881
use nix::unistd::pipe;
883882
let (rfd, wfd) = pipe().map_err(|err| err.into_pyexception(vm))?;
884-
set_inheritable(rfd, false, vm)
885-
.and_then(|_| set_inheritable(wfd, false, vm))
886-
.inspect_err(|_| {
887-
let _ = close(rfd);
888-
let _ = close(wfd);
889-
})?;
883+
set_inheritable(rfd.as_raw_fd(), false, vm)?;
884+
set_inheritable(wfd.as_raw_fd(), false, vm)?;
890885
Ok((rfd, wfd))
891886
}
892887

@@ -901,7 +896,7 @@ pub mod module {
901896
target_os = "openbsd"
902897
))]
903898
#[pyfunction]
904-
fn pipe2(flags: libc::c_int, vm: &VirtualMachine) -> PyResult<(RawFd, RawFd)> {
899+
fn pipe2(flags: libc::c_int, vm: &VirtualMachine) -> PyResult<(OwnedFd, OwnedFd)> {
905900
let oflags = fcntl::OFlag::from_bits_truncate(flags);
906901
nix::unistd::pipe2(oflags).map_err(|err| err.into_pyexception(vm))
907902
}
@@ -1227,7 +1222,7 @@ pub mod module {
1227122 10000 2
}
12281223

12291224
#[pyfunction]
1230-
fn ttyname(fd: i32, vm: &VirtualMachine) -> PyResult {
1225+
fn ttyname(fd: BorrowedFd<'_>, vm: &VirtualMachine) -> PyResult {
12311226
let name = unistd::ttyname(fd).map_err(|e| e.into_pyexception(vm))?;
12321227
let name = name.into_os_string().into_string().unwrap();
12331228
Ok(vm.ctx.new_str(name).into())
@@ -1756,10 +1751,10 @@ pub mod module {
17561751
who: PriorityWhoType,
17571752
vm: &VirtualMachine,
17581753
) -> PyResult {
1759-
use nix::errno::{errno, Errno};
1754+
use nix::errno::Errno;
17601755
Errno::clear();
17611756
let retval = unsafe { libc::getpriority(which, who) };
1762-
if errno() != 0 {
1757+
if Errno::last_raw() != 0 {
17631758
Err(errno_err(vm))
17641759
} else {
17651760
Ok(vm.ctx.new_int(retval).into())
@@ -1973,10 +1968,10 @@ pub mod module {
19731968
PathconfName(name): PathconfName,
19741969
vm: &VirtualMachine,
19751970
) -> PyResult<Option<libc::c_long>> {
1976-
use nix::errno::{self, Errno};
1971+
use nix::errno::Errno;
19771972

19781973
Errno::clear();
1979-
debug_assert_eq!(errno::errno(), 0);
1974+
debug_assert_eq!(Errno::last_raw(), 0);
19801975
let raw = match &path {
19811976
OsPathOrFd::Path(path) => {
19821977
let path = path.clone().into_cstring(vm)?;
@@ -1986,7 +1981,7 @@ pub mod module {
19861981
};
19871982

19881983
if raw == -1 {
1989-
if errno::errno() == 0 {
1984+
if Errno::last_raw() == 0 {
19901985
Ok(None)
19911986
} else {
19921987
Err(IOErrorBuilder::with_filename(

vm/src/stdlib/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ mod platform {
630630

631631
let ts = TimeSpec::from(dur);
632632
let res = unsafe { libc::nanosleep(ts.as_ref(), std::ptr::null_mut()) };
633-
let interrupted = res == -1 && nix::errno::errno() == libc::EINTR;
633+
let interrupted = res == -1 && nix::Error::last_raw() == libc::EINTR;
634634

635635
if interrupted {
636636
vm.check_signals()?;

0 commit comments

Comments
 (0)
0