Skip to main content

pyforge_ffi/cpython/
pystate.rs

1use crate::PyThreadState;
2use crate::{PyFrameObject, PyInterpreterState, PyObject};
3use std::ffi::c_int;
4
5// skipped private _PyInterpreterState_RequiresIDRef
6// skipped private _PyInterpreterState_RequireIDRef
7
8pub type Py_tracefunc = unsafe extern "C" fn(
9    obj: *mut PyObject,
10    frame: *mut PyFrameObject,
11    what: c_int,
12    arg: *mut PyObject,
13) -> c_int;
14
15pub const PyTrace_CALL: c_int = 0;
16pub const PyTrace_EXCEPTION: c_int = 1;
17pub const PyTrace_LINE: c_int = 2;
18pub const PyTrace_RETURN: c_int = 3;
19pub const PyTrace_C_CALL: c_int = 4;
20pub const PyTrace_C_EXCEPTION: c_int = 5;
21pub const PyTrace_C_RETURN: c_int = 6;
22pub const PyTrace_OPCODE: c_int = 7;
23
24// skipped private _Py_MAX_SCRIPT_PATH_SIZE
25// skipped private _PyRemoteDebuggerSupport
26
27/// Private structure used inline in `PyGenObject`
28///
29/// `PyGenObject` was made opaque in Python 3.14, so we don't bother defining this
30/// structure for that version and later.
31#[cfg(not(Py_3_14))]
32#[repr(C)]
33#[derive(Clone, Copy)]
34pub(crate) struct _PyErr_StackItem {
35    exc_value: *mut PyObject,
36    previous_item: *mut _PyErr_StackItem,
37}
38
39// skipped private _PyStackChunk
40
41// skipped private _PY_DATA_STACK_CHUNK_SIZE
42// skipped private _ts (aka PyThreadState)
43
44extern_libpython! {
45    #[cfg(Py_3_13)]
46    pub fn PyThreadState_GetUnchecked() -> *mut PyThreadState;
47
48    #[cfg(not(Py_3_13))]
49    pub(crate) fn _PyThreadState_UncheckedGet() -> *mut PyThreadState;
50
51    pub fn PyThreadState_EnterTracing(state: *mut PyThreadState);
52    pub fn PyThreadState_LeaveTracing(state: *mut PyThreadState);
53
54    pub fn PyGILState_Check() -> c_int;
55
56    // skipped private _PyThread_CurrentFrames
57
58    // skipped PyUnstable_ThreadState_SetStackProtection
59    // skipped PyUnstable_ThreadState_ResetStackProtection
60
61    pub fn PyInterpreterState_Main() -> *mut PyInterpreterState;
62    pub fn PyInterpreterState_Head() -> *mut PyInterpreterState;
63    pub fn PyInterpreterState_Next(interp: *mut PyInterpreterState) -> *mut PyInterpreterState;
64    pub fn PyInterpreterState_ThreadHead(interp: *mut PyInterpreterState) -> *mut PyThreadState;
65    pub fn PyThreadState_Next(tstate: *mut PyThreadState) -> *mut PyThreadState;
66
67    pub fn PyThreadState_DeleteCurrent();
68}
69
70// skipped private _PyFrameEvalFunction
71// skipped private _PyInterpreterState_GetEvalFrameFunc
72// skipped private _PyInterpreterState_SetEvalFrameFunc