1use crate::cpython::code::PyCodeObject;
2use crate::object::*;
3use crate::pystate::PyThreadState;
4#[cfg(not(any(PyPy, Py_3_11)))]
5use std::os::raw::c_char;
6use std::os::raw::c_int;
7use std::ptr::addr_of_mut;
8
9#[cfg(not(any(PyPy, Py_3_11)))]
10pub type PyFrameState = c_char;
11
12#[repr(C)]
13#[derive(Copy, Clone)]
14#[cfg(not(any(PyPy, Py_3_11)))]
15pub struct PyTryBlock {
16 pub b_type: c_int,
17 pub b_handler: c_int,
18 pub b_level: c_int,
19}
20
21#[repr(C)]
22#[derive(Copy, Clone)]
23#[cfg(not(any(PyPy, Py_3_11)))]
24pub struct PyFrameObject {
25 pub ob_base: PyVarObject,
26 pub f_back: *mut PyFrameObject,
27 pub f_code: *mut PyCodeObject,
28 pub f_builtins: *mut PyObject,
29 pub f_globals: *mut PyObject,
30 pub f_locals: *mut PyObject,
31 pub f_valuestack: *mut *mut PyObject,
32
33 #[cfg(not(Py_3_10))]
34 pub f_stacktop: *mut *mut PyObject,
35 pub f_trace: *mut PyObject,
36 #[cfg(Py_3_10)]
37 pub f_stackdepth: c_int,
38 pub f_trace_lines: c_char,
39 pub f_trace_opcodes: c_char,
40
41 pub f_gen: *mut PyObject,
42
43 pub f_lasti: c_int,
44 pub f_lineno: c_int,
45 pub f_iblock: c_int,
46 #[cfg(not(Py_3_10))]
47 pub f_executing: c_char,
48 #[cfg(Py_3_10)]
49 pub f_state: PyFrameState,
50 pub f_blockstack: [PyTryBlock; crate::CO_MAXBLOCKS],
51 pub f_localsplus: [*mut PyObject; 1],
52}
53
54#[cfg(any(PyPy, Py_3_11))]
55opaque_struct!(PyFrameObject);
56
57// skipped _PyFrame_IsRunnable
58// skipped _PyFrame_IsExecuting
59// skipped _PyFrameHasCompleted
60
61#[cfg_attr(windows, link(name = "pythonXY"))]
62extern "C" {
63 pub static mut PyFrame_Type: PyTypeObject;
64}
65
66#[inline]
67pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int {
68 (Py_TYPE(ob:op) == addr_of_mut!(PyFrame_Type)) as c_int
69}
70
71extern "C" {
72 #[cfg_attr(PyPy, link_name = "PyPyFrame_New")]
73 pub fn PyFrame_New(
74 tstate: *mut PyThreadState,
75 code: *mut PyCodeObject,
76 globals: *mut PyObject,
77 locals: *mut PyObject,
78 ) -> *mut PyFrameObject;
79 // skipped _PyFrame_New_NoTrack
80
81 pub fn PyFrame_BlockSetup(f: *mut PyFrameObject, _type: c_int, handler: c_int, level: c_int);
82 #[cfg(not(any(PyPy, Py_3_11)))]
83 pub fn PyFrame_BlockPop(f: *mut PyFrameObject) -> *mut PyTryBlock;
84
85 pub fn PyFrame_LocalsToFast(f: *mut PyFrameObject, clear: c_int);
86 pub fn PyFrame_FastToLocalsWithError(f: *mut PyFrameObject) -> c_int;
87 pub fn PyFrame_FastToLocals(f: *mut PyFrameObject);
88
89 // skipped _PyFrame_DebugMallocStats
90 // skipped PyFrame_GetBack
91
92 #[cfg(not(Py_3_9))]
93 pub fn PyFrame_ClearFreeList() -> c_int;
94}
95