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