From e940854dec0f68d492cf1a91f3418ca514792ed0 Mon Sep 17 00:00:00 2001 From: Fabio Valentini Date: Wed, 26 Jun 2024 19:13:48 +0200 Subject: [PATCH] Fix regression in 128-bit number conversions --- ...ession-in-128-bit-number-conversions.patch | 54 +++++++++++++++++++ rust-pyo3.spec | 2 + 2 files changed, 56 insertions(+) create mode 100644 0001-fix-regression-in-128-bit-number-conversions.patch diff --git a/0001-fix-regression-in-128-bit-number-conversions.patch b/0001-fix-regression-in-128-bit-number-conversions.patch new file mode 100644 index 0000000..6d8d879 --- /dev/null +++ b/0001-fix-regression-in-128-bit-number-conversions.patch @@ -0,0 +1,54 @@ +From 0654258b18d314c83d6a3e78c4030d22b6b3ea75 Mon Sep 17 00:00:00 2001 +From: Fabio Valentini +Date: Wed, 26 Jun 2024 18:52:08 +0200 +Subject: [PATCH] fix regression in 128-bit number conversions + +--- + src/conversions/std/num.rs | 23 +++++++++++++---------- + 1 file changed, 13 insertions(+), 10 deletions(-) + +diff --git a/src/conversions/std/num.rs b/src/conversions/std/num.rs +index effe7c7..1304e73 100644 +--- a/src/conversions/std/num.rs ++++ b/src/conversions/std/num.rs +@@ -238,15 +238,18 @@ mod fast_128bit_int_conversion { + unsafe { ffi::PyNumber_Index(ob.as_ptr()).assume_owned_or_err(ob.py())? }; + let mut buffer = [0u8; std::mem::size_of::<$rust_type>()]; + #[cfg(not(Py_3_13))] +- crate::err::error_on_minusone(ob.py(), unsafe { +- ffi::_PyLong_AsByteArray( +- num.as_ptr() as *mut ffi::PyLongObject, +- buffer.as_mut_ptr(), +- buffer.len(), +- 1, +- $is_signed.into(), +- ) +- })?; ++ { ++ crate::err::error_on_minusone(ob.py(), unsafe { ++ ffi::_PyLong_AsByteArray( ++ num.as_ptr() as *mut ffi::PyLongObject, ++ buffer.as_mut_ptr(), ++ buffer.len(), ++ 1, ++ $is_signed.into(), ++ ) ++ })?; ++ Ok(<$rust_type>::from_le_bytes(buffer)) ++ } + #[cfg(Py_3_13)] + { + let mut flags = ffi::Py_ASNATIVEBYTES_NATIVE_ENDIAN; +@@ -272,8 +275,8 @@ mod fast_128bit_int_conversion { + "Python int larger than 128 bits", + )); + } ++ Ok(<$rust_type>::from_ne_bytes(buffer)) + } +- Ok(<$rust_type>::from_ne_bytes(buffer)) + } + + #[cfg(feature = "experimental-inspect")] +-- +2.45.2 + diff --git a/rust-pyo3.spec b/rust-pyo3.spec index 983e2f8..9abbdc4 100644 --- a/rust-pyo3.spec +++ b/rust-pyo3.spec @@ -15,6 +15,8 @@ Source: %{crates_source} # Manually created patch for downstream crate metadata changes # * drop MSVC- and MinGW-only features Patch: pyo3-fix-metadata.diff +# https://github.com/PyO3/pyo3/issues/4290 +Patch: 0001-fix-regression-in-128-bit-number-conversions.patch BuildRequires: cargo-rpm-macros >= 24