Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Upgrade clap to v3 (and other dep upgrades) #3512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
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
1,130 changes: 491 additions & 639 deletions 1,130 Cargo.lock

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions 8 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
9 changes: 5 additions & 4 deletions 9 benches/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
})
Expand Down Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions 20 benches/microbenchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -44,25 +45,28 @@ 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")
}
};

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")
Expand Down Expand Up @@ -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()
}
Expand Down
1 change: 0 additions & 1 deletion 1 common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
3 changes: 1 addition & 2 deletions 3 common/src/int.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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),
Expand Down
7 changes: 4 additions & 3 deletions 7 stdlib/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions 12 vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -152,4 +152,4 @@ itertools = { workspace = true }
rustc_version = "0.4.0"

[lints]
workspace = true
workspace = true
33 changes: 14 additions & 19 deletions 33 vm/src/stdlib/posix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
}

Expand All @@ -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))
}
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)?;
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion 2 vm/src/stdlib/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down
17 changes: 9 additions & 8 deletions 17 vm/src/stdlib/winreg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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
}
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.