use crate::moduleobject::PyModuleDef;
use crate::object::PyObject;
use crate::pytypedefs::{PyInterpreterState, PyThreadState};
use std::ffi::c_int;
#[cfg(any(all(Py_3_9, not(Py_LIMITED_API)), Py_3_10))]
use crate::PyFrameObject;
use std::ffi::c_long;
pub const MAX_CO_EXTRA_USERS: c_int = 255;
extern_libpython! {
pub fn PyInterpreterState_New() -> *mut PyInterpreterState;
pub fn PyInterpreterState_Clear(arg1: *mut PyInterpreterState);
pub fn PyInterpreterState_Delete(arg1: *mut PyInterpreterState);
#[cfg(Py_3_9)]
pub fn PyInterpreterState_Get() -> *mut PyInterpreterState;
pub fn PyInterpreterState_GetDict(arg1: *mut PyInterpreterState) -> *mut PyObject;
pub fn PyInterpreterState_GetID(arg1: *mut PyInterpreterState) -> i64;
pub fn PyState_AddModule(arg1: *mut PyObject, arg2: *mut PyModuleDef) -> c_int;
pub fn PyState_RemoveModule(arg1: *mut PyModuleDef) -> c_int;
pub fn PyState_FindModule(arg1: *mut PyModuleDef) -> *mut PyObject;
pub fn PyThreadState_New(arg1: *mut PyInterpreterState) -> *mut PyThreadState;
pub fn PyThreadState_Clear(arg1: *mut PyThreadState);
pub fn PyThreadState_Delete(arg1: *mut PyThreadState);
pub fn PyThreadState_Get() -> *mut PyThreadState;
}
#[inline]
pub unsafe fn PyThreadState_GET() -> *mut PyThreadState {
PyThreadState_Get()
}
extern_libpython! {
pub fn PyThreadState_Swap(arg1: *mut PyThreadState) -> *mut PyThreadState;
pub fn PyThreadState_GetDict() -> *mut PyObject;
pub fn PyThreadState_SetAsyncExc(arg1: c_long, arg2: *mut PyObject) -> c_int;
#[cfg(any(all(Py_3_9, not(Py_LIMITED_API)), Py_3_10))]
pub fn PyThreadState_GetInterpreter(arg1: *mut PyThreadState) -> *mut PyInterpreterState;
#[cfg(any(all(Py_3_9, not(Py_LIMITED_API)), Py_3_10))]
pub fn PyThreadState_GetFrame(arg1: *mut PyThreadState) -> *mut PyFrameObject;
#[cfg(any(all(Py_3_9, not(Py_LIMITED_API)), Py_3_10))]
pub fn PyThreadState_GetID(arg1: *mut PyThreadState) -> i64;
}
#[repr(C)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum PyGILState_STATE {
PyGILState_LOCKED,
PyGILState_UNLOCKED,
}
#[cfg(not(any(Py_3_14, target_arch = "wasm32")))]
struct HangThread;
#[cfg(not(any(Py_3_14, target_arch = "wasm32")))]
impl Drop for HangThread {
fn drop(&mut self) {
loop {
std::thread::park(); }
}
}
mod raw {
#[cfg(not(any(Py_3_14, target_arch = "wasm32")))]
extern_libpython! { "C-unwind" {
pub fn PyGILState_Ensure() -> super::PyGILState_STATE;
}}
#[cfg(any(Py_3_14, target_arch = "wasm32"))]
extern_libpython! {
pub fn PyGILState_Ensure() -> super::PyGILState_STATE;
}
}
#[cfg(not(any(Py_3_14, target_arch = "wasm32")))]
pub unsafe extern "C" fn PyGILState_Ensure() -> PyGILState_STATE {
let guard = HangThread;
let ret: PyGILState_STATE = raw::PyGILState_Ensure();
std::mem::forget(guard);
ret
}
#[cfg(any(Py_3_14, target_arch = "wasm32"))]
pub use self::raw::PyGILState_Ensure;
extern_libpython! {
pub fn PyGILState_Release(arg1: PyGILState_STATE);
pub fn PyGILState_GetThisThreadState() -> *mut PyThreadState;
}