frameobject.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* Frame object interface */
  2. #ifndef Py_LIMITED_API
  3. #ifndef Py_FRAMEOBJECT_H
  4. #define Py_FRAMEOBJECT_H
  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. typedef 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. } PyFrameObject;
  42. /* Standard object interface */
  43. PyAPI_DATA(PyTypeObject) PyFrame_Type;
  44. #define PyFrame_Check(op) (Py_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. /* Extend the value stack */
  55. PyAPI_FUNC(PyObject **) PyFrame_ExtendStack(PyFrameObject *, int, int);
  56. /* Conversions between "fast locals" and locals in dictionary */
  57. PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int);
  58. PyAPI_FUNC(int) PyFrame_FastToLocalsWithError(PyFrameObject *f);
  59. PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
  60. PyAPI_FUNC(int) PyFrame_ClearFreeList(void);
  61. PyAPI_FUNC(void) _PyFrame_DebugMallocStats(FILE *out);
  62. /* Return the line of code the frame is currently executing. */
  63. PyAPI_FUNC(int) PyFrame_GetLineNumber(PyFrameObject *);
  64. #ifdef __cplusplus
  65. }
  66. #endif
  67. #endif /* !Py_FRAMEOBJECT_H */
  68. #endif /* Py_LIMITED_API */