frameobject.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Frame object interface */
  2. #ifndef Py_CPYTHON_FRAMEOBJECT_H
  3. # error "this header file must not be included directly"
  4. #endif
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. typedef struct {
  9. int b_type; /* what kind of block this is */
  10. int b_handler; /* where to jump to find handler */
  11. int b_level; /* value stack level to pop to */
  12. } PyTryBlock;
  13. struct _frame {
  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. /* Borrowed reference to a generator, or NULL */
  29. PyObject *f_gen;
  30. int f_lasti; /* Last instruction if called */
  31. /* Call PyFrame_GetLineNumber() instead of reading this field
  32. directly. As of 2.3 f_lineno is only valid when tracing is
  33. active (i.e. when f_trace is set). At other times we use
  34. PyCode_Addr2Line to calculate the line from the current
  35. bytecode index. */
  36. int f_lineno; /* Current line number */
  37. int f_iblock; /* index in f_blockstack */
  38. char f_executing; /* whether the frame is still executing */
  39. PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */
  40. PyObject *f_localsplus[1]; /* locals+stack, dynamically sized */
  41. };
  42. /* Standard object interface */
  43. PyAPI_DATA(PyTypeObject) PyFrame_Type;
  44. #define PyFrame_Check(op) Py_IS_TYPE(op, &PyFrame_Type)
  45. PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
  46. PyObject *, PyObject *);
  47. /* only internal use */
  48. PyFrameObject* _PyFrame_New_NoTrack(PyThreadState *, PyCodeObject *,
  49. PyObject *, PyObject *);
  50. /* The rest of the interface is specific for frame objects */
  51. /* Block management functions */
  52. PyAPI_FUNC(void) PyFrame_BlockSetup(PyFrameObject *, int, int, int);
  53. PyAPI_FUNC(PyTryBlock *) PyFrame_BlockPop(PyFrameObject *);
  54. /* Conversions between "fast locals" and locals in dictionary */
  55. PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int);
  56. PyAPI_FUNC(int) PyFrame_FastToLocalsWithError(PyFrameObject *f);
  57. PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
  58. PyAPI_FUNC(void) _PyFrame_DebugMallocStats(FILE *out);
  59. PyAPI_FUNC(PyFrameObject *) PyFrame_GetBack(PyFrameObject *frame);
  60. #ifdef __cplusplus
  61. }
  62. #endif