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#[cfg(not(PyPy))]
31#[repr(C)]
32#[derive(Clone, Copy)]
33pub struct _PyErr_StackItem {
34    #[cfg(not(Py_3_11))]
35    pub exc_type: *mut PyObject,
36    pub exc_value: *mut PyObject,
37    #[cfg(not(Py_3_11))]
38    pub exc_traceback: *mut PyObject,
39    pub previous_item: *mut _PyErr_StackItem,
40}
41
42// skipped _PyStackChunk
43// skipped _ts (aka PyThreadState)
44
45extern "C" {
46    // skipped _PyThreadState_Prealloc
47    // skipped _PyThreadState_UncheckedGet
48    // skipped _PyThreadState_GetDict
49
50    #[cfg_attr(PyPy, link_name = "PyPyGILState_Check")]
51    pub fn PyGILState_Check() -> c_int;
52
53    // skipped _PyGILState_GetInterpreterStateUnsafe
54    // skipped _PyThread_CurrentFrames
55    // skipped _PyThread_CurrentExceptions
56
57    #[cfg(not(PyPy))]
58    pub fn PyInterpreterState_Main() -> *mut PyInterpreterState;
59    #[cfg_attr(PyPy, link_name = "PyPyInterpreterState_Head")]
60    pub fn PyInterpreterState_Head() -> *mut PyInterpreterState;
61    #[cfg_attr(PyPy, link_name = "PyPyInterpreterState_Next")]
62    pub fn PyInterpreterState_Next(interp: *mut PyInterpreterState) -> *mut PyInterpreterState;
63    #[cfg(not(PyPy))]
64    pub fn PyInterpreterState_ThreadHead(interp: *mut PyInterpreterState) -> *mut PyThreadState;
65    #[cfg(not(PyPy))]
66    pub fn PyThreadState_Next(tstate: *mut PyThreadState) -> *mut PyThreadState;
67
68    #[cfg_attr(PyPy, link_name = "PyPyThreadState_DeleteCurrent")]
69    pub fn PyThreadState_DeleteCurrent();
70}
71
72#[cfg(all(Py_3_9, not(any(Py_3_11, PyPy))))]
73pub type _PyFrameEvalFunction = extern "C" fn(
74    *mut crate::PyThreadState,
75    *mut crate::PyFrameObject,
76    c_int,
77) -> *mut crate::object::PyObject;
78
79#[cfg(all(Py_3_11, not(PyPy)))]
80pub type _PyFrameEvalFunction = extern "C" fn(
81    *mut crate::PyThreadState,
82    *mut crate::_PyInterpreterFrame,
83    c_int,
84) -> *mut crate::object::PyObject;
85
86#[cfg(all(Py_3_9, not(PyPy)))]
87extern "C" {
88    /// Get the frame evaluation function.
89    pub fn _PyInterpreterState_GetEvalFrameFunc(
90        interp: *mut PyInterpreterState,
91    ) -> _PyFrameEvalFunction;
92
93    ///Set the frame evaluation function.
94    pub fn _PyInterpreterState_SetEvalFrameFunc(
95        interp: *mut PyInterpreterState,
96        eval_frame: _PyFrameEvalFunction,
97    );
98}
99
100// skipped _PyInterpreterState_GetConfig
101// skipped _PyInterpreterState_GetConfigCopy
102// skipped _PyInterpreterState_SetConfig
103// skipped _Py_GetConfig
104
105// skipped _PyCrossInterpreterData
106// skipped _PyObject_GetCrossInterpreterData
107// skipped _PyCrossInterpreterData_NewObject
108// skipped _PyCrossInterpreterData_Release
109// skipped _PyObject_CheckCrossInterpreterData
110// skipped crossinterpdatafunc
111// skipped _PyCrossInterpreterData_RegisterClass
112// skipped _PyCrossInterpreterData_Lookup