1 /* Generator object interface */
2
3 #ifndef Py_LIMITED_API
4 #ifndef Py_GENOBJECT_H
5 #define Py_GENOBJECT_H
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9
10 /* --- Generators --------------------------------------------------------- */
11
12 /* _PyGenObject_HEAD defines the initial segment of generator
13 and coroutine objects. */
14 #define _PyGenObject_HEAD(prefix) \
15 PyObject_HEAD \
16 /* List of weak reference. */ \
17 PyObject *prefix##_weakreflist; \
18 /* Name of the generator. */ \
19 PyObject *prefix##_name; \
20 /* Qualified name of the generator. */ \
21 PyObject *prefix##_qualname; \
22 _PyErr_StackItem prefix##_exc_state; \
23 PyObject *prefix##_origin_or_finalizer; \
24 char prefix##_hooks_inited; \
25 char prefix##_closed; \
26 char prefix##_running_async; \
27 /* The frame */ \
28 int8_t prefix##_frame_state; \
29 PyObject *prefix##_iframe[1]; \
30
31 typedef struct {
32 /* The gi_ prefix is intended to remind of generator-iterator. */
33 _PyGenObject_HEAD(gi)
34 } PyGenObject;
35
36 PyAPI_DATA(PyTypeObject) PyGen_Type;
37
38 #define PyGen_Check(op) PyObject_TypeCheck((op), &PyGen_Type)
39 #define PyGen_CheckExact(op) Py_IS_TYPE((op), &PyGen_Type)
40
41 PyAPI_FUNC(PyObject *) PyGen_New(PyFrameObject *);
42 PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(PyFrameObject *,
43 PyObject *name, PyObject *qualname);
44 PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *);
45 PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);
46 PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self);
47 PyAPI_FUNC(PyCodeObject *) PyGen_GetCode(PyGenObject *gen);
48
49
50 /* --- PyCoroObject ------------------------------------------------------- */
51
52 typedef struct {
53 _PyGenObject_HEAD(cr)
54 } PyCoroObject;
55
56 PyAPI_DATA(PyTypeObject) PyCoro_Type;
57 PyAPI_DATA(PyTypeObject) _PyCoroWrapper_Type;
58
59 #define PyCoro_CheckExact(op) Py_IS_TYPE((op), &PyCoro_Type)
60 PyAPI_FUNC(PyObject *) PyCoro_New(PyFrameObject *,
61 PyObject *name, PyObject *qualname);
62
63
64 /* --- Asynchronous Generators -------------------------------------------- */
65
66 typedef struct {
67 _PyGenObject_HEAD(ag)
68 } PyAsyncGenObject;
69
70 PyAPI_DATA(PyTypeObject) PyAsyncGen_Type;
71 PyAPI_DATA(PyTypeObject) _PyAsyncGenASend_Type;
72 PyAPI_DATA(PyTypeObject) _PyAsyncGenWrappedValue_Type;
73 PyAPI_DATA(PyTypeObject) _PyAsyncGenAThrow_Type;
74
75 PyAPI_FUNC(PyObject *) PyAsyncGen_New(PyFrameObject *,
76 PyObject *name, PyObject *qualname);
77
78 #define PyAsyncGen_CheckExact(op) Py_IS_TYPE((op), &PyAsyncGen_Type)
79
80 #define PyAsyncGenASend_CheckExact(op) Py_IS_TYPE((op), &_PyAsyncGenASend_Type)
81
82
83 #undef _PyGenObject_HEAD
84
85 #ifdef __cplusplus
86 }
87 #endif
88 #endif /* !Py_GENOBJECT_H */
89 #endif /* Py_LIMITED_API */