python3_sys/
pystate.rs

1#[cfg(Py_3_9)]
2use crate::frameobject::PyFrameObject;
3use crate::moduleobject::PyModuleDef;
4use crate::object::PyObject;
5
6#[cfg(Py_3_6)]
7pub const MAX_CO_EXTRA_USERS: libc::c_int = 255;
8
9#[repr(C)]
10pub struct PyInterpreterState {
11    _private: [u8; 0],
12}
13
14#[repr(C)]
15pub struct PyThreadState {
16    _private: [u8; 0],
17}
18
19#[cfg_attr(windows, link(name = "pythonXY"))]
20extern "C" {
21    pub fn PyInterpreterState_New() -> *mut PyInterpreterState;
22    pub fn PyInterpreterState_Clear(arg1: *mut PyInterpreterState) -> ();
23    pub fn PyInterpreterState_Delete(arg1: *mut PyInterpreterState) -> ();
24    #[cfg(Py_3_9)]
25    pub fn PyInterpreterState_Get() -> *mut PyInterpreterState;
26    #[cfg(Py_3_8)]
27    pub fn PyInterpreterState_GetDict(arg1: *mut PyInterpreterState) -> *mut PyObject;
28    #[cfg(Py_3_7)]
29    pub fn PyInterpreterState_GetID(arg1: *mut PyInterpreterState) -> i64;
30    pub fn PyState_FindModule(arg1: *mut PyModuleDef) -> *mut PyObject;
31    pub fn PyThreadState_New(arg1: *mut PyInterpreterState) -> *mut PyThreadState;
32    ignore! {
33        fn _PyThreadState_Prealloc(arg1: *mut PyInterpreterState) -> *mut PyThreadState;
34        fn _PyThreadState_Init(arg1: *mut PyThreadState) -> ();
35    }
36    pub fn PyThreadState_Clear(arg1: *mut PyThreadState) -> ();
37    pub fn PyThreadState_Delete(arg1: *mut PyThreadState) -> ();
38    #[cfg(any(Py_3_7, py_sys_config = "WITH_THREAD"))]
39    pub fn PyThreadState_DeleteCurrent() -> ();
40    pub fn PyThreadState_Get() -> *mut PyThreadState;
41    pub fn PyThreadState_Swap(arg1: *mut PyThreadState) -> *mut PyThreadState;
42    pub fn PyThreadState_GetDict() -> *mut PyObject;
43    #[cfg(not(Py_3_7))]
44    pub fn PyThreadState_SetAsyncExc(arg1: libc::c_long, arg2: *mut PyObject) -> libc::c_int;
45    #[cfg(Py_3_7)]
46    pub fn PyThreadState_SetAsyncExc(arg1: libc::c_ulong, arg2: *mut PyObject) -> libc::c_int;
47    #[cfg(Py_3_9)]
48    pub fn PyThreadState_GetInterpreter(tstate: *mut PyThreadState) -> *mut PyInterpreterState;
49    #[cfg(Py_3_11)]
50    pub fn PyThreadState_EnterTracing(state: *mut PyThreadState);
51        #[cfg(Py_3_11)]
52    pub fn PyThreadState_LeaveTracing(state: *mut PyThreadState);
53    #[cfg(Py_3_9)]
54    pub fn PyThreadState_GetFrame(tstate: *mut PyThreadState) -> *mut PyFrameObject;
55    #[cfg(Py_3_9)]
56    pub fn PyThreadState_GetID(tstate: *mut PyThreadState) -> u64;
57}
58
59#[repr(C)]
60#[derive(Copy, Clone)]
61pub enum PyGILState_STATE {
62    PyGILState_LOCKED,
63    PyGILState_UNLOCKED,
64}
65
66#[cfg(any(Py_3_7, py_sys_config = "WITH_THREAD"))]
67#[cfg_attr(windows, link(name = "pythonXY"))]
68extern "C" {
69    #[cfg(Py_3_4)]
70    pub fn PyGILState_Check() -> libc::c_int;
71    pub fn PyGILState_Ensure() -> PyGILState_STATE;
72    pub fn PyGILState_Release(arg1: PyGILState_STATE) -> ();
73    pub fn PyGILState_GetThisThreadState() -> *mut PyThreadState;
74}
75
76#[inline(always)]
77pub unsafe fn PyThreadState_GET() -> *mut PyThreadState {
78    PyThreadState_Get()
79}