pyo3_ffi/cpython/
pystate.rs1#[cfg(not(PyPy))]
2use crate::PyThreadState;
3use crate::{PyFrameObject, PyInterpreterState, PyObject};
4use std::os::raw::c_int;
5
6pub 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#[cfg(not(PyPy))]
32#[repr(C)]
33#[derive(Clone, Copy)]
34pub(crate) struct _PyErr_StackItem {
35 #[cfg(not(Py_3_11))]
36 exc_type: *mut PyObject,
37 exc_value: *mut PyObject,
38 #[cfg(not(Py_3_11))]
39 exc_traceback: *mut PyObject,
40 previous_item: *mut _PyErr_StackItem,
41}
42
43extern "C" {
47 #[cfg_attr(PyPy, link_name = "PyPyGILState_Check")]
52 pub fn PyGILState_Check() -> c_int;
53
54 #[cfg(not(PyPy))]
59 pub fn PyInterpreterState_Main() -> *mut PyInterpreterState;
60 #[cfg_attr(PyPy, link_name = "PyPyInterpreterState_Head")]
61 pub fn PyInterpreterState_Head() -> *mut PyInterpreterState;
62 #[cfg_attr(PyPy, link_name = "PyPyInterpreterState_Next")]
63 pub fn PyInterpreterState_Next(interp: *mut PyInterpreterState) -> *mut PyInterpreterState;
64 #[cfg(not(PyPy))]
65 pub fn PyInterpreterState_ThreadHead(interp: *mut PyInterpreterState) -> *mut PyThreadState;
66 #[cfg(not(PyPy))]
67 pub fn PyThreadState_Next(tstate: *mut PyThreadState) -> *mut PyThreadState;
68
69 #[cfg_attr(PyPy, link_name = "PyPyThreadState_DeleteCurrent")]
70 pub fn PyThreadState_DeleteCurrent();
71}
72
73#[cfg(all(Py_3_9, not(any(Py_3_11, PyPy))))]
74pub 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)))]
81pub 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)))]
88extern "C" {
89 pub fn _PyInterpreterState_GetEvalFrameFunc(
91 interp: *mut PyInterpreterState,
92 ) -> _PyFrameEvalFunction;
93
94 pub fn _PyInterpreterState_SetEvalFrameFunc(
96 interp: *mut PyInterpreterState,
97 eval_frame: _PyFrameEvalFunction,
98 );
99}
100
101