forked from Rust-related/RustPython
Update deps (#5417)
* Upgrade nix * Update deps * Upgrade pyo3, winreg * Fix errors from upgrading
This commit is contained in:
1164
Cargo.lock
generated
1164
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
10
Cargo.toml
10
Cargo.toml
@@ -49,7 +49,7 @@ rustyline = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = { version = "0.3.5", features = ["html_reports"] }
|
||||
pyo3 = { version = "0.20.2", features = ["auto-initialize"] }
|
||||
pyo3 = { version = "0.22", features = ["auto-initialize"] }
|
||||
|
||||
[[bench]]
|
||||
name = "execution"
|
||||
@@ -105,7 +105,7 @@ members = [
|
||||
version = "0.4.0"
|
||||
authors = ["RustPython Team"]
|
||||
edition = "2021"
|
||||
rust-version = "1.78.0"
|
||||
rust-version = "1.80.0"
|
||||
repository = "https://github.com/RustPython/RustPython"
|
||||
license = "MIT"
|
||||
|
||||
@@ -143,7 +143,7 @@ ahash = "0.8.11"
|
||||
ascii = "1.0"
|
||||
atty = "0.2.14"
|
||||
bitflags = "2.4.1"
|
||||
bstr = "0.2.17"
|
||||
bstr = "1"
|
||||
cfg-if = "1.0"
|
||||
chrono = "0.4.37"
|
||||
crossbeam-utils = "0.8.19"
|
||||
@@ -158,7 +158,7 @@ is-macro = "0.3.0"
|
||||
junction = "1.0.0"
|
||||
libc = "0.2.153"
|
||||
log = "0.4.16"
|
||||
nix = { version = "0.27", features = ["fs", "user", "process", "term", "time", "signal", "ioctl", "socket", "sched", "zerocopy", "dir", "hostname", "net", "poll"] }
|
||||
nix = { version = "0.29", features = ["fs", "user", "process", "term", "time", "signal", "ioctl", "socket", "sched", "zerocopy", "dir", "hostname", "net", "poll"] }
|
||||
malachite-bigint = "0.2.0"
|
||||
malachite-q = "0.4.4"
|
||||
malachite-base = "0.4.4"
|
||||
@@ -176,6 +176,8 @@ rustyline = "14.0.0"
|
||||
serde = { version = "1.0.133", default-features = false }
|
||||
schannel = "0.1.22"
|
||||
static_assertions = "1.1"
|
||||
strum = "0.26"
|
||||
strum_macros = "0.26"
|
||||
syn = "1.0.109"
|
||||
thiserror = "1.0"
|
||||
thread_local = "1.1.4"
|
||||
|
||||
@@ -13,8 +13,8 @@ use std::path::Path;
|
||||
fn bench_cpython_code(b: &mut Bencher, source: &str) {
|
||||
pyo3::Python::with_gil(|py| {
|
||||
b.iter(|| {
|
||||
let module =
|
||||
pyo3::types::PyModule::from_code(py, source, "", "").expect("Error running source");
|
||||
let module = pyo3::types::PyModule::from_code_bound(py, source, "", "")
|
||||
.expect("Error running source");
|
||||
black_box(module);
|
||||
})
|
||||
})
|
||||
@@ -53,9 +53,10 @@ pub fn benchmark_file_parsing(group: &mut BenchmarkGroup<WallTime>, name: &str,
|
||||
b.iter(|| ast::Suite::parse(contents, name).unwrap())
|
||||
});
|
||||
group.bench_function(BenchmarkId::new("cpython", name), |b| {
|
||||
use pyo3::types::PyAnyMethods;
|
||||
pyo3::Python::with_gil(|py| {
|
||||
let builtins =
|
||||
pyo3::types::PyModule::import(py, "builtins").expect("Failed to import builtins");
|
||||
let builtins = pyo3::types::PyModule::import_bound(py, "builtins")
|
||||
.expect("Failed to import builtins");
|
||||
let compile = builtins.getattr("compile").expect("no compile in builtins");
|
||||
b.iter(|| {
|
||||
let x = compile
|
||||
|
||||
@@ -2,6 +2,7 @@ use criterion::{
|
||||
criterion_group, criterion_main, measurement::WallTime, BatchSize, BenchmarkGroup, BenchmarkId,
|
||||
Criterion, Throughput,
|
||||
};
|
||||
use pyo3::types::PyAnyMethods;
|
||||
use rustpython_compiler::Mode;
|
||||
use rustpython_vm::{AsObject, Interpreter, PyResult, Settings};
|
||||
use std::{
|
||||
@@ -44,11 +45,14 @@ fn bench_cpython_code(group: &mut BenchmarkGroup<WallTime>, bench: &MicroBenchma
|
||||
|
||||
// Grab the exec function in advance so we don't have lookups in the hot code
|
||||
let builtins =
|
||||
pyo3::types::PyModule::import(py, "builtins").expect("Failed to import builtins");
|
||||
pyo3::types::PyModule::import_bound(py, "builtins").expect("Failed to import builtins");
|
||||
let exec = builtins.getattr("exec").expect("no exec in builtins");
|
||||
|
||||
let bench_func = |(globals, locals): &mut (&pyo3::types::PyDict, &pyo3::types::PyDict)| {
|
||||
let res = exec.call((code, &*globals, &*locals), None);
|
||||
let bench_func = |(globals, locals): &mut (
|
||||
pyo3::Bound<pyo3::types::PyDict>,
|
||||
pyo3::Bound<pyo3::types::PyDict>,
|
||||
)| {
|
||||
let res = exec.call((&code, &*globals, &*locals), None);
|
||||
if let Err(e) = res {
|
||||
e.print(py);
|
||||
panic!("Error running microbenchmark")
|
||||
@@ -56,13 +60,13 @@ fn bench_cpython_code(group: &mut BenchmarkGroup<WallTime>, bench: &MicroBenchma
|
||||
};
|
||||
|
||||
let bench_setup = |iterations| {
|
||||
let globals = pyo3::types::PyDict::new(py);
|
||||
let locals = pyo3::types::PyDict::new(py);
|
||||
let globals = pyo3::types::PyDict::new_bound(py);
|
||||
let locals = pyo3::types::PyDict::new_bound(py);
|
||||
if let Some(idx) = iterations {
|
||||
globals.set_item("ITERATIONS", idx).unwrap();
|
||||
}
|
||||
|
||||
let res = exec.call((setup_code, &globals, &locals), None);
|
||||
let res = exec.call((&setup_code, &globals, &locals), None);
|
||||
if let Err(e) = res {
|
||||
e.print(py);
|
||||
panic!("Error running microbenchmark setup code")
|
||||
@@ -93,9 +97,9 @@ fn cpy_compile_code<'a>(
|
||||
py: pyo3::Python<'a>,
|
||||
code: &str,
|
||||
name: &str,
|
||||
) -> pyo3::PyResult<&'a pyo3::types::PyCode> {
|
||||
) -> pyo3::PyResult<pyo3::Bound<'a, pyo3::types::PyCode>> {
|
||||
let builtins =
|
||||
pyo3::types::PyModule::import(py, "builtins").expect("Failed to import builtins");
|
||||
pyo3::types::PyModule::import_bound(py, "builtins").expect("Failed to import builtins");
|
||||
let compile = builtins.getattr("compile").expect("no compile in builtins");
|
||||
compile.call1((code, name, "exec"))?.extract()
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ rustpython-format = { workspace = true }
|
||||
|
||||
ascii = { workspace = true }
|
||||
bitflags = { workspace = true }
|
||||
bstr = { workspace = true }
|
||||
cfg-if = { workspace = true }
|
||||
itertools = { workspace = true }
|
||||
libc = { workspace = true }
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use bstr::ByteSlice;
|
||||
use malachite_base::{num::conversion::traits::RoundingInto, rounding_modes::RoundingMode};
|
||||
use malachite_bigint::{BigInt, BigUint, Sign};
|
||||
use malachite_q::Rational;
|
||||
@@ -32,7 +31,7 @@ pub fn float_to_ratio(value: f64) -> Option<(BigInt, BigInt)> {
|
||||
|
||||
pub fn bytes_to_int(lit: &[u8], mut base: u32) -> Option<BigInt> {
|
||||
// split sign
|
||||
let mut lit = lit.trim();
|
||||
let mut lit = lit.trim_ascii();
|
||||
let sign = match lit.first()? {
|
||||
b'+' => Some(Sign::Plus),
|
||||
b'-' => Some(Sign::Minus),
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
//! A crate to hold types and functions common to all rustpython components.
|
||||
|
||||
#![cfg_attr(target_os = "redox", feature(byte_slice_trim_ascii))]
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
pub use macros::*;
|
||||
|
||||
@@ -1842,15 +1842,16 @@ mod _socket {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use nix::poll::*;
|
||||
use std::os::fd::AsFd;
|
||||
let events = match kind {
|
||||
SelectKind::Read => PollFlags::POLLIN,
|
||||
SelectKind::Write => PollFlags::POLLOUT,
|
||||
SelectKind::Connect => PollFlags::POLLOUT | PollFlags::POLLERR,
|
||||
};
|
||||
let mut pollfd = [PollFd::new(sock, events)];
|
||||
let mut pollfd = [PollFd::new(sock.as_fd(), events)];
|
||||
let timeout = match interval {
|
||||
Some(d) => d.as_millis() as _,
|
||||
None => -1,
|
||||
Some(d) => d.try_into().unwrap_or(PollTimeout::MAX),
|
||||
None => PollTimeout::NONE,
|
||||
};
|
||||
let ret = poll(&mut pollfd, timeout)?;
|
||||
Ok(ret == 0)
|
||||
|
||||
@@ -74,7 +74,7 @@ memchr = { workspace = true }
|
||||
|
||||
caseless = "0.2.1"
|
||||
flamer = { version = "0.4", optional = true }
|
||||
half = "1.8.2"
|
||||
half = "2"
|
||||
memoffset = "0.9.1"
|
||||
optional = "0.5.0"
|
||||
result-like = "0.4.6"
|
||||
@@ -94,12 +94,12 @@ unic-ucd-ident = "0.9.0"
|
||||
rustix = { workspace = true }
|
||||
exitcode = "1.1.2"
|
||||
uname = "0.1.1"
|
||||
strum = "0.24.0"
|
||||
strum_macros = "0.24.0"
|
||||
strum = { workspace = true }
|
||||
strum_macros = { workspace = true }
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
rustyline = { workspace = true }
|
||||
which = "4.2.5"
|
||||
which = "6"
|
||||
|
||||
[target.'cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))'.dependencies]
|
||||
num_cpus = "1.13.1"
|
||||
@@ -108,7 +108,7 @@ num_cpus = "1.13.1"
|
||||
junction = { workspace = true }
|
||||
schannel = { workspace = true }
|
||||
widestring = { workspace = true }
|
||||
winreg = "0.10.1"
|
||||
winreg = "0.52"
|
||||
|
||||
[target.'cfg(windows)'.dependencies.windows]
|
||||
version = "0.52.0"
|
||||
|
||||
@@ -540,7 +540,8 @@ make_pack_float!(f64);
|
||||
impl Packable for f16 {
|
||||
fn pack<E: ByteOrder>(vm: &VirtualMachine, arg: PyObjectRef, data: &mut [u8]) -> PyResult<()> {
|
||||
let f_64 = *ArgIntoFloat::try_from_object(vm, arg)?;
|
||||
let f_16 = f16::from_f64(f_64);
|
||||
// "from_f64 should be preferred in any non-`const` context" except it gives the wrong result :/
|
||||
let f_16 = f16::from_f64_const(f_64);
|
||||
if f_16.is_infinite() != f_64.is_infinite() {
|
||||
return Err(vm.new_overflow_error("float too large to pack with e format".to_owned()));
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ fn inner_pow(v1: Complex64, v2: Complex64, vm: &VirtualMachine) -> PyResult<Comp
|
||||
};
|
||||
}
|
||||
|
||||
let ans = v1.powc(v2);
|
||||
let ans = powc(v1, v2);
|
||||
if ans.is_infinite() && !(v1.is_infinite() || v2.is_infinite()) {
|
||||
Err(vm.new_overflow_error("complex exponentiation overflow".to_owned()))
|
||||
} else {
|
||||
@@ -139,6 +139,19 @@ fn inner_pow(v1: Complex64, v2: Complex64, vm: &VirtualMachine) -> PyResult<Comp
|
||||
}
|
||||
}
|
||||
|
||||
// num-complex changed their powc() implementation in 0.4.4, making it incompatible
|
||||
// with what the regression tests expect. this is that old formula.
|
||||
fn powc(a: Complex64, exp: Complex64) -> Complex64 {
|
||||
let (r, theta) = a.to_polar();
|
||||
if r.is_zero() {
|
||||
return Complex64::new(r, r);
|
||||
}
|
||||
Complex64::from_polar(
|
||||
r.powf(exp.re) * (-exp.im * theta).exp(),
|
||||
exp.re * theta + exp.im * r.ln(),
|
||||
)
|
||||
}
|
||||
|
||||
impl Constructor for PyComplex {
|
||||
type Args = ComplexArgs;
|
||||
|
||||
|
||||
@@ -855,7 +855,7 @@ fn try_int_radix(obj: &PyObject, base: u32, vm: &VirtualMachine) -> PyResult<Big
|
||||
|
||||
let opt = match_class!(match obj.to_owned() {
|
||||
string @ PyStr => {
|
||||
let s = string.as_str();
|
||||
let s = string.as_str().trim();
|
||||
bytes_to_int(s.as_bytes(), base)
|
||||
}
|
||||
bytes @ PyBytes => {
|
||||
|
||||
@@ -77,7 +77,7 @@ impl PyObject {
|
||||
))
|
||||
})
|
||||
} else if let Some(s) = self.payload::<PyStr>() {
|
||||
try_convert(self, s.as_str().as_bytes(), vm)
|
||||
try_convert(self, s.as_str().trim().as_bytes(), vm)
|
||||
} else if let Some(bytes) = self.payload::<PyBytes>() {
|
||||
try_convert(self, bytes, vm)
|
||||
} else if let Some(bytearray) = self.payload::<PyByteArray>() {
|
||||
|
||||
@@ -406,9 +406,9 @@ pub mod module {
|
||||
};
|
||||
|
||||
let flag = if follow_symlinks.0 {
|
||||
nix::unistd::FchownatFlags::FollowSymlink
|
||||
nix::fcntl::AtFlags::empty()
|
||||
} else {
|
||||
nix::unistd::FchownatFlags::NoFollowSymlink
|
||||
nix::fcntl::AtFlags::AT_SYMLINK_NOFOLLOW
|
||||
};
|
||||
|
||||
let dir_fd = dir_fd.get_opt();
|
||||
@@ -631,10 +631,10 @@ pub mod module {
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
#[pyfunction]
|
||||
fn nice(increment: i32, vm: &VirtualMachine) -> PyResult<i32> {
|
||||
use nix::errno::{errno, Errno};
|
||||
use nix::errno::Errno;
|
||||
Errno::clear();
|
||||
let res = unsafe { libc::nice(increment) };
|
||||
if res == -1 && errno() != 0 {
|
||||
if res == -1 && Errno::last_raw() != 0 {
|
||||
Err(errno_err(vm))
|
||||
} else {
|
||||
Ok(res)
|
||||
@@ -877,16 +877,11 @@ pub mod module {
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
fn pipe(vm: &VirtualMachine) -> PyResult<(RawFd, RawFd)> {
|
||||
use nix::unistd::close;
|
||||
fn pipe(vm: &VirtualMachine) -> PyResult<(OwnedFd, OwnedFd)> {
|
||||
use nix::unistd::pipe;
|
||||
let (rfd, wfd) = pipe().map_err(|err| err.into_pyexception(vm))?;
|
||||
set_inheritable(rfd, false, vm)
|
||||
.and_then(|_| set_inheritable(wfd, false, vm))
|
||||
.inspect_err(|_| {
|
||||
let _ = close(rfd);
|
||||
let _ = close(wfd);
|
||||
})?;
|
||||
set_inheritable(rfd.as_raw_fd(), false, vm)?;
|
||||
set_inheritable(wfd.as_raw_fd(), false, vm)?;
|
||||
Ok((rfd, wfd))
|
||||
}
|
||||
|
||||
@@ -901,7 +896,7 @@ pub mod module {
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
#[pyfunction]
|
||||
fn pipe2(flags: libc::c_int, vm: &VirtualMachine) -> PyResult<(RawFd, RawFd)> {
|
||||
fn pipe2(flags: libc::c_int, vm: &VirtualMachine) -> PyResult<(OwnedFd, OwnedFd)> {
|
||||
let oflags = fcntl::OFlag::from_bits_truncate(flags);
|
||||
nix::unistd::pipe2(oflags).map_err(|err| err.into_pyexception(vm))
|
||||
}
|
||||
@@ -1227,7 +1222,7 @@ pub mod module {
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
fn ttyname(fd: i32, vm: &VirtualMachine) -> PyResult {
|
||||
fn ttyname(fd: BorrowedFd<'_>, vm: &VirtualMachine) -> PyResult {
|
||||
let name = unistd::ttyname(fd).map_err(|e| e.into_pyexception(vm))?;
|
||||
let name = name.into_os_string().into_string().unwrap();
|
||||
Ok(vm.ctx.new_str(name).into())
|
||||
@@ -1756,10 +1751,10 @@ pub mod module {
|
||||
who: PriorityWhoType,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult {
|
||||
use nix::errno::{errno, Errno};
|
||||
use nix::errno::Errno;
|
||||
Errno::clear();
|
||||
let retval = unsafe { libc::getpriority(which, who) };
|
||||
if errno() != 0 {
|
||||
if Errno::last_raw() != 0 {
|
||||
Err(errno_err(vm))
|
||||
} else {
|
||||
Ok(vm.ctx.new_int(retval).into())
|
||||
@@ -1973,10 +1968,10 @@ pub mod module {
|
||||
PathconfName(name): PathconfName,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<Option<libc::c_long>> {
|
||||
use nix::errno::{self, Errno};
|
||||
use nix::errno::Errno;
|
||||
|
||||
Errno::clear();
|
||||
debug_assert_eq!(errno::errno(), 0);
|
||||
debug_assert_eq!(Errno::last_raw(), 0);
|
||||
let raw = match &path {
|
||||
OsPathOrFd::Path(path) => {
|
||||
let path = path.clone().into_cstring(vm)?;
|
||||
@@ -1986,7 +1981,7 @@ pub mod module {
|
||||
};
|
||||
|
||||
if raw == -1 {
|
||||
if errno::errno() == 0 {
|
||||
if Errno::last_raw() == 0 {
|
||||
Ok(None)
|
||||
} else {
|
||||
Err(IOErrorBuilder::with_filename(
|
||||
|
||||
@@ -630,7 +630,7 @@ mod platform {
|
||||
|
||||
let ts = TimeSpec::from(dur);
|
||||
let res = unsafe { libc::nanosleep(ts.as_ref(), std::ptr::null_mut()) };
|
||||
let interrupted = res == -1 && nix::errno::errno() == libc::EINTR;
|
||||
let interrupted = res == -1 && nix::Error::last_raw() == libc::EINTR;
|
||||
|
||||
if interrupted {
|
||||
vm.check_signals()?;
|
||||
|
||||
@@ -33,6 +33,7 @@ mod winreg {
|
||||
TryFromObject, VirtualMachine,
|
||||
};
|
||||
use ::winreg::{enums::RegType, RegKey, RegValue};
|
||||
use std::mem::ManuallyDrop;
|
||||
use std::{ffi::OsStr, io};
|
||||
use windows_sys::Win32::Foundation;
|
||||
|
||||
@@ -97,7 +98,7 @@ mod winreg {
|
||||
|
||||
#[pymethod(magic)]
|
||||
fn bool(&self) -> bool {
|
||||
!self.key().raw_handle().is_null()
|
||||
self.key().raw_handle() != 0
|
||||
}
|
||||
#[pymethod(magic)]
|
||||
fn enter(zelf: PyRef<Self>) -> PyRef<Self> {
|
||||
@@ -125,10 +126,8 @@ mod winreg {
|
||||
match self {
|
||||
Self::PyHkey(py) => f(&py.key()),
|
||||
Self::Constant(hkey) => {
|
||||
let k = RegKey::predef(*hkey);
|
||||
let res = f(&k);
|
||||
std::mem::forget(k);
|
||||
res
|
||||
let k = ManuallyDrop::new(RegKey::predef(*hkey));
|
||||
f(&k)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -283,9 +282,11 @@ mod winreg {
|
||||
i.map(|i| vm.ctx.new_int(i).into())
|
||||
}};
|
||||
}
|
||||
let bytes_to_wide = |b: &[u8]| -> Option<&[u16]> {
|
||||
if b.len() % 2 == 0 {
|
||||
Some(unsafe { std::slice::from_raw_parts(b.as_ptr().cast(), b.len() / 2) })
|
||||
let bytes_to_wide = |b| {
|
||||
if <[u8]>::len(b) % 2 == 0 {
|
||||
let (pref, wide, suf) = unsafe { <[u8]>::align_to::<u16>(b) };
|
||||
assert!(pref.is_empty() && suf.is_empty(), "wide slice is unaligned");
|
||||
Some(wide)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
@@ -70,15 +70,15 @@ mod _browser {
|
||||
None => FetchResponseFormat::Text,
|
||||
};
|
||||
|
||||
let mut opts = web_sys::RequestInit::new();
|
||||
let opts = web_sys::RequestInit::new();
|
||||
|
||||
match method {
|
||||
Some(s) => opts.method(s.as_str()),
|
||||
None => opts.method("GET"),
|
||||
Some(s) => opts.set_method(s.as_str()),
|
||||
None => opts.set_method("GET"),
|
||||
};
|
||||
|
||||
if let Some(body) = body {
|
||||
opts.body(Some(&convert::py_to_js(vm, body)));
|
||||
opts.set_body(&convert::py_to_js(vm, body));
|
||||
}
|
||||
|
||||
let request = web_sys::Request::new_with_str_and_init(url.as_str(), &opts)
|
||||
@@ -225,8 +225,8 @@ mod _browser {
|
||||
fn load_module(module: PyStrRef, path: PyStrRef, vm: &VirtualMachine) -> PyResult {
|
||||
let weak_vm = weak_vm(vm);
|
||||
|
||||
let mut opts = web_sys::RequestInit::new();
|
||||
opts.method("GET");
|
||||
let opts = web_sys::RequestInit::new();
|
||||
opts.set_method("GET");
|
||||
|
||||
let request = web_sys::Request::new_with_str_and_init(path.as_str(), &opts)
|
||||
.map_err(|err| convert::js_py_typeerror(vm, err))?;
|
||||
|
||||
Reference in New Issue
Block a user