python27_sys/
frameobject.rs

1use libc::c_int;
2
3use crate::code::{PyCodeObject, CO_MAXBLOCKS};
4use crate::object::*;
5use crate::pyport::Py_ssize_t;
6use crate::pystate::PyThreadState;
7
8#[repr(C)]
9#[derive(Copy, Clone)]
10pub struct PyTryBlock {
11    pub b_type: c_int,
12    pub b_handler: c_int,
13    pub b_level: c_int,
14}
15
16#[repr(C)]
17#[derive(Copy, Clone)]
18pub struct PyFrameObject {
19    #[cfg(py_sys_config = "Py_TRACE_REFS")]
20    pub _ob_next: *mut PyObject,
21    #[cfg(py_sys_config = "Py_TRACE_REFS")]
22    pub _ob_prev: *mut PyObject,
23    pub ob_refcnt: Py_ssize_t,
24    pub ob_type: *mut PyTypeObject,
25    pub ob_size: Py_ssize_t,
26    pub f_back: *mut PyFrameObject,       /* previous frame, or NULL */
27    pub f_code: *mut PyCodeObject,        /* code segment */
28    pub f_builtins: *mut PyObject,        /* builtin symbol table (PyDictObject) */
29    pub f_globals: *mut PyObject,         /* global symbol table (PyDictObject) */
30    pub f_locals: *mut PyObject,          /* local symbol table (any mapping) */
31    pub f_valuestack: *mut *mut PyObject, /* points after the last local */
32    /* Next free slot in f_valuestack.  Frame creation sets to f_valuestack.
33    Frame evaluation usually NULLs it, but a frame that yields sets it
34    to the current stack top. */
35    pub f_stacktop: *mut *mut PyObject,
36    pub f_trace: *mut PyObject, /* Trace function */
37
38    pub f_exc_type: *mut PyObject,
39    pub f_exc_value: *mut PyObject,
40    pub f_exc_traceback: *mut PyObject,
41
42    pub f_tstate: *mut PyThreadState,
43
44    pub f_lasti: c_int, /* Last instruction if called */
45    /* Call PyFrame_GetLineNumber() instead of reading this field
46     directly.  As of 2.3 f_lineno is only valid when tracing is
47     active (i.e. when f_trace is set).  At other times we use
48     PyCode_Addr2Line to calculate the line from the current
49    bytecode index. */
50    pub f_lineno: c_int,                          /* Current line number */
51    pub f_iblock: c_int,                          /* index in f_blockstack */
52    pub f_blockstack: [PyTryBlock; CO_MAXBLOCKS], /* for try and loop blocks */
53    pub f_localsplus: [*mut PyObject; 1],         /* locals+stack, dynamically sized */
54}
55
56#[cfg_attr(windows, link(name = "pythonXY"))]
57extern "C" {
58    pub static mut PyFrame_Type: PyTypeObject;
59}
60
61#[inline]
62pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int {
63    ((*op).ob_type == &mut PyFrame_Type) as c_int
64}
65
66ignore! {
67    #[inline]
68    pub unsafe fn PyFrame_IsRestricted(f: *mut PyFrameObject) -> c_int {
69        ((*f).f_builtins != (*(*(*f).f_tstate).interp).builtins) as c_int
70    }
71}
72
73#[cfg_attr(windows, link(name = "pythonXY"))]
74extern "C" {
75    pub fn PyFrame_New(
76        tstate: *mut PyThreadState,
77        code: *mut PyCodeObject,
78        globals: *mut PyObject,
79        locals: *mut PyObject,
80    ) -> *mut PyFrameObject;
81
82    pub fn PyFrame_BlockSetup(
83        f: *mut PyFrameObject,
84        _type: c_int,
85        handler: c_int,
86        level: c_int,
87    ) -> ();
88    pub fn PyFrame_BlockPop(f: *mut PyFrameObject) -> *mut PyTryBlock;
89
90    pub fn PyFrame_LocalsToFast(f: *mut PyFrameObject, clear: c_int) -> ();
91    pub fn PyFrame_FastToLocals(f: *mut PyFrameObject) -> ();
92
93    pub fn PyFrame_ClearFreeList() -> c_int;
94    pub fn PyFrame_GetLineNumber(f: *mut PyFrameObject) -> c_int;
95}