genobject.h 3.6 KB

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