genobject.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. 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_TYPE(op) == &PyGen_Type)
  32. PyAPI_FUNC(PyObject *) PyGen_New(struct _frame *);
  33. PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(struct _frame *,
  34. PyObject *name, PyObject *qualname);
  35. PyAPI_FUNC(int) PyGen_NeedsFinalizing(PyGenObject *);
  36. PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);
  37. PyObject *_PyGen_Send(PyGenObject *, PyObject *);
  38. PyObject *_PyGen_yf(PyGenObject *);
  39. PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self);
  40. #ifndef Py_LIMITED_API
  41. typedef struct {
  42. _PyGenObject_HEAD(cr)
  43. } PyCoroObject;
  44. PyAPI_DATA(PyTypeObject) PyCoro_Type;
  45. PyAPI_DATA(PyTypeObject) _PyCoroWrapper_Type;
  46. PyAPI_DATA(PyTypeObject) _PyAIterWrapper_Type;
  47. PyObject *_PyAIterWrapper_New(PyObject *aiter);
  48. #define PyCoro_CheckExact(op) (Py_TYPE(op) == &PyCoro_Type)
  49. PyObject *_PyCoro_GetAwaitableIter(PyObject *o);
  50. PyAPI_FUNC(PyObject *) PyCoro_New(struct _frame *,
  51. PyObject *name, PyObject *qualname);
  52. #endif
  53. #undef _PyGenObject_HEAD
  54. #ifdef __cplusplus
  55. }
  56. #endif
  57. #endif /* !Py_GENOBJECT_H */
  58. #endif /* Py_LIMITED_API */