Skip to content

Commit ddc7edb

Browse files
committed
sync pystate.h headers with Python 3.14
1 parent b69c767 commit ddc7edb

File tree

8 files changed

+64
-87
lines changed

8 files changed

+64
-87
lines changed

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+
create::_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: 24 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ use crate::PyThreadState;
33
use crate::{PyFrameObject, PyInterpreterState, PyObject};
44
use std::ffi::c_int;
55

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

119
pub type Py_tracefunc = unsafe extern "C" fn(
1210
obj: *mut PyObject,
@@ -24,11 +22,11 @@ pub const PyTrace_C_EXCEPTION: c_int = 5;
2422
pub const PyTrace_C_RETURN: c_int = 6;
2523
pub const PyTrace_OPCODE: c_int = 7;
2624

27-
// skipped PyTraceInfo
28-
// skipped CFrame
25+
// skipped private _Py_MAX_SCRIPT_PATH_SIZE
26+
// skipped private _PyRemoteDebuggerSupport
2927

3028
/// Private structure used inline in `PyGenObject`
31-
#[cfg(not(PyPy))]
29+
#[cfg(not(any(PyPy, Py_3_14)))]
3230
#[repr(C)]
3331
#[derive(Clone, Copy)]
3432
pub(crate) struct _PyErr_StackItem {
@@ -40,20 +38,28 @@ pub(crate) struct _PyErr_StackItem {
4038
previous_item: *mut _PyErr_StackItem,
4139
}
4240

43-
// skipped _PyStackChunk
44-
// skipped _ts (aka PyThreadState)
41+
// skipped private _PyStackChunk
42+
43+
// skipped private _PY_DATA_STACK_CHUNK_SIZE
44+
// skipped private _ts (aka PyThreadState)
4545

4646
extern "C" {
47-
// skipped _PyThreadState_Prealloc
48-
// skipped _PyThreadState_UncheckedGet
49-
// skipped _PyThreadState_GetDict
47+
#[cfg(Py_3_13)]
48+
pub fn PyThreadState_GetUnchecked() -> *mut PyThreadState;
49+
50+
#[cfg(not(Py_3_13))]
51+
pub(crate) fn _PyThreadState_UncheckedGet() -> *mut PyThreadState;
52+
53+
// skipped PyThreadState_EnterTracing
54+
// skipped PyThreadState_LeaveTracing
5055

5156
#[cfg_attr(PyPy, link_name = "PyPyGILState_Check")]
5257
pub fn PyGILState_Check() -> c_int;
5358

54-
// skipped _PyGILState_GetInterpreterStateUnsafe
55-
// skipped _PyThread_CurrentFrames
56-
// skipped _PyThread_CurrentExceptions
59+
// skipped private _PyThread_CurrentFrames
60+
61+
// skipped PyUnstable_ThreadState_SetStackProtection
62+
// skipped PyUnstable_ThreadState_ResetStackProtection
5763

5864
#[cfg(not(PyPy))]
5965
pub fn PyInterpreterState_Main() -> *mut PyInterpreterState;
@@ -70,44 +76,6 @@ extern "C" {
7076
pub fn PyThreadState_DeleteCurrent();
7177
}
7278

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
79+
// skipped private _PyFrameEvalFunction
80+
// skipped private _PyInterpreterState_GetEvalFrameFunc
81+
// 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;

pyo3-ffi/src/pystate.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::moduleobject::PyModuleDef;
22
use crate::object::PyObject;
3+
use crate::pytypedefs::{PyInterpreterState, PyThreadState};
34
use std::ffi::c_int;
45

56
#[cfg(all(Py_3_10, not(PyPy), not(Py_LIMITED_API)))]
@@ -10,9 +11,6 @@ use std::ffi::c_long;
1011

1112
pub const MAX_CO_EXTRA_USERS: c_int = 255;
1213

13-
opaque_struct!(pub PyThreadState);
14-
opaque_struct!(pub PyInterpreterState);
15-
1614
extern "C" {
1715
#[cfg(not(PyPy))]
1816
pub fn PyInterpreterState_New() -> *mut PyInterpreterState;
@@ -32,7 +30,6 @@ extern "C" {
3230

3331
#[cfg_attr(PyPy, link_name = "PyPyState_AddModule")]
3432
pub fn PyState_AddModule(arg1: *mut PyObject, arg2: *mut PyModuleDef) -> c_int;
35-
3633
#[cfg_attr(PyPy, link_name = "PyPyState_RemoveModule")]
3734
pub fn PyState_RemoveModule(arg1: *mut PyModuleDef) -> c_int;
3835

@@ -62,15 +59,16 @@ extern "C" {
6259
pub fn PyThreadState_GetDict() -> *mut PyObject;
6360
#[cfg(not(PyPy))]
6461
pub fn PyThreadState_SetAsyncExc(arg1: c_long, arg2: *mut PyObject) -> c_int;
65-
}
66-
67-
// skipped non-limited / 3.9 PyThreadState_GetInterpreter
68-
// skipped non-limited / 3.9 PyThreadState_GetID
6962

70-
extern "C" {
71-
// PyThreadState_GetFrame
72-
#[cfg(all(Py_3_10, not(PyPy), not(Py_LIMITED_API)))]
63+
#[cfg(any(all(Py_3_9, not(Py_LIMITED_API)), Py_3_10))]
64+
#[cfg(not(PyPy))]
65+
pub fn PyThreadState_GetInterpreter(arg1: *mut PyThreadState) -> *mut PyInterpreterState;
66+
#[cfg(any(all(Py_3_9, not(Py_LIMITED_API)), Py_3_10))]
67+
#[cfg(not(PyPy))]
7368
pub fn PyThreadState_GetFrame(arg1: *mut PyThreadState) -> *mut PyFrameObject;
69+
#[cfg(any(all(Py_3_9, not(Py_LIMITED_API)), Py_3_10))]
70+
#[cfg(not(PyPy))]
71+
pub fn PyThreadState_GetID(arg1: *mut PyThreadState) -> i64;
7472
}
7573

7674
#[repr(C)]

pyo3-ffi/src/pytypedefs.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
// TODO: Created this file as part of fixing pyframe.rs and cpython/pyframe.rs
2-
// TODO: Finish defining or moving declarations now in Include/pytypedefs.h
1+
// NB: unlike C, we do not need to forward declare structs in Rust.
2+
// So we only define opaque structs for those which do not have public structure.
33

4+
// PyModuleDef
5+
// PyModuleDef_Slot
6+
// PyMethodDef
7+
// PyGetSetDef
8+
// PyMemberDef
9+
10+
// PyObject
11+
// PyLongObject
12+
// PyTypeObject
13+
opaque_struct!(pub PyCodeObject);
414
opaque_struct!(pub PyFrameObject);
15+
16+
opaque_struct!(pub PyThreadState);
17+
opaque_struct!(pub PyInterpreterState);

0 commit comments

Comments
 (0)