From 2f2113c34ab522e499366272a81e8d6060a488c5 Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Tue, 12 May 2026 11:30:03 +0100 Subject: [PATCH 1/3] remove more `_Py` private definitions from `pyo3-ffi` --- pyo3-ffi-check/macro/src/lib.rs | 14 -------------- pyo3-ffi/src/cpython/floatobject.rs | 3 ++- pyo3-ffi/src/cpython/pythonrun.rs | 21 --------------------- pyo3-ffi/src/cpython/unicodeobject.rs | 11 +++-------- pyo3-ffi/src/impl_/macros.rs | 24 ------------------------ pyo3-ffi/src/pyhash.rs | 8 ++++---- 6 files changed, 9 insertions(+), 72 deletions(-) diff --git a/pyo3-ffi-check/macro/src/lib.rs b/pyo3-ffi-check/macro/src/lib.rs index 7151e938c2a..2799d6d5865 100644 --- a/pyo3-ffi-check/macro/src/lib.rs +++ b/pyo3-ffi-check/macro/src/lib.rs @@ -441,15 +441,6 @@ const EXCLUDED_SYMBOLS: &[&str] = &[ "_PyEval_RequestCodeExtraIndex", // FIXME: probably outdated definitions that fail to build, need investigation, // temporarily here to make the build pass to get CI running - "_PyFloat_CAST", - "_PyObject_MakeTpCall", - "_PyRun_AnyFileObject", - "_PyRun_InteractiveLoopObject", - "_PyRun_SimpleFileObject", - "_PySequence_IterSearch", - "_PySet_NextEntry", - "_PyUnicode_CheckConsistency", - "_Py_CheckFunctionResult", "PyCode_New", "PyCode_NewWithPosOnlyArgs", "PyCFunction_New", @@ -474,7 +465,6 @@ const EXCLUDED_SYMBOLS: &[&str] = &[ "PyUnicode_EncodeUnicodeEscape", "PyUnicode_TransformDecimalToASCII", "PyUnicode_TranslateCharmap", - "_Py_HashBytes", // This symbol was not in headers but still public until Python 3.10, // should be able to remove this exclusion once support for 3.9 dropped "Py_GetArgcArgv", @@ -491,10 +481,6 @@ const EXCLUDED_SYMBOLS: &[&str] = &[ "PyOS_BeforeFork", "PyOS_AfterFork_Parent", "PyOS_AfterFork_Child", - // Private symbols that pyo3-ffi should stop exporting - "_PyUnicode_COMPACT_DATA", - "_PyUnicode_NONCOMPACT_DATA", - "_PyUnicode_Ready", // See https://github.com/python/cpython/pull/139166/changes#r3214904694 "Py_IS_TYPE", "Py_SIZE", diff --git a/pyo3-ffi/src/cpython/floatobject.rs b/pyo3-ffi/src/cpython/floatobject.rs index e3ff9a3371f..8a6ae1e636e 100644 --- a/pyo3-ffi/src/cpython/floatobject.rs +++ b/pyo3-ffi/src/cpython/floatobject.rs @@ -10,7 +10,8 @@ pub struct PyFloatObject { } #[inline] -pub unsafe fn _PyFloat_CAST(op: *mut PyObject) -> *mut PyFloatObject { +#[cfg(not(GraalPy))] +unsafe fn _PyFloat_CAST(op: *mut PyObject) -> *mut PyFloatObject { debug_assert_eq!(PyFloat_Check(op), 1); op.cast() } diff --git a/pyo3-ffi/src/cpython/pythonrun.rs b/pyo3-ffi/src/cpython/pythonrun.rs index 697747d05fa..e2df4ea298e 100644 --- a/pyo3-ffi/src/cpython/pythonrun.rs +++ b/pyo3-ffi/src/cpython/pythonrun.rs @@ -9,24 +9,12 @@ use libc::FILE; extern_libpython! { pub fn PyRun_SimpleStringFlags(arg1: *const c_char, arg2: *mut PyCompilerFlags) -> c_int; - pub fn _PyRun_SimpleFileObject( - fp: *mut FILE, - filename: *mut PyObject, - closeit: c_int, - flags: *mut PyCompilerFlags, - ) -> c_int; pub fn PyRun_AnyFileExFlags( fp: *mut FILE, filename: *const c_char, closeit: c_int, flags: *mut PyCompilerFlags, ) -> c_int; - pub fn _PyRun_AnyFileObject( - fp: *mut FILE, - filename: *mut PyObject, - closeit: c_int, - flags: *mut PyCompilerFlags, - ) -> c_int; pub fn PyRun_SimpleFileExFlags( fp: *mut FILE, filename: *const c_char, @@ -48,11 +36,6 @@ extern_libpython! { filename: *const c_char, flags: *mut PyCompilerFlags, ) -> c_int; - pub fn _PyRun_InteractiveLoopObject( - fp: *mut FILE, - filename: *mut PyObject, - flags: *mut PyCompilerFlags, - ) -> c_int; #[cfg(not(any(PyPy, GraalPy, Py_3_10)))] pub fn PyParser_ASTFromString( @@ -94,9 +77,7 @@ extern_libpython! { errcode: *mut c_int, arena: *mut PyArena, ) -> *mut _mod; -} -extern_libpython! { #[cfg_attr(PyPy, link_name = "PyPyRun_StringFlags")] pub fn PyRun_StringFlags( arg1: *const c_char, @@ -151,8 +132,6 @@ pub unsafe fn Py_CompileStringFlags( Py_CompileStringExFlags(string, p, s, f, -1) } -// skipped _Py_SourceAsString - extern_libpython! { #[cfg_attr(PyPy, link_name = "PyPyRun_String")] pub fn PyRun_String( diff --git a/pyo3-ffi/src/cpython/unicodeobject.rs b/pyo3-ffi/src/cpython/unicodeobject.rs index 9117d4d90e8..39315534786 100644 --- a/pyo3-ffi/src/cpython/unicodeobject.rs +++ b/pyo3-ffi/src/cpython/unicodeobject.rs @@ -458,11 +458,6 @@ pub struct PyUnicodeObject { pub data: PyUnicodeObjectData, } -extern_libpython! { - #[cfg(not(any(PyPy, GraalPy)))] - pub fn _PyUnicode_CheckConsistency(op: *mut PyObject, check_content: c_int) -> c_int; -} - // skipped PyUnicode_GET_SIZE // skipped PyUnicode_GET_DATA_SIZE // skipped PyUnicode_AS_UNICODE @@ -540,7 +535,7 @@ pub unsafe fn PyUnicode_KIND(op: *mut PyObject) -> c_uint { #[cfg(not(any(GraalPy, Py_3_14)))] #[inline] -pub unsafe fn _PyUnicode_COMPACT_DATA(op: *mut PyObject) -> *mut c_void { +unsafe fn _PyUnicode_COMPACT_DATA(op: *mut PyObject) -> *mut c_void { if PyUnicode_IS_ASCII(op) != 0 { (op as *mut PyASCIIObject).offset(1) as *mut c_void } else { @@ -550,7 +545,7 @@ pub unsafe fn _PyUnicode_COMPACT_DATA(op: *mut PyObject) -> *mut c_void { #[cfg(not(any(GraalPy, PyPy)))] #[inline] -pub unsafe fn _PyUnicode_NONCOMPACT_DATA(op: *mut PyObject) -> *mut c_void { +unsafe fn _PyUnicode_NONCOMPACT_DATA(op: *mut PyObject) -> *mut c_void { debug_assert!(!(*(op as *mut PyUnicodeObject)).data.any.is_null()); (*(op as *mut PyUnicodeObject)).data.any @@ -628,7 +623,7 @@ extern_libpython! { #[cfg_attr(PyPy, link_name = "PyPyUnicode_New")] pub fn PyUnicode_New(size: Py_ssize_t, maxchar: Py_UCS4) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "_PyPyUnicode_Ready")] - pub fn _PyUnicode_Ready(unicode: *mut PyObject) -> c_int; + fn _PyUnicode_Ready(unicode: *mut PyObject) -> c_int; // skipped _PyUnicode_Copy diff --git a/pyo3-ffi/src/impl_/macros.rs b/pyo3-ffi/src/impl_/macros.rs index 466fbb8f4de..2481d584072 100644 --- a/pyo3-ffi/src/impl_/macros.rs +++ b/pyo3-ffi/src/impl_/macros.rs @@ -110,30 +110,6 @@ macro_rules! extern_libpython_maybe_private_fn { ) => { extern_libpython_cpython_private_fn! { $(#[$attrs])* $vis $name($($args)*) $(-> $ret)? } }; - ( - [_PyRun_AnyFileObject] - $(#[$attrs:meta])* $vis:vis fn $name:ident($($args:tt)*) $(-> $ret:ty)? - ) => { - extern_libpython_cpython_private_fn! { $(#[$attrs])* $vis $name($($args)*) $(-> $ret)? } - }; - ( - [_PyRun_InteractiveLoopObject] - $(#[$attrs:meta])* $vis:vis fn $name:ident($($args:tt)*) $(-> $ret:ty)? - ) => { - extern_libpython_cpython_private_fn! { $(#[$attrs])* $vis $name($($args)*) $(-> $ret)? } - }; - ( - [_PyRun_SimpleFileObject] - $(#[$attrs:meta])* $vis:vis fn $name:ident($($args:tt)*) $(-> $ret:ty)? - ) => { - extern_libpython_cpython_private_fn! { $(#[$attrs])* $vis $name($($args)*) $(-> $ret)? } - }; - ( - [_PyUnicode_CheckConsistency] - $(#[$attrs:meta])* $vis:vis fn $name:ident($($args:tt)*) $(-> $ret:ty)? - ) => { - extern_libpython_cpython_private_fn! { $(#[$attrs])* $vis $name($($args)*) $(-> $ret)? } - }; ( [_PyUnicode_Ready] $(#[$attrs:meta])* $vis:vis fn $name:ident($($args:tt)*) $(-> $ret:ty)? diff --git a/pyo3-ffi/src/pyhash.rs b/pyo3-ffi/src/pyhash.rs index ca39071dbbf..ca6a3c70af9 100644 --- a/pyo3-ffi/src/pyhash.rs +++ b/pyo3-ffi/src/pyhash.rs @@ -1,6 +1,6 @@ -#[cfg(not(any(Py_LIMITED_API, PyPy)))] +#[cfg(not(any(Py_LIMITED_API, PyPy, Py_3_14)))] use crate::pyport::{Py_hash_t, Py_ssize_t}; -#[cfg(not(any(Py_LIMITED_API, PyPy)))] +#[cfg(not(any(Py_LIMITED_API, PyPy, Py_3_14)))] use core::ffi::c_void; use core::ffi::{c_int, c_ulong}; @@ -10,8 +10,8 @@ extern_libpython! { // skipped non-limited _Py_HashPointer // skipped non-limited _Py_HashPointerRaw - #[cfg(not(any(Py_LIMITED_API, PyPy)))] - pub fn _Py_HashBytes(src: *const c_void, len: Py_ssize_t) -> Py_hash_t; + #[cfg(not(any(Py_LIMITED_API, PyPy, Py_3_14)))] + pub(crate) fn _Py_HashBytes(src: *const c_void, len: Py_ssize_t) -> Py_hash_t; } pub const _PyHASH_MULTIPLIER: c_ulong = 1000003; From bf2d73ccea14ffb4c50deaca3422b85269c8d4a5 Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Tue, 12 May 2026 11:35:32 +0100 Subject: [PATCH 2/3] newsfragment --- newsfragments/6036.removed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/6036.removed.md diff --git a/newsfragments/6036.removed.md b/newsfragments/6036.removed.md new file mode 100644 index 00000000000..599db3afa6c --- /dev/null +++ b/newsfragments/6036.removed.md @@ -0,0 +1 @@ +Remove private FFI definitions `_PyFloat_CAST`, `_PyRun_SimpleFileObject`, `_PyRun_AnyFileObject`, `_PyRun_InteractiveLoopObject`, `_PyUnicode_CheckConsistency`, `_PyUnicode_COMPACT_DATA`, `_PyUnicode_NONCOMPACT_DATA`, `_PyUnicode_Ready`, and `_Py_HashBytes`. From 678a750b6f02897ea3d79e976cae677668f937e2 Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Tue, 12 May 2026 22:02:05 +0100 Subject: [PATCH 3/3] fixup graalpy import --- pyo3-ffi/src/cpython/floatobject.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyo3-ffi/src/cpython/floatobject.rs b/pyo3-ffi/src/cpython/floatobject.rs index 8a6ae1e636e..6dcb21397a5 100644 --- a/pyo3-ffi/src/cpython/floatobject.rs +++ b/pyo3-ffi/src/cpython/floatobject.rs @@ -1,6 +1,8 @@ #[cfg(GraalPy)] use crate::PyFloat_AsDouble; -use crate::{PyFloat_Check, PyObject}; +#[cfg(not(GraalPy))] +use crate::PyFloat_Check; +use crate::PyObject; use core::ffi::c_double; #[repr(C)]