genobject.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /* --- Generators --------------------------------------------------------- */
  9. /* _PyGenObject_HEAD defines the initial segment of generator
  10. and coroutine objects. */
  11. #define _PyGenObject_HEAD(prefix) \
  12. PyObject_HEAD \
  13. /* List of weak reference. */ \
  14. PyObject *prefix##_weakreflist; \
  15. /* Name of the generator. */ \
  16. PyObject *prefix##_name; \
  17. /* Qualified name of the generator. */ \
  18. PyObject *prefix##_qualname; \
  19. _PyErr_StackItem prefix##_exc_state; \
  20. PyObject *prefix##_origin_or_finalizer; \
  21. char prefix##_hooks_inited; \
  22. char prefix##_closed; \
  23. char prefix##_running_async; \
  24. /* The frame */ \
  25. int8_t prefix##_frame_state; \
  26. PyObject *prefix##_iframe[1]; \
  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_IS_TYPE((op), &PyGen_Type)
  34. PyAPI_FUNC(PyObject *) PyGen_New(PyFrameObject *);
  35. PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(PyFrameObject *,
  36. PyObject *name, PyObject *qualname);
  37. PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *);
  38. PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);
  39. PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self);
  40. PyAPI_FUNC(PyCodeObject *) PyGen_GetCode(PyGenObject *gen);
  41. /* --- PyCoroObject ------------------------------------------------------- */
  42. typedef struct {
  43. _PyGenObject_HEAD(cr)
  44. } PyCoroObject;
  45. PyAPI_DATA(PyTypeObject) PyCoro_Type;
  46. PyAPI_DATA(PyTypeObject) _PyCoroWrapper_Type;
  47. #define PyCoro_CheckExact(op) Py_IS_TYPE((op), &PyCoro_Type)
  48. PyAPI_FUNC(PyObject *) PyCoro_New(PyFrameObject *,
  49. PyObject *name, PyObject *qualname);
  50. /* --- Asynchronous Generators -------------------------------------------- */
  51. typedef struct {
  52. _PyGenObject_HEAD(ag)
  53. } PyAsyncGenObject;
  54. PyAPI_DATA(PyTypeObject) PyAsyncGen_Type;
  55. PyAPI_DATA(PyTypeObject) _PyAsyncGenASend_Type;
  56. PyAPI_DATA(PyTypeObject) _PyAsyncGenWrappedValue_Type;
  57. PyAPI_DATA(PyTypeObject) _PyAsyncGenAThrow_Type;
  58. PyAPI_FUNC(PyObject *) PyAsyncGen_New(PyFrameObject *,
  59. PyObject *name, PyObject *qualname);
  60. #define PyAsyncGen_CheckExact(op) Py_IS_TYPE((op), &PyAsyncGen_Type)
  61. #define PyAsyncGenASend_CheckExact(op) Py_IS_TYPE((op), &_PyAsyncGenASend_Type)
  62. #undef _PyGenObject_HEAD
  63. #ifdef __cplusplus
  64. }
  65. #endif
  66. #endif /* !Py_GENOBJECT_H */
  67. #endif /* Py_LIMITED_API */