genobject.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* Generator object interface */
  2. #ifndef Py_LIMITED_API
  3. #ifndef Py_GENOBJECT_H
  4. #define Py_GENOBJECT_H
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. #include "pystate.h" /* _PyErr_StackItem */
  9. struct _frame; /* Avoid including frameobject.h */
  10. /* _PyGenObject_HEAD defines the initial segment of generator
  11. and coroutine objects. */
  12. #define _PyGenObject_HEAD(prefix) \
  13. PyObject_HEAD \
  14. /* Note: gi_frame can be NULL if the generator is "finished" */ \
  15. struct _frame *prefix##_frame; \
  16. /* True if generator is being executed. */ \
  17. char prefix##_running; \
  18. /* The code object backing the generator */ \
  19. PyObject *prefix##_code; \
  20. /* List of weak reference. */ \
  21. PyObject *prefix##_weakreflist; \
  22. /* Name of the generator. */ \
  23. PyObject *prefix##_name; \
  24. /* Qualified name of the generator. */ \
  25. PyObject *prefix##_qualname; \
  26. _PyErr_StackItem prefix##_exc_state;
  27. typedef struct {
  28. /* The gi_ prefix is intended to remind of generator-iterator. */
  29. _PyGenObject_HEAD(gi)
  30. } PyGenObject;
  31. PyAPI_DATA(PyTypeObject) PyGen_Type;
  32. #define PyGen_Check(op) PyObject_TypeCheck(op, &PyGen_Type)
  33. #define PyGen_CheckExact(op) (Py_TYPE(op) == &PyGen_Type)
  34. PyAPI_FUNC(PyObject *) PyGen_New(struct _frame *);
  35. PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(struct _frame *,
  36. PyObject *name, PyObject *qualname);
  37. PyAPI_FUNC(int) PyGen_NeedsFinalizing(PyGenObject *);
  38. PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *);
  39. PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);
  40. PyAPI_FUNC(PyObject *) _PyGen_Send(PyGenObject *, PyObject *);
  41. PyObject *_PyGen_yf(PyGenObject *);
  42. PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self);
  43. #ifndef Py_LIMITED_API
  44. typedef struct {
  45. _PyGenObject_HEAD(cr)
  46. PyObject *cr_origin;
  47. } PyCoroObject;
  48. PyAPI_DATA(PyTypeObject) PyCoro_Type;
  49. PyAPI_DATA(PyTypeObject) _PyCoroWrapper_Type;
  50. PyAPI_DATA(PyTypeObject) _PyAIterWrapper_Type;
  51. #define PyCoro_CheckExact(op) (Py_TYPE(op) == &PyCoro_Type)
  52. PyObject *_PyCoro_GetAwaitableIter(PyObject *o);
  53. PyAPI_FUNC(PyObject *) PyCoro_New(struct _frame *,
  54. PyObject *name, PyObject *qualname);
  55. /* Asynchronous Generators */
  56. typedef struct {
  57. _PyGenObject_HEAD(ag)
  58. PyObject *ag_finalizer;
  59. /* Flag is set to 1 when hooks set up by sys.set_asyncgen_hooks
  60. were called on the generator, to avoid calling them more
  61. than once. */
  62. int ag_hooks_inited;
  63. /* Flag is set to 1 when aclose() is called for the first time, or
  64. when a StopAsyncIteration exception is raised. */
  65. int ag_closed;
  66. int ag_running_async;
  67. } PyAsyncGenObject;
  68. PyAPI_DATA(PyTypeObject) PyAsyncGen_Type;
  69. PyAPI_DATA(PyTypeObject) _PyAsyncGenASend_Type;
  70. PyAPI_DATA(PyTypeObject) _PyAsyncGenWrappedValue_Type;
  71. PyAPI_DATA(PyTypeObject) _PyAsyncGenAThrow_Type;
  72. PyAPI_FUNC(PyObject *) PyAsyncGen_New(struct _frame *,
  73. PyObject *name, PyObject *qualname);
  74. #define PyAsyncGen_CheckExact(op) (Py_TYPE(op) == &PyAsyncGen_Type)
  75. PyObject *_PyAsyncGenValueWrapperNew(PyObject *);
  76. int PyAsyncGen_ClearFreeLists(void);
  77. #endif
  78. #undef _PyGenObject_HEAD
  79. #ifdef __cplusplus
  80. }
  81. #endif
  82. #endif /* !Py_GENOBJECT_H */
  83. #endif /* Py_LIMITED_API */