genobject.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. /* _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. PyFrameObject *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_IS_TYPE(op, &PyGen_Type)
  33. PyAPI_FUNC(PyObject *) PyGen_New(PyFrameObject *);
  34. PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(PyFrameObject *,
  35. PyObject *name, PyObject *qualname);
  36. PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *);
  37. PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);
  38. PyAPI_FUNC(PyObject *) _PyGen_Send(PyGenObject *, PyObject *);
  39. PyObject *_PyGen_yf(PyGenObject *);
  40. PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self);
  41. #ifndef Py_LIMITED_API
  42. typedef struct {
  43. _PyGenObject_HEAD(cr)
  44. PyObject *cr_origin;
  45. } PyCoroObject;
  46. PyAPI_DATA(PyTypeObject) PyCoro_Type;
  47. PyAPI_DATA(PyTypeObject) _PyCoroWrapper_Type;
  48. #define PyCoro_CheckExact(op) Py_IS_TYPE(op, &PyCoro_Type)
  49. PyObject *_PyCoro_GetAwaitableIter(PyObject *o);
  50. PyAPI_FUNC(PyObject *) PyCoro_New(PyFrameObject *,
  51. PyObject *name, PyObject *qualname);
  52. /* Asynchronous Generators */
  53. typedef struct {
  54. _PyGenObject_HEAD(ag)
  55. PyObject *ag_finalizer;
  56. /* Flag is set to 1 when hooks set up by sys.set_asyncgen_hooks
  57. were called on the generator, to avoid calling them more
  58. than once. */
  59. int ag_hooks_inited;
  60. /* Flag is set to 1 when aclose() is called for the first time, or
  61. when a StopAsyncIteration exception is raised. */
  62. int ag_closed;
  63. int ag_running_async;
  64. } PyAsyncGenObject;
  65. PyAPI_DATA(PyTypeObject) PyAsyncGen_Type;
  66. PyAPI_DATA(PyTypeObject) _PyAsyncGenASend_Type;
  67. PyAPI_DATA(PyTypeObject) _PyAsyncGenWrappedValue_Type;
  68. PyAPI_DATA(PyTypeObject) _PyAsyncGenAThrow_Type;
  69. PyAPI_FUNC(PyObject *) PyAsyncGen_New(PyFrameObject *,
  70. PyObject *name, PyObject *qualname);
  71. #define PyAsyncGen_CheckExact(op) Py_IS_TYPE(op, &PyAsyncGen_Type)
  72. PyObject *_PyAsyncGenValueWrapperNew(PyObject *);
  73. #endif
  74. #undef _PyGenObject_HEAD
  75. #ifdef __cplusplus
  76. }
  77. #endif
  78. #endif /* !Py_GENOBJECT_H */
  79. #endif /* Py_LIMITED_API */