Skip to content

Commit b527ee8

Browse files
authored
sync pystate.h headers with Python 3.14 (#5711)
* sync `pystate.h` headers with Python 3.14 * newsfragments * fixup * fix typo * fix include on PyPy * fix another import on PyPy * review feedback
1 parent b467428 commit b527ee8

File tree

13 files changed

+76
-91
lines changed

13 files changed

+76
-91
lines changed

newsfragments/5711.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add FFI definitions `PyThreadState_GetInterpreter` and `PyThreadState_GetID` on Python 3.9+, `PyThreadState_EnterTracing` and `PyThreadState_LeaveTracing` on Python 3.11+, `PyThreadState_GetUnchecked` on Python 3.13+, and `compat::PyThreadState_GetUnchecked`.

newsfragments/5711.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Correct FFI definition for `PyThreadState_GetFrame` to mark it available with abi3 in 3.10+.

newsfragments/5711.removed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove private FFI definitions `_PyFrameEvalFunction`, `_PyInterpreterState_GetEvalFrameFunc` and `_PyInterpreterState_SetEvalFrameFunc`.

pyo3-ffi/src/ceval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::object::PyObject;
2-
use crate::pystate::PyThreadState;
2+
use crate::pytypedefs::PyThreadState;
33
use std::ffi::{c_char, c_int, c_void};
44

55
extern "C" {

pyo3-ffi/src/code.rs

Lines changed: 0 additions & 4 deletions
This file was deleted.

pyo3-ffi/src/compat/py_3_13.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,14 @@ compat_function!(
119119
result
120120
}
121121
);
122+
123+
#[cfg(not(Py_LIMITED_API))]
124+
compat_function!(
125+
originally_defined_for(Py_3_13);
126+
127+
#[inline]
128+
pub unsafe fn PyThreadState_GetUnchecked(
129+
) -> *mut crate::PyThreadState {
130+
crate::_PyThreadState_UncheckedGet()
131+
}
132+
);

pyo3-ffi/src/cpython/code.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::object::*;
22
use crate::pyport::Py_ssize_t;
33

4+
#[cfg(not(GraalPy))]
5+
use crate::PyCodeObject;
46
#[cfg(not(GraalPy))]
57
use std::ffi::c_char;
68
use std::ffi::{c_int, c_void};
@@ -32,13 +34,6 @@ use std::ptr::addr_of_mut;
3234

3335
// skipped private _PyExecutorArray
3436

35-
opaque_struct!(
36-
#[doc = "A Python code object.\n"]
37-
#[doc = "\n"]
38-
#[doc = "`pyo3-ffi` does not expose the contents of this struct, as it has no stability guarantees."]
39-
pub PyCodeObject
40-
);
41-
4237
/* Masks for co_flags */
4338
pub const CO_OPTIMIZED: c_int = 0x0001;
4439
pub const CO_NEWLOCALS: c_int = 0x0002;

pyo3-ffi/src/cpython/frameobject.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#[cfg(not(GraalPy))]
2-
use crate::cpython::code::PyCodeObject;
3-
#[cfg(not(GraalPy))]
42
use crate::object::*;
53
#[cfg(not(GraalPy))]
6-
use crate::pystate::PyThreadState;
4+
use crate::PyCodeObject;
75
use crate::PyFrameObject;
6+
#[cfg(not(GraalPy))]
7+
use crate::PyThreadState;
88
#[cfg(not(any(PyPy, GraalPy, Py_3_11)))]
99
use std::ffi::c_char;
1010
use std::ffi::c_int;

pyo3-ffi/src/cpython/pystate.rs

Lines changed: 29 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
#[cfg(not(PyPy))]
21
use crate::PyThreadState;
32
use crate::{PyFrameObject, PyInterpreterState, PyObject};
43
use std::ffi::c_int;
54

6-
// skipped _PyInterpreterState_RequiresIDRef
7-
// skipped _PyInterpreterState_RequireIDRef
8-
9-
// skipped _PyInterpreterState_GetMainModule
5+
// skipped private _PyInterpreterState_RequiresIDRef
6+
// skipped private _PyInterpreterState_RequireIDRef
107

118
pub type Py_tracefunc = unsafe extern "C" fn(
129
obj: *mut PyObject,
@@ -24,11 +21,14 @@ pub const PyTrace_C_EXCEPTION: c_int = 5;
2421
pub const PyTrace_C_RETURN: c_int = 6;
2522
pub const PyTrace_OPCODE: c_int = 7;
2623

27-
// skipped PyTraceInfo
28-
// skipped CFrame
24+
// skipped private _Py_MAX_SCRIPT_PATH_SIZE
25+
// skipped private _PyRemoteDebuggerSupport
2926

3027
/// Private structure used inline in `PyGenObject`
31-
#[cfg(not(PyPy))]
28+
///
29+
/// `PyGenObject` was made opaque in Python 3.14, so we don't bother defining this
30+
/// structure for that version and later.
31+
#[cfg(not(any(PyPy, Py_3_14)))]
3232
#[repr(C)]
3333
#[derive(Clone, Copy)]
3434
pub(crate) struct _PyErr_StackItem {
@@ -40,20 +40,30 @@ pub(crate) struct _PyErr_StackItem {
4040
previous_item: *mut _PyErr_StackItem,
4141
}
4242

43-
// skipped _PyStackChunk
44-
// skipped _ts (aka PyThreadState)
43+
// skipped private _PyStackChunk
44+
45+
// skipped private _PY_DATA_STACK_CHUNK_SIZE
46+
// skipped private _ts (aka PyThreadState)
4547

4648
extern "C" {
47-
// skipped _PyThreadState_Prealloc
48-
// skipped _PyThreadState_UncheckedGet
49-
// skipped _PyThreadState_GetDict
49+
#[cfg(Py_3_13)]
50+
pub fn PyThreadState_GetUnchecked() -> *mut PyThreadState;
51+
52+
#[cfg(not(Py_3_13))]
53+
pub(crate) fn _PyThreadState_UncheckedGet() -> *mut PyThreadState;
54+
55+
#[cfg(Py_3_11)]
56+
pub fn PyThreadState_EnterTracing(state: *mut PyThreadState);
57+
#[cfg(Py_3_11)]
58+
pub fn PyThreadState_LeaveTracing(state: *mut PyThreadState);
5059

5160
#[cfg_attr(PyPy, link_name = "PyPyGILState_Check")]
5261
pub fn PyGILState_Check() -> c_int;
5362

54-
// skipped _PyGILState_GetInterpreterStateUnsafe
55-
// skipped _PyThread_CurrentFrames
56-
// skipped _PyThread_CurrentExceptions
63+
// skipped private _PyThread_CurrentFrames
64+
65+
// skipped PyUnstable_ThreadState_SetStackProtection
66+
// skipped PyUnstable_ThreadState_ResetStackProtection
5767

5868
#[cfg(not(PyPy))]
5969
pub fn PyInterpreterState_Main() -> *mut PyInterpreterState;
@@ -70,44 +80,6 @@ extern "C" {
7080
pub fn PyThreadState_DeleteCurrent();
7181
}
7282

73-
#[cfg(all(Py_3_9, not(any(Py_3_11, PyPy))))]
74-
pub type _PyFrameEvalFunction = extern "C" fn(
75-
*mut crate::PyThreadState,
76-
*mut crate::PyFrameObject,
77-
c_int,
78-
) -> *mut crate::object::PyObject;
79-
80-
#[cfg(all(Py_3_11, not(PyPy)))]
81-
pub type _PyFrameEvalFunction = extern "C" fn(
82-
*mut crate::PyThreadState,
83-
*mut crate::_PyInterpreterFrame,
84-
c_int,
85-
) -> *mut crate::object::PyObject;
86-
87-
#[cfg(all(Py_3_9, not(PyPy)))]
88-
extern "C" {
89-
/// Get the frame evaluation function.
90-
pub fn _PyInterpreterState_GetEvalFrameFunc(
91-
interp: *mut PyInterpreterState,
92-
) -> _PyFrameEvalFunction;
93-
94-
///Set the frame evaluation function.
95-
pub fn _PyInterpreterState_SetEvalFrameFunc(
96-
interp: *mut PyInterpreterState,
97-
eval_frame: _PyFrameEvalFunction,
98-
);
99-
}
100-
101-
// skipped _PyInterpreterState_GetConfig
102-
// skipped _PyInterpreterState_GetConfigCopy
103-
// skipped _PyInterpreterState_SetConfig
104-
// skipped _Py_GetConfig
105-
106-
// skipped _PyCrossInterpreterData
107-
// skipped _PyObject_GetCrossInterpreterData
108-
// skipped _PyCrossInterpreterData_NewObject
109-
// skipped _PyCrossInterpreterData_Release
110-
// skipped _PyObject_CheckCrossInterpreterData
111-
// skipped crossinterpdatafunc
112-
// skipped _PyCrossInterpreterData_RegisterClass
113-
// skipped _PyCrossInterpreterData_Lookup
83+
// skipped private _PyFrameEvalFunction
84+
// skipped private _PyInterpreterState_GetEvalFrameFunc
85+
// skipped private _PyInterpreterState_SetEvalFrameFunc

pyo3-ffi/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,6 @@ pub use self::boolobject::*;
386386
pub use self::bytearrayobject::*;
387387
pub use self::bytesobject::*;
388388
pub use self::ceval::*;
389-
#[cfg(Py_LIMITED_API)]
390-
pub use self::code::*;
391389
pub use self::codecs::*;
392390
pub use self::compile::*;
393391
pub use self::complexobject::*;
@@ -455,8 +453,6 @@ mod bytesobject;
455453
// skipped cellobject.h
456454
mod ceval;
457455
// skipped classobject.h
458-
#[cfg(Py_LIMITED_API)]
459-
mod code;
460456
mod codecs;
461457
mod compile;
462458
mod complexobject;

0 commit comments

Comments
 (0)