pyo3_ffi/cpython/
frameobject.rs

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