Skip to content

Commit

Permalink
Merge pull request #2161 from cmpute/main
Browse files Browse the repository at this point in the history
Fix the signature of _PyLong_NumBits
  • Loading branch information
davidhewitt authored Feb 13, 2022
2 parents 03e650c + de502f0 commit fd57a5e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 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)
- Fix memory leak in implementation of `AsPyPointer` for `Option<T>`. [#2160](https://github.com/PyO3/pyo3/pull/2160)
- Fix the signature of `_PyLong_NumBits` [#2161](https://github.com/PyO3/pyo3/pull/2161)

## [0.15.1] - 2021-11-19

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

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

// skipped _PyLong_DivmodNear

Expand Down
4 changes: 2 additions & 2 deletions src/conversions/num_bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ macro_rules! bigint_conversion {
let num: Py<PyLong> =
Py::from_owned_ptr_or_err(py, ffi::PyNumber_Index(ob.as_ptr()))?;
let n_bits = ffi::_PyLong_NumBits(num.as_ptr());
let n_bytes = if n_bits == -1 {
let n_bytes = if n_bits == (-1isize as usize) {
return Err(PyErr::fetch(py));
} else if n_bits == 0 {
0
} else {
(n_bits as usize - 1 + $is_signed) / 8 + 1
(n_bits - 1 + $is_signed) / 8 + 1
};
if n_bytes <= 128 {
let mut buffer = [0; 128];
Expand Down

0 comments on commit fd57a5e

Please sign in to comment.