From 67c3a3bfb64900d9674b3fa0bc55ca934436c59d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelmer=20Vernoo=C4=B3?= Date: Tue, 4 Nov 2025 18:13:09 +0000 Subject: [PATCH] Migrate to PyO3 0.27 --- .github/workflows/wheels.yaml | 5 +++-- Cargo.lock | 20 ++++++++++---------- Cargo.toml | 2 +- src/lib.rs | 9 +++++++-- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/.github/workflows/wheels.yaml b/.github/workflows/wheels.yaml index e00af23..d5c99c4 100644 --- a/.github/workflows/wheels.yaml +++ b/.github/workflows/wheels.yaml @@ -1,10 +1,11 @@ +--- name: Build Python distributions -on: +"on": push: pull_request: schedule: - - cron: "0 6 * * *" # Daily 6AM UTC build + - cron: "0 6 * * *" # Daily 6AM UTC build jobs: build-wheels: diff --git a/Cargo.lock b/Cargo.lock index cdf74ef..8bf9999 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -68,9 +68,9 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.26.0" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ba0117f4212101ee6544044dae45abe1083d30ce7b29c4b5cbdfa2354e07383" +checksum = "37a6df7eab65fc7bee654a421404947e10a0f7085b6951bf2ea395f4659fb0cf" dependencies = [ "indoc", "libc", @@ -85,18 +85,18 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.26.0" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fc6ddaf24947d12a9aa31ac65431fb1b851b8f4365426e182901eabfb87df5f" +checksum = "f77d387774f6f6eec64a004eac0ed525aab7fa1966d94b42f743797b3e395afb" dependencies = [ "target-lexicon", ] [[package]] name = "pyo3-ffi" -version = "0.26.0" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "025474d3928738efb38ac36d4744a74a400c901c7596199e20e45d98eb194105" +checksum = "2dd13844a4242793e02df3e2ec093f540d948299a6a77ea9ce7afd8623f542be" dependencies = [ "libc", "pyo3-build-config", @@ -104,9 +104,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.26.0" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e64eb489f22fe1c95911b77c44cc41e7c19f3082fc81cce90f657cdc42ffded" +checksum = "eaf8f9f1108270b90d3676b8679586385430e5c0bb78bb5f043f95499c821a71" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -116,9 +116,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.26.0" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "100246c0ecf400b475341b8455a9213344569af29a3c841d29270e53102e0fcf" +checksum = "70a3b2274450ba5288bc9b8c1b69ff569d1d61189d4bff38f8d22e03d17f932b" dependencies = [ "heck", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 20e1d09..43601fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,4 @@ name = "fastbencode__bencode_rs" crate-type = ["cdylib"] [dependencies] -pyo3 = { version = ">=0.25,<0.27", features = ["extension-module"] } +pyo3 = { version = "0.27", features = ["extension-module"] } diff --git a/src/lib.rs b/src/lib.rs index 6d1618a..800d6d9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -177,7 +177,12 @@ impl Decoder { // Return as bytes or decode depending on bytestring_encoding if let Some(encoding) = &self.bytestring_encoding { - Ok(PyString::from_object(&bytes_obj, encoding, "strict")?.into_any()) + let encoding_cstr = std::ffi::CString::new(encoding.as_str()) + .map_err(|_| PyValueError::new_err("invalid encoding string"))?; + Ok( + PyString::from_encoded_object(&bytes_obj, Some(&encoding_cstr), Some(c"strict"))? + .into_any(), + ) } else { Ok(bytes_obj) } @@ -367,7 +372,7 @@ impl Encoder { let mut keys: Vec> = dict .keys() .iter() - .map(|key| key.extract::>()) + .map(|key| key.extract::>().map_err(|e| e.into())) .collect::>>()?; keys.sort_by(|a, b| { let a_str = a.extract::<&[u8]>().unwrap();