1 | #[cfg (any(not(PyPy), Py_3_9))] |
2 | use crate::moduleobject::PyModuleDef; |
3 | use crate::object::PyObject; |
4 | use std::os::raw::c_int; |
5 | |
6 | #[cfg (not(PyPy))] |
7 | use std::os::raw::c_long; |
8 | |
9 | pub const MAX_CO_EXTRA_USERS: c_int = 255; |
10 | |
11 | opaque_struct!(PyThreadState); |
12 | opaque_struct!(PyInterpreterState); |
13 | |
14 | extern "C" { |
15 | #[cfg (not(PyPy))] |
16 | pub fn PyInterpreterState_New() -> *mut PyInterpreterState; |
17 | #[cfg (not(PyPy))] |
18 | pub fn PyInterpreterState_Clear(arg1: *mut PyInterpreterState); |
19 | #[cfg (not(PyPy))] |
20 | pub fn PyInterpreterState_Delete(arg1: *mut PyInterpreterState); |
21 | |
22 | #[cfg (all(Py_3_9, not(PyPy)))] |
23 | pub fn PyInterpreterState_Get() -> *mut PyInterpreterState; |
24 | |
25 | #[cfg (all(Py_3_8, not(PyPy)))] |
26 | pub fn PyInterpreterState_GetDict(arg1: *mut PyInterpreterState) -> *mut PyObject; |
27 | |
28 | #[cfg (not(PyPy))] |
29 | pub fn PyInterpreterState_GetID(arg1: *mut PyInterpreterState) -> i64; |
30 | |
31 | #[cfg (any(not(PyPy), Py_3_9))] // only on PyPy since 3.9 |
32 | #[cfg_attr (PyPy, link_name = "PyPyState_AddModule" )] |
33 | pub fn PyState_AddModule(arg1: *mut PyObject, arg2: *mut PyModuleDef) -> c_int; |
34 | |
35 | #[cfg (any(not(PyPy), Py_3_9))] // only on PyPy since 3.9 |
36 | #[cfg_attr (PyPy, link_name = "PyPyState_RemoveModule" )] |
37 | pub fn PyState_RemoveModule(arg1: *mut PyModuleDef) -> c_int; |
38 | |
39 | #[cfg (any(not(PyPy), Py_3_9))] // only on PyPy since 3.9 |
40 | // only has PyPy prefix since 3.10 |
41 | #[cfg_attr (all(PyPy, Py_3_10), link_name = "PyPyState_FindModule" )] |
42 | pub fn PyState_FindModule(arg1: *mut PyModuleDef) -> *mut PyObject; |
43 | |
44 | #[cfg_attr (PyPy, link_name = "PyPyThreadState_New" )] |
45 | pub fn PyThreadState_New(arg1: *mut PyInterpreterState) -> *mut PyThreadState; |
46 | #[cfg_attr (PyPy, link_name = "PyPyThreadState_Clear" )] |
47 | pub fn PyThreadState_Clear(arg1: *mut PyThreadState); |
48 | #[cfg_attr (PyPy, link_name = "PyPyThreadState_Delete" )] |
49 | pub fn PyThreadState_Delete(arg1: *mut PyThreadState); |
50 | |
51 | #[cfg_attr (PyPy, link_name = "PyPyThreadState_Get" )] |
52 | pub fn PyThreadState_Get() -> *mut PyThreadState; |
53 | } |
54 | |
55 | #[inline ] |
56 | pub unsafe fn PyThreadState_GET() -> *mut PyThreadState { |
57 | PyThreadState_Get() |
58 | } |
59 | |
60 | extern "C" { |
61 | #[cfg_attr (PyPy, link_name = "PyPyThreadState_Swap" )] |
62 | pub fn PyThreadState_Swap(arg1: *mut PyThreadState) -> *mut PyThreadState; |
63 | #[cfg_attr (PyPy, link_name = "PyPyThreadState_GetDict" )] |
64 | pub fn PyThreadState_GetDict() -> *mut PyObject; |
65 | #[cfg (not(PyPy))] |
66 | pub fn PyThreadState_SetAsyncExc(arg1: c_long, arg2: *mut PyObject) -> c_int; |
67 | } |
68 | |
69 | // skipped non-limited / 3.9 PyThreadState_GetInterpreter |
70 | // skipped non-limited / 3.9 PyThreadState_GetFrame |
71 | // skipped non-limited / 3.9 PyThreadState_GetID |
72 | |
73 | #[repr (C)] |
74 | #[derive (Copy, Clone, Debug, PartialEq, Eq)] |
75 | pub enum PyGILState_STATE { |
76 | PyGILState_LOCKED, |
77 | PyGILState_UNLOCKED, |
78 | } |
79 | |
80 | extern "C" { |
81 | #[cfg_attr (PyPy, link_name = "PyPyGILState_Ensure" )] |
82 | pub fn PyGILState_Ensure() -> PyGILState_STATE; |
83 | #[cfg_attr (PyPy, link_name = "PyPyGILState_Release" )] |
84 | pub fn PyGILState_Release(arg1: PyGILState_STATE); |
85 | #[cfg (not(PyPy))] |
86 | pub fn PyGILState_GetThisThreadState() -> *mut PyThreadState; |
87 | } |
88 | |