python27_sys/
pystate.rs

1use libc::{c_int, c_long};
2
3use crate::frameobject::PyFrameObject;
4use crate::object::PyObject;
5
6#[repr(C)]
7pub struct PyInterpreterState {
8    _private: [u8; 0],
9}
10
11pub type Py_tracefunc = unsafe extern "C" fn(
12    arg1: *mut PyObject,
13    arg2: *mut PyFrameObject,
14    arg3: c_int,
15    arg4: *mut PyObject,
16) -> c_int;
17
18/* The following values are used for 'what' for tracefunc functions: */
19pub const PyTrace_CALL: c_int = 0;
20pub const PyTrace_EXCEPTION: c_int = 1;
21pub const PyTrace_LINE: c_int = 2;
22pub const PyTrace_RETURN: c_int = 3;
23pub const PyTrace_C_CALL: c_int = 4;
24pub const PyTrace_C_EXCEPTION: c_int = 5;
25pub const PyTrace_C_RETURN: c_int = 6;
26
27#[repr(C)]
28#[derive(Copy)]
29pub struct PyThreadState {
30    pub next: *mut PyThreadState,
31    pub interp: *mut PyInterpreterState,
32    pub frame: *mut PyFrameObject,
33    pub recursion_depth: c_int,
34    pub tracing: c_int,
35    pub use_tracing: c_int,
36    pub c_profilefunc: Option<Py_tracefunc>,
37    pub c_tracefunc: Option<Py_tracefunc>,
38    pub c_profileobj: *mut PyObject,
39    pub c_traceobj: *mut PyObject,
40    pub curexc_type: *mut PyObject,
41    pub curexc_value: *mut PyObject,
42    pub curexc_traceback: *mut PyObject,
43    pub exc_type: *mut PyObject,
44    pub exc_value: *mut PyObject,
45    pub exc_traceback: *mut PyObject,
46    pub dict: *mut PyObject,
47    pub tick_counter: c_int,
48    pub gilstate_counter: c_int,
49    pub async_exc: *mut PyObject,
50    pub thread_id: c_long,
51    pub trash_delete_nesting: c_int,
52    pub trash_delete_later: *mut PyObject,
53}
54
55impl Clone for PyThreadState {
56    #[inline]
57    fn clone(&self) -> PyThreadState {
58        *self
59    }
60}
61
62#[repr(C)]
63#[derive(Copy, Clone)]
64pub enum PyGILState_STATE {
65    PyGILState_LOCKED,
66    PyGILState_UNLOCKED,
67}
68
69#[cfg_attr(windows, link(name = "pythonXY"))]
70extern "C" {
71    static mut _PyThreadState_Current: *mut PyThreadState;
72    //static mut _PyThreadState_GetFrame: PyThreadFrameGetter;
73
74    pub fn PyInterpreterState_New() -> *mut PyInterpreterState;
75    pub fn PyInterpreterState_Clear(arg1: *mut PyInterpreterState);
76    pub fn PyInterpreterState_Delete(arg1: *mut PyInterpreterState);
77    pub fn PyThreadState_New(arg1: *mut PyInterpreterState) -> *mut PyThreadState;
78    pub fn _PyThreadState_Prealloc(arg1: *mut PyInterpreterState) -> *mut PyThreadState;
79    pub fn _PyThreadState_Init(arg1: *mut PyThreadState);
80    pub fn PyThreadState_Clear(arg1: *mut PyThreadState);
81    pub fn PyThreadState_Delete(arg1: *mut PyThreadState);
82    #[cfg(py_sys_config = "WITH_THREAD")]
83    pub fn PyThreadState_DeleteCurrent();
84    pub fn PyThreadState_Get() -> *mut PyThreadState;
85    pub fn PyThreadState_Swap(arg1: *mut PyThreadState) -> *mut PyThreadState;
86    pub fn PyThreadState_GetDict() -> *mut PyObject;
87    pub fn PyThreadState_SetAsyncExc(arg1: c_long, arg2: *mut PyObject) -> c_int;
88    pub fn PyGILState_Ensure() -> PyGILState_STATE;
89    pub fn PyGILState_Release(arg1: PyGILState_STATE);
90    pub fn PyGILState_GetThisThreadState() -> *mut PyThreadState;
91    fn _PyThread_CurrentFrames() -> *mut PyObject;
92    pub fn PyInterpreterState_Head() -> *mut PyInterpreterState;
93    pub fn PyInterpreterState_Next(arg1: *mut PyInterpreterState) -> *mut PyInterpreterState;
94    pub fn PyInterpreterState_ThreadHead(arg1: *mut PyInterpreterState) -> *mut PyThreadState;
95    pub fn PyThreadState_Next(arg1: *mut PyThreadState) -> *mut PyThreadState;
96}
97
98#[cfg(py_sys_config = "Py_DEBUG")]
99#[inline(always)]
100pub unsafe fn PyThreadState_GET() -> *mut PyThreadState {
101    PyThreadState_Get()
102}
103
104#[cfg(not(py_sys_config = "Py_DEBUG"))]
105#[inline(always)]
106pub unsafe fn PyThreadState_GET() -> *mut PyThreadState {
107    _PyThreadState_Current
108}