pyo3_ffi/cpython/
pystate.rs1#[cfg(all(Py_3_11, not(PyPy)))]
2use crate::cpython::pyframe::_PyInterpreterFrame;
3use crate::PyThreadState;
4use crate::{PyFrameObject, PyInterpreterState, PyObject};
5use core::ffi::c_int;
6
7pub type Py_tracefunc = unsafe extern "C" fn(
11 obj: *mut PyObject,
12 frame: *mut PyFrameObject,
13 what: c_int,
14 arg: *mut PyObject,
15) -> c_int;
16
17#[cfg(all(not(Py_3_11), not(PyPy)))]
18pub type _PyFrameEvalFunction = unsafe extern "C" fn(
19 tstate: *mut PyThreadState,
20 frame: *mut PyFrameObject,
21 throwflag: c_int,
22) -> *mut PyObject;
23
24#[cfg(all(Py_3_11, not(PyPy)))]
25pub type _PyFrameEvalFunction = unsafe extern "C" fn(
26 tstate: *mut PyThreadState,
27 frame: *mut _PyInterpreterFrame,
28 throwflag: c_int,
29) -> *mut PyObject;
30
31pub const PyTrace_CALL: c_int = 0;
32pub const PyTrace_EXCEPTION: c_int = 1;
33pub const PyTrace_LINE: c_int = 2;
34pub const PyTrace_RETURN: c_int = 3;
35pub const PyTrace_C_CALL: c_int = 4;
36pub const PyTrace_C_EXCEPTION: c_int = 5;
37pub const PyTrace_C_RETURN: c_int = 6;
38pub const PyTrace_OPCODE: c_int = 7;
39
40#[cfg(not(any(PyPy, Py_3_14)))]
48#[repr(C)]
49#[derive(Clone, Copy)]
50pub(crate) struct _PyErr_StackItem {
51 #[cfg(not(Py_3_11))]
52 exc_type: *mut PyObject,
53 exc_value: *mut PyObject,
54 #[cfg(not(Py_3_11))]
55 exc_traceback: *mut PyObject,
56 previous_item: *mut _PyErr_StackItem,
57}
58
59extern_libpython! {
65 #[cfg(Py_3_13)]
66 pub fn PyThreadState_GetUnchecked() -> *mut PyThreadState;
67
68 #[cfg(not(Py_3_13))]
69 pub(crate) fn _PyThreadState_UncheckedGet() -> *mut PyThreadState;
70
71 #[cfg(Py_3_11)]
72 pub fn PyThreadState_EnterTracing(state: *mut PyThreadState);
73 #[cfg(Py_3_11)]
74 pub fn PyThreadState_LeaveTracing(state: *mut PyThreadState);
75
76 #[cfg_attr(PyPy, link_name = "PyPyGILState_Check")]
77 pub fn PyGILState_Check() -> c_int;
78
79 #[cfg(not(PyPy))]
85 pub fn PyInterpreterState_Main() -> *mut PyInterpreterState;
86 #[cfg_attr(PyPy, link_name = "PyPyInterpreterState_Head")]
87 pub fn PyInterpreterState_Head() -> *mut PyInterpreterState;
88 #[cfg_attr(PyPy, link_name = "PyPyInterpreterState_Next")]
89 pub fn PyInterpreterState_Next(interp: *mut PyInterpreterState) -> *mut PyInterpreterState;
90 #[cfg(not(PyPy))]
91 pub fn PyInterpreterState_ThreadHead(interp: *mut PyInterpreterState) -> *mut PyThreadState;
92 #[cfg(not(PyPy))]
93 pub fn PyThreadState_Next(tstate: *mut PyThreadState) -> *mut PyThreadState;
94
95 #[cfg_attr(PyPy, link_name = "PyPyThreadState_DeleteCurrent")]
96 pub fn PyThreadState_DeleteCurrent();
97
98 #[cfg(all(not(Py_3_11), not(PyPy)))]
99 pub fn _PyInterpreterState_GetEvalFrameFunc(
100 interp: *mut PyInterpreterState,
101 ) -> Option<_PyFrameEvalFunction>;
102 #[cfg(all(Py_3_11, not(PyPy)))]
103 pub fn _PyInterpreterState_GetEvalFrameFunc(
104 interp: *mut PyInterpreterState,
105 ) -> _PyFrameEvalFunction;
106 #[cfg(not(PyPy))]
107 pub fn _PyInterpreterState_SetEvalFrameFunc(
108 interp: *mut PyInterpreterState,
109 eval_frame: Option<_PyFrameEvalFunction>,
110 );
111}