genobject.h 3.3 KB

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