Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions newsfragments/5946.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Removed use of the CPython-internal `_PyUnicode_COMPACT_DATA` symbol from PyO3's FFI test suite.
Removed `_PySet_NextEntry` in `pyo3-ffi`; it is a CPython-internal API with no stability guarantee.
Removed `_PyLong_NumBits` in `pyo3-ffi` and replaced its internal use with `int.bit_length()` for Python < 3.13 builds.
6 changes: 0 additions & 6 deletions pyo3-ffi/src/impl_/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,6 @@ macro_rules! extern_libpython_maybe_private_fn {
) => {
extern_libpython_cpython_private_fn! { $(#[$attrs])* $vis $name($($args)*) $(-> $ret)? }
};
(
[_PySet_NextEntry]
$(#[$attrs:meta])* $vis:vis fn $name:ident($($args:tt)*) $(-> $ret:ty)?
) => {
extern_libpython_cpython_private_fn! { $(#[$attrs])* $vis $name($($args)*) $(-> $ret)? }
};
(
[$name:ident]
$(#[$attrs:meta])* $vis:vis fn $fn_name:ident($($args:tt)*) $(-> $ret:ty)?
Expand Down
2 changes: 2 additions & 0 deletions pyo3-ffi/src/longobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ extern_libpython! {
#[cfg(not(Py_LIMITED_API))]
extern_libpython! {
#[cfg_attr(PyPy, link_name = "_PyPyLong_NumBits")]
#[cfg(not(Py_3_13))]
#[doc(hidden)]
pub fn _PyLong_NumBits(obj: *mut PyObject) -> size_t;
}

Expand Down
10 changes: 1 addition & 9 deletions pyo3-ffi/src/setobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,7 @@ pub unsafe fn PySet_GET_SIZE(so: *mut PyObject) -> Py_ssize_t {
// skipped _PySet_Dummy

extern_libpython! {
#[cfg(not(Py_LIMITED_API))]
#[cfg_attr(PyPy, link_name = "_PyPySet_NextEntry")]
pub fn _PySet_NextEntry(
set: *mut PyObject,
pos: *mut Py_ssize_t,
key: *mut *mut PyObject,
hash: *mut super::Py_hash_t,
) -> c_int;

// skipped non-limited _PySet_NextEntry
// skipped non-limited _PySet_Update
}

Expand Down
21 changes: 3 additions & 18 deletions src/conversions/num_bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,24 +318,9 @@ fn int_to_py_bytes<'py>(
#[inline]
#[cfg(any(not(Py_3_13), Py_LIMITED_API))]
fn int_n_bits(long: &Bound<'_, PyInt>) -> PyResult<usize> {
let py = long.py();
#[cfg(not(Py_LIMITED_API))]
{
// fast path
let n_bits = unsafe { crate::ffi::_PyLong_NumBits(long.as_ptr()) };
if n_bits == (-1isize as usize) {
return Err(crate::PyErr::fetch(py));
}
Ok(n_bits)
}

#[cfg(Py_LIMITED_API)]
{
// slow path
use crate::types::PyAnyMethods;
long.call_method0(crate::intern!(py, "bit_length"))
.and_then(|any| any.extract())
}
use crate::types::PyAnyMethods;
long.call_method0(crate::intern!(long.py(), "bit_length"))
.and_then(|any| any.extract())
}

#[cfg(test)]
Expand Down
4 changes: 0 additions & 4 deletions src/ffi/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ fn ascii() {
// 2 and 4 byte macros return nonsense for this string instance.
assert_eq!(PyUnicode_KIND(ptr), PyUnicode_1BYTE_KIND);

#[cfg(not(Py_3_14))]
assert!(!_PyUnicode_COMPACT_DATA(ptr).is_null());
// _PyUnicode_NONCOMPACT_DATA isn't valid for compact strings.
assert!(!PyUnicode_DATA(ptr).is_null());

Expand Down Expand Up @@ -243,8 +241,6 @@ fn ucs4() {
assert!(!PyUnicode_4BYTE_DATA(ptr).is_null());
assert_eq!(PyUnicode_KIND(ptr), PyUnicode_4BYTE_KIND);

#[cfg(not(Py_3_14))]
assert!(!_PyUnicode_COMPACT_DATA(ptr).is_null());
// _PyUnicode_NONCOMPACT_DATA isn't valid for compact strings.
assert!(!PyUnicode_DATA(ptr).is_null());

Expand Down
Loading