diff --git a/newsfragments/5946.changed.md b/newsfragments/5946.changed.md new file mode 100644 index 00000000000..5e606663272 --- /dev/null +++ b/newsfragments/5946.changed.md @@ -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. diff --git a/pyo3-ffi/src/impl_/macros.rs b/pyo3-ffi/src/impl_/macros.rs index c493157186c..c5ca00a029e 100644 --- a/pyo3-ffi/src/impl_/macros.rs +++ b/pyo3-ffi/src/impl_/macros.rs @@ -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)? diff --git a/pyo3-ffi/src/longobject.rs b/pyo3-ffi/src/longobject.rs index 7aab545777e..4ecd22ce8fc 100644 --- a/pyo3-ffi/src/longobject.rs +++ b/pyo3-ffi/src/longobject.rs @@ -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; } diff --git a/pyo3-ffi/src/setobject.rs b/pyo3-ffi/src/setobject.rs index b56ed5d1cd5..8a22415257f 100644 --- a/pyo3-ffi/src/setobject.rs +++ b/pyo3-ffi/src/setobject.rs @@ -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 } diff --git a/src/conversions/num_bigint.rs b/src/conversions/num_bigint.rs index cdc77d8b095..c11ca92e6a5 100644 --- a/src/conversions/num_bigint.rs +++ b/src/conversions/num_bigint.rs @@ -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 { - 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)] diff --git a/src/ffi/tests.rs b/src/ffi/tests.rs index 8b5226dd444..203669083c0 100644 --- a/src/ffi/tests.rs +++ b/src/ffi/tests.rs @@ -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()); @@ -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());