frameobject.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Frame object interface */
  2. #ifndef Py_FRAMEOBJECT_H
  3. #define Py_FRAMEOBJECT_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  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. typedef struct _frame {
  13. PyObject_VAR_HEAD
  14. struct _frame *f_back; /* previous frame, or NULL */
  15. PyCodeObject *f_code; /* code segment */
  16. PyObject *f_builtins; /* builtin symbol table (PyDictObject) */
  17. PyObject *f_globals; /* global symbol table (PyDictObject) */
  18. PyObject *f_locals; /* local symbol table (any mapping) */
  19. PyObject **f_valuestack; /* points after the last local */
  20. /* Next free slot in f_valuestack. Frame creation sets to f_valuestack.
  21. Frame evaluation usually NULLs it, but a frame that yields sets it
  22. to the current stack top. */
  23. PyObject **f_stacktop;
  24. PyObject *f_trace; /* Trace function */
  25. /* If an exception is raised in this frame, the next three are used to
  26. * record the exception info (if any) originally in the thread state. See
  27. * comments before set_exc_info() -- it's not obvious.
  28. * Invariant: if _type is NULL, then so are _value and _traceback.
  29. * Desired invariant: all three are NULL, or all three are non-NULL. That
  30. * one isn't currently true, but "should be".
  31. */
  32. PyObject *f_exc_type, *f_exc_value, *f_exc_traceback;
  33. PyThreadState *f_tstate;
  34. int f_lasti; /* Last instruction if called */
  35. /* Call PyFrame_GetLineNumber() instead of reading this field
  36. directly. As of 2.3 f_lineno is only valid when tracing is
  37. active (i.e. when f_trace is set). At other times we use
  38. PyCode_Addr2Line to calculate the line from the current
  39. bytecode index. */
  40. int f_lineno; /* Current line number */
  41. int f_iblock; /* index in f_blockstack */
  42. PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */
  43. PyObject *f_localsplus[1]; /* locals+stack, dynamically sized */
  44. } PyFrameObject;
  45. /* Standard object interface */
  46. PyAPI_DATA(PyTypeObject) PyFrame_Type;
  47. #define PyFrame_Check(op) ((op)->ob_type == &PyFrame_Type)
  48. #define PyFrame_IsRestricted(f) \
  49. ((f)->f_builtins != (f)->f_tstate->interp->builtins)
  50. PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
  51. PyObject *, PyObject *);
  52. /* The rest of the interface is specific for frame objects */
  53. /* Block management functions */
  54. PyAPI_FUNC(void) PyFrame_BlockSetup(PyFrameObject *, int, int, int);
  55. PyAPI_FUNC(PyTryBlock *) PyFrame_BlockPop(PyFrameObject *);
  56. /* Extend the value stack */
  57. PyAPI_FUNC(PyObject **) PyFrame_ExtendStack(PyFrameObject *, int, int);
  58. /* Conversions between "fast locals" and locals in dictionary */
  59. PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int);
  60. PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
  61. PyAPI_FUNC(int) PyFrame_ClearFreeList(void);
  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 */