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     /* The code object backing the generator */                             \
17     PyCodeObject *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     PyObject *prefix##_origin_or_finalizer;                                 \
26     char prefix##_hooks_inited;                                             \
27     char prefix##_closed;                                                   \
28     char prefix##_running_async;                                            \
29     /* The frame */                                                         \
30     int8_t prefix##_frame_state;                                            \
31     PyObject *prefix##_iframe[1];
32 
33 typedef struct {
34     /* The gi_ prefix is intended to remind of generator-iterator. */
35     _PyGenObject_HEAD(gi)
36 } PyGenObject;
37 
38 PyAPI_DATA(PyTypeObject) PyGen_Type;
39 
40 #define PyGen_Check(op) PyObject_TypeCheck(op, &PyGen_Type)
41 #define PyGen_CheckExact(op) Py_IS_TYPE(op, &PyGen_Type)
42 
43 PyAPI_FUNC(PyObject *) PyGen_New(PyFrameObject *);
44 PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(PyFrameObject *,
45     PyObject *name, PyObject *qualname);
46 PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *);
47 PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);
48 PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self);
49 
50 
51 /* --- PyCoroObject ------------------------------------------------------- */
52 
53 typedef struct {
54     _PyGenObject_HEAD(cr)
55 } PyCoroObject;
56 
57 PyAPI_DATA(PyTypeObject) PyCoro_Type;
58 PyAPI_DATA(PyTypeObject) _PyCoroWrapper_Type;
59 
60 #define PyCoro_CheckExact(op) Py_IS_TYPE(op, &PyCoro_Type)
61 PyAPI_FUNC(PyObject *) PyCoro_New(PyFrameObject *,
62     PyObject *name, PyObject *qualname);
63 
64 
65 /* --- Asynchronous Generators -------------------------------------------- */
66 
67 typedef struct {
68     _PyGenObject_HEAD(ag)
69 } PyAsyncGenObject;
70 
71 PyAPI_DATA(PyTypeObject) PyAsyncGen_Type;
72 PyAPI_DATA(PyTypeObject) _PyAsyncGenASend_Type;
73 PyAPI_DATA(PyTypeObject) _PyAsyncGenWrappedValue_Type;
74 PyAPI_DATA(PyTypeObject) _PyAsyncGenAThrow_Type;
75 
76 PyAPI_FUNC(PyObject *) PyAsyncGen_New(PyFrameObject *,
77     PyObject *name, PyObject *qualname);
78 
79 #define PyAsyncGen_CheckExact(op) Py_IS_TYPE(op, &PyAsyncGen_Type)
80 
81 
82 #undef _PyGenObject_HEAD
83 
84 #ifdef __cplusplus
85 }
86 #endif
87 #endif /* !Py_GENOBJECT_H */
88 #endif /* Py_LIMITED_API */
89