Nick Coghlan | 1e420f8 | 2020-01-21 08:21:35 +1000 | [diff] [blame] | 1 | /* Frame object interface */ |
| 2 | |
| 3 | #ifndef Py_CPYTHON_FRAMEOBJECT_H |
| 4 | # error "this header file must not be included directly" |
| 5 | #endif |
| 6 | |
Nick Coghlan | 1e420f8 | 2020-01-21 08:21:35 +1000 | [diff] [blame] | 7 | typedef struct { |
| 8 | int b_type; /* what kind of block this is */ |
| 9 | int b_handler; /* where to jump to find handler */ |
| 10 | int b_level; /* value stack level to pop to */ |
| 11 | } PyTryBlock; |
| 12 | |
Victor Stinner | 7c59d7c | 2020-04-28 16:32:48 +0200 | [diff] [blame] | 13 | struct _frame { |
Nick Coghlan | 1e420f8 | 2020-01-21 08:21:35 +1000 | [diff] [blame] | 14 | PyObject_VAR_HEAD |
| 15 | struct _frame *f_back; /* previous frame, or NULL */ |
| 16 | PyCodeObject *f_code; /* code segment */ |
| 17 | PyObject *f_builtins; /* builtin symbol table (PyDictObject) */ |
| 18 | PyObject *f_globals; /* global symbol table (PyDictObject) */ |
| 19 | PyObject *f_locals; /* local symbol table (any mapping) */ |
| 20 | PyObject **f_valuestack; /* points after the last local */ |
| 21 | /* Next free slot in f_valuestack. Frame creation sets to f_valuestack. |
| 22 | Frame evaluation usually NULLs it, but a frame that yields sets it |
| 23 | to the current stack top. */ |
| 24 | PyObject **f_stacktop; |
| 25 | PyObject *f_trace; /* Trace function */ |
| 26 | char f_trace_lines; /* Emit per-line trace events? */ |
| 27 | char f_trace_opcodes; /* Emit per-opcode trace events? */ |
| 28 | |
| 29 | /* Borrowed reference to a generator, or NULL */ |
| 30 | PyObject *f_gen; |
| 31 | |
| 32 | int f_lasti; /* Last instruction if called */ |
| 33 | /* Call PyFrame_GetLineNumber() instead of reading this field |
| 34 | directly. As of 2.3 f_lineno is only valid when tracing is |
| 35 | active (i.e. when f_trace is set). At other times we use |
| 36 | PyCode_Addr2Line to calculate the line from the current |
| 37 | bytecode index. */ |
| 38 | int f_lineno; /* Current line number */ |
| 39 | int f_iblock; /* index in f_blockstack */ |
| 40 | char f_executing; /* whether the frame is still executing */ |
| 41 | PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */ |
| 42 | PyObject *f_localsplus[1]; /* locals+stack, dynamically sized */ |
Victor Stinner | 7c59d7c | 2020-04-28 16:32:48 +0200 | [diff] [blame] | 43 | }; |
Nick Coghlan | 1e420f8 | 2020-01-21 08:21:35 +1000 | [diff] [blame] | 44 | |
| 45 | |
| 46 | /* Standard object interface */ |
| 47 | |
| 48 | PyAPI_DATA(PyTypeObject) PyFrame_Type; |
| 49 | |
Dong-hee Na | 1b55b65 | 2020-02-17 19:09:15 +0900 | [diff] [blame] | 50 | #define PyFrame_Check(op) Py_IS_TYPE(op, &PyFrame_Type) |
Nick Coghlan | 1e420f8 | 2020-01-21 08:21:35 +1000 | [diff] [blame] | 51 | |
| 52 | PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *, |
| 53 | PyObject *, PyObject *); |
| 54 | |
| 55 | /* only internal use */ |
| 56 | PyFrameObject* _PyFrame_New_NoTrack(PyThreadState *, PyCodeObject *, |
| 57 | PyObject *, PyObject *); |
| 58 | |
| 59 | |
| 60 | /* The rest of the interface is specific for frame objects */ |
| 61 | |
| 62 | /* Block management functions */ |
| 63 | |
| 64 | PyAPI_FUNC(void) PyFrame_BlockSetup(PyFrameObject *, int, int, int); |
| 65 | PyAPI_FUNC(PyTryBlock *) PyFrame_BlockPop(PyFrameObject *); |
| 66 | |
| 67 | /* Conversions between "fast locals" and locals in dictionary */ |
| 68 | |
| 69 | PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int); |
| 70 | |
| 71 | PyAPI_FUNC(int) PyFrame_FastToLocalsWithError(PyFrameObject *f); |
| 72 | PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *); |
| 73 | |
Nick Coghlan | 1e420f8 | 2020-01-21 08:21:35 +1000 | [diff] [blame] | 74 | PyAPI_FUNC(void) _PyFrame_DebugMallocStats(FILE *out); |
| 75 | |
Victor Stinner | 7036477 | 2020-04-29 03:28:46 +0200 | [diff] [blame] | 76 | PyAPI_FUNC(PyFrameObject *) PyFrame_GetBack(PyFrameObject *frame); |