1 2 /* Frame object interface */ 3 4 #ifndef Py_LIMITED_API 5 #ifndef Py_FRAMEOBJECT_H 6 #define Py_FRAMEOBJECT_H 7 #ifdef __cplusplus 8 extern "C" { 9 #endif 10 11 typedef struct { 12 int b_type; /* what kind of block this is */ 13 int b_handler; /* where to jump to find handler */ 14 int b_level; /* value stack level to pop to */ 15 } PyTryBlock; 16 17 typedef struct _frame { 18 PyObject_VAR_HEAD 19 struct _frame *f_back; /* previous frame, or NULL */ 20 PyCodeObject *f_code; /* code segment */ 21 PyObject *f_builtins; /* builtin symbol table (PyDictObject) */ 22 PyObject *f_globals; /* global symbol table (PyDictObject) */ 23 PyObject *f_locals; /* local symbol table (any mapping) */ 24 PyObject **f_valuestack; /* points after the last local */ 25 /* Next free slot in f_valuestack. Frame creation sets to f_valuestack. 26 Frame evaluation usually NULLs it, but a frame that yields sets it 27 to the current stack top. */ 28 PyObject **f_stacktop; 29 PyObject *f_trace; /* Trace function */ 30 31 /* In a generator, we need to be able to swap between the exception 32 state inside the generator and the exception state of the calling 33 frame (which shouldn't be impacted when the generator "yields" 34 from an except handler). 35 These three fields exist exactly for that, and are unused for 36 non-generator frames. See the save_exc_state and swap_exc_state 37 functions in ceval.c for details of their use. */ 38 PyObject *f_exc_type, *f_exc_value, *f_exc_traceback; 39 /* Borrowed reference to a generator, or NULL */ 40 PyObject *f_gen; 41 42 int f_lasti; /* Last instruction if called */ 43 /* Call PyFrame_GetLineNumber() instead of reading this field 44 directly. As of 2.3 f_lineno is only valid when tracing is 45 active (i.e. when f_trace is set). At other times we use 46 PyCode_Addr2Line to calculate the line from the current 47 bytecode index. */ 48 int f_lineno; /* Current line number */ 49 int f_iblock; /* index in f_blockstack */ 50 char f_executing; /* whether the frame is still executing */ 51 PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */ 52 PyObject *f_localsplus[1]; /* locals+stack, dynamically sized */ 53 } PyFrameObject; 54 55 56 /* Standard object interface */ 57 58 PyAPI_DATA(PyTypeObject) PyFrame_Type; 59 60 #define PyFrame_Check(op) (Py_TYPE(op) == &PyFrame_Type) 61 62 PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *, 63 PyObject *, PyObject *); 64 65 66 /* The rest of the interface is specific for frame objects */ 67 68 /* Block management functions */ 69 70 PyAPI_FUNC(void) PyFrame_BlockSetup(PyFrameObject *, int, int, int); 71 PyAPI_FUNC(PyTryBlock *) PyFrame_BlockPop(PyFrameObject *); 72 73 /* Extend the value stack */ 74 75 PyAPI_FUNC(PyObject **) PyFrame_ExtendStack(PyFrameObject *, int, int); 76 77 /* Conversions between "fast locals" and locals in dictionary */ 78 79 PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int); 80 81 PyAPI_FUNC(int) PyFrame_FastToLocalsWithError(PyFrameObject *f); 82 PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *); 83 84 PyAPI_FUNC(int) PyFrame_ClearFreeList(void); 85 86 PyAPI_FUNC(void) _PyFrame_DebugMallocStats(FILE *out); 87 88 /* Return the line of code the frame is currently executing. */ 89 PyAPI_FUNC(int) PyFrame_GetLineNumber(PyFrameObject *); 90 91 #ifdef __cplusplus 92 } 93 #endif 94 #endif /* !Py_FRAMEOBJECT_H */ 95 #endif /* Py_LIMITED_API */ 96