Skip to content

Commit

Permalink
Merge pull request #2146 from davidhewitt/pypy-ffi-cleanup
Browse files Browse the repository at this point in the history
pypy: support fast long conversion
  • Loading branch information
davidhewitt authored Feb 5, 2022
2 parents 02b7f99 + 71e5a12 commit 5dd46e9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Use the Rust function path for `wrap_pymodule!` of a `#[pymodule]` with a `#[pyo3(name = "..")]` attribute, not the Python name. [#2081](https://github.com/PyO3/pyo3/pull/2081)
- Fix panic in `#[pyfunction]` generated code when a required argument following an `Option` was not provided. [#2093](https://github.com/PyO3/pyo3/pull/2093)
- Fixed undefined behaviour caused by incorrect `ExactSizeIterator` implementations. [#2124](https://github.com/PyO3/pyo3/pull/2124)
- Add missing FFI definitions `_PyLong_NumBits` and `_PyLong_AsByteArray` on PyPy. [#2146](https://github.com/PyO3/pyo3/pull/2146)

## [0.15.1] - 2021-11-19

Expand Down
4 changes: 2 additions & 2 deletions pyo3-ffi/src/longobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ extern "C" {
extern "C" {
// skipped non-limited _PyLong_Sign

#[cfg(not(PyPy))]
#[cfg_attr(PyPy, link_name = "_PyPyLong_NumBits")]
pub fn _PyLong_NumBits(obj: *mut PyObject) -> c_int;

// skipped _PyLong_DivmodNear
Expand All @@ -109,7 +109,7 @@ extern "C" {
is_signed: c_int,
) -> *mut PyObject;

#[cfg(not(PyPy))]
#[cfg_attr(PyPy, link_name = "_PyPyLong_AsByteArrayO")]
pub fn _PyLong_AsByteArray(
v: *mut PyLongObject,
bytes: *mut c_uchar,
Expand Down
12 changes: 5 additions & 7 deletions src/types/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ int_convert_u64_or_i64!(
ffi::PyLong_AsUnsignedLongLong
);

#[cfg(not(any(Py_LIMITED_API, PyPy)))]
#[cfg(not(Py_LIMITED_API))]
mod fast_128bit_int_conversion {
use super::*;

Expand Down Expand Up @@ -200,8 +200,8 @@ mod fast_128bit_int_conversion {
int_convert_128!(u128, 0);
}

// For ABI3 and PyPy, we implement the conversion manually.
#[cfg(any(Py_LIMITED_API, PyPy))]
// For ABI3 we implement the conversion manually.
#[cfg(Py_LIMITED_API)]
mod slow_128bit_int_conversion {
use super::*;
const SHIFT: usize = 64;
Expand Down Expand Up @@ -245,10 +245,10 @@ mod slow_128bit_int_conversion {
-1 as _,
ffi::PyLong_AsUnsignedLongLongMask(ob.as_ptr()),
)? as $rust_type;
let shifted = PyObject::from_owned_ptr(
let shifted = PyObject::from_owned_ptr_or_err(
py,
ffi::PyNumber_Rshift(ob.as_ptr(), SHIFT.into_py(py).as_ptr()),
);
)?;
let upper: $half_type = shifted.extract(py)?;
Ok((<$rust_type>::from(upper) << SHIFT) | lower)
}
Expand Down Expand Up @@ -461,8 +461,6 @@ mod tests {
test_common!(u64, u64);
test_common!(isize, isize);
test_common!(usize, usize);
#[cfg(not(any(Py_LIMITED_API, PyPy)))]
test_common!(i128, i128);
#[cfg(not(any(Py_LIMITED_API, PyPy)))]
test_common!(u128, u128);
}

0 comments on commit 5dd46e9

Please sign in to comment.