pyo3_ffi/cpython/
pystate.rs

1#[cfg(not(PyPy))]
2use crate::PyThreadState;
3use crate::{PyFrameObject, PyInterpreterState, PyObject};
4use std::os::raw::c_int;
5
6// skipped _PyInterpreterState_RequiresIDRef
7// skipped _PyInterpreterState_RequireIDRef
8
9// skipped _PyInterpreterState_GetMainModule
10
11pub type Py_tracefunc = unsafe extern "C" fn(
12    obj: *mut PyObject,
13    frame: *mut PyFrameObject,
14    what: c_int,
15    arg: *mut PyObject,
16) -> c_int;
17
18pub const PyTrace_CALL: c_int = 0;
19pub const PyTrace_EXCEPTION: c_int = 1;
20pub const PyTrace_LINE: c_int = 2;
21pub const PyTrace_RETURN: c_int = 3;
22pub const PyTrace_C_CALL: c_int = 4;
23pub const PyTrace_C_EXCEPTION: c_int = 5;
24pub const PyTrace_C_RETURN: c_int = 6;
25pub const PyTrace_OPCODE: c_int = 7;
26
27// skipped PyTraceInfo
28// skipped CFrame
29
30/// Private structure used inline in `PyGenObject`
31#[cfg(not(PyPy))]
32#[repr(C)]
33#[derive(Clone, Copy)]
34#[doc(hidden)] // TODO should be able to make pub(crate) after MSRV 1.74
35pub struct _PyErr_StackItem {
36    #[cfg(not(Py_3_11))]
37    exc_type: *mut PyObject,
38    exc_value: *mut PyObject,
39    #[cfg(not(Py_3_11))]
40    exc_traceback: *mut PyObject,
41    previous_item: *mut _PyErr_StackItem,
42}
43
44// skipped _PyStackChunk
45// skipped _ts (aka PyThreadState)
46
47extern "C" {
48    // skipped _PyThreadState_Prealloc
49    // skipped _PyThreadState_UncheckedGet
50    // skipped _PyThreadState_GetDict
51
52    #[cfg_attr(PyPy, link_name = "PyPyGILState_Check")]
53    pub fn PyGILState_Check() -> c_int;
54
55    // skipped _PyGILState_GetInterpreterStateUnsafe
56    // skipped _PyThread_CurrentFrames
57    // skipped _PyThread_CurrentExceptions
58
59    #[cfg(not(PyPy))]
60    pub fn PyInterpreterState_Main() -> *mut PyInterpreterState;
61    #[cfg_attr(PyPy, link_name = "PyPyInterpreterState_Head")]
62    pub fn PyInterpreterState_Head() -> *mut PyInterpreterState;
63    #[cfg_attr(PyPy, link_name = "PyPyInterpreterState_Next")]
64    pub fn PyInterpreterState_Next(interp: *mut PyInterpreterState) -> *mut PyInterpreterState;
65    #[cfg(not(PyPy))]
66    pub fn PyInterpreterState_ThreadHead(interp: *mut PyInterpreterState) -> *mut PyThreadState;
67    #[cfg(not(PyPy))]
68    pub fn PyThreadState_Next(tstate: *mut PyThreadState) -> *mut PyThreadState;
69
70    #[cfg_attr(PyPy, link_name = "PyPyThreadState_DeleteCurrent")]
71    pub fn PyThreadState_DeleteCurrent();
72}
73
74#[cfg(all(Py_3_9, not(any(Py_3_11, PyPy))))]
75pub type _PyFrameEvalFunction = extern "C" fn(
76    *mut crate::PyThreadState,
77    *mut crate::PyFrameObject,
78    c_int,
79) -> *mut crate::object::PyObject;
80
81#[cfg(all(Py_3_11, not(PyPy)))]
82pub type _PyFrameEvalFunction = extern "C" fn(
83    *mut crate::PyThreadState,
84    *mut crate::_PyInterpreterFrame,
85    c_int,
86) -> *mut crate::object::PyObject;
87
88#[cfg(all(Py_3_9, not(PyPy)))]
89extern "C" {
90    /// Get the frame evaluation function.
91    pub fn _PyInterpreterState_GetEvalFrameFunc(
92        interp: *mut PyInterpreterState,
93    ) -> _PyFrameEvalFunction;
94
95    ///Set the frame evaluation function.
96    pub fn _PyInterpreterState_SetEvalFrameFunc(
97        interp: *mut PyInterpreterState,
98        eval_frame: _PyFrameEvalFunction,
99    );
100}
101
102// skipped _PyInterpreterState_GetConfig
103// skipped _PyInterpreterState_GetConfigCopy
104// skipped _PyInterpreterState_SetConfig
105// skipped _Py_GetConfig
106
107// skipped _PyCrossInterpreterData
108// skipped _PyObject_GetCrossInterpreterData
109// skipped _PyCrossInterpreterData_NewObject
110// skipped _PyCrossInterpreterData_Release
111// skipped _PyObject_CheckCrossInterpreterData
112// skipped crossinterpdatafunc
113// skipped _PyCrossInterpreterData_RegisterClass
114// skipped _PyCrossInterpreterData_Lookup
⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here