• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Frame object interface */
2 
3 #ifndef Py_CPYTHON_FRAMEOBJECT_H
4 #  error "this header file must not be included directly"
5 #endif
6 
7 /* These values are chosen so that the inline functions below all
8  * compare f_state to zero.
9  */
10 enum _framestate {
11     FRAME_CREATED = -2,
12     FRAME_SUSPENDED = -1,
13     FRAME_EXECUTING = 0,
14     FRAME_RETURNED = 1,
15     FRAME_UNWINDING = 2,
16     FRAME_RAISED = 3,
17     FRAME_CLEARED = 4
18 };
19 
20 typedef signed char PyFrameState;
21 
22 typedef struct {
23     int b_type;                 /* what kind of block this is */
24     int b_handler;              /* where to jump to find handler */
25     int b_level;                /* value stack level to pop to */
26 } PyTryBlock;
27 
28 struct _frame {
29     PyObject_VAR_HEAD
30     struct _frame *f_back;      /* previous frame, or NULL */
31     PyCodeObject *f_code;       /* code segment */
32     PyObject *f_builtins;       /* builtin symbol table (PyDictObject) */
33     PyObject *f_globals;        /* global symbol table (PyDictObject) */
34     PyObject *f_locals;         /* local symbol table (any mapping) */
35     PyObject **f_valuestack;    /* points after the last local */
36     PyObject *f_trace;          /* Trace function */
37     int f_stackdepth;           /* Depth of value stack */
38     char f_trace_lines;         /* Emit per-line trace events? */
39     char f_trace_opcodes;       /* Emit per-opcode trace events? */
40 
41     /* Borrowed reference to a generator, or NULL */
42     PyObject *f_gen;
43 
44     int f_lasti;                /* Last instruction if called */
45     int f_lineno;               /* Current line number. Only valid if non-zero */
46     int f_iblock;               /* index in f_blockstack */
47     PyFrameState f_state;       /* What state the frame is in */
48     PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */
49     PyObject *f_localsplus[1];  /* locals+stack, dynamically sized */
50 };
51 
_PyFrame_IsRunnable(struct _frame * f)52 static inline int _PyFrame_IsRunnable(struct _frame *f) {
53     return f->f_state < FRAME_EXECUTING;
54 }
55 
_PyFrame_IsExecuting(struct _frame * f)56 static inline int _PyFrame_IsExecuting(struct _frame *f) {
57     return f->f_state == FRAME_EXECUTING;
58 }
59 
_PyFrameHasCompleted(struct _frame * f)60 static inline int _PyFrameHasCompleted(struct _frame *f) {
61     return f->f_state > FRAME_EXECUTING;
62 }
63 
64 /* Standard object interface */
65 
66 PyAPI_DATA(PyTypeObject) PyFrame_Type;
67 
68 #define PyFrame_Check(op) Py_IS_TYPE(op, &PyFrame_Type)
69 
70 PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
71                                         PyObject *, PyObject *);
72 
73 /* only internal use */
74 PyFrameObject*
75 _PyFrame_New_NoTrack(PyThreadState *, PyFrameConstructor *, PyObject *);
76 
77 
78 /* The rest of the interface is specific for frame objects */
79 
80 /* Block management functions */
81 
82 PyAPI_FUNC(void) PyFrame_BlockSetup(PyFrameObject *, int, int, int);
83 PyAPI_FUNC(PyTryBlock *) PyFrame_BlockPop(PyFrameObject *);
84 
85 /* Conversions between "fast locals" and locals in dictionary */
86 
87 PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int);
88 
89 PyAPI_FUNC(int) PyFrame_FastToLocalsWithError(PyFrameObject *f);
90 PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
91 
92 PyAPI_FUNC(void) _PyFrame_DebugMallocStats(FILE *out);
93 
94 PyAPI_FUNC(PyFrameObject *) PyFrame_GetBack(PyFrameObject *frame);
95