8000 Update deps by coolreader18 · Pull Request #5417 · RustPython/RustPython · GitHub
[go: up one dir, main page]

Skip to content

Update deps #5417

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

Merged
merged 4 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Upgrade pyo3, winreg
  • Loading branch information
coolreader18 committed Sep 25, 2024
commit a46a74dad9e7c971f21bcb47d31762a36138821d
43 changes: 22 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion 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 @@ -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 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 benches/microbenchmarks.rs
8000
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
8 changes: 4 additions & 4 deletions vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ 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 }
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
17 changes: 9 additions & 8 deletions 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<Se 1E80 lf> {
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
0