blob: 8ffd15646f084e2aae375e2638d5abe7325e92f3 [file] [log] [blame]
Olivier Deprezf4ef2d02021-04-20 13:36:24 +02001
2/* Generator object interface */
3
4#ifndef Py_LIMITED_API
5#ifndef Py_GENOBJECT_H
6#define Py_GENOBJECT_H
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11#include "pystate.h" /* _PyErr_StackItem */
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 PyFrameObject *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 _PyErr_StackItem prefix##_exc_state;
30
31typedef struct {
32 /* The gi_ prefix is intended to remind of generator-iterator. */
33 _PyGenObject_HEAD(gi)
34} PyGenObject;
35
36PyAPI_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
41PyAPI_FUNC(PyObject *) PyGen_New(PyFrameObject *);
42PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(PyFrameObject *,
43 PyObject *name, PyObject *qualname);
44PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *);
45PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);
46PyAPI_FUNC(PyObject *) _PyGen_Send(PyGenObject *, PyObject *);
47PyObject *_PyGen_yf(PyGenObject *);
48PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self);
49
50#ifndef Py_LIMITED_API
51typedef struct {
52 _PyGenObject_HEAD(cr)
53 PyObject *cr_origin;
54} PyCoroObject;
55
56PyAPI_DATA(PyTypeObject) PyCoro_Type;
57PyAPI_DATA(PyTypeObject) _PyCoroWrapper_Type;
58
59#define PyCoro_CheckExact(op) Py_IS_TYPE(op, &PyCoro_Type)
60PyObject *_PyCoro_GetAwaitableIter(PyObject *o);
61PyAPI_FUNC(PyObject *) PyCoro_New(PyFrameObject *,
62 PyObject *name, PyObject *qualname);
63
64/* Asynchronous Generators */
65
66typedef struct {
67 _PyGenObject_HEAD(ag)
68 PyObject *ag_finalizer;
69
70 /* Flag is set to 1 when hooks set up by sys.set_asyncgen_hooks
71 were called on the generator, to avoid calling them more
72 than once. */
73 int ag_hooks_inited;
74
75 /* Flag is set to 1 when aclose() is called for the first time, or
76 when a StopAsyncIteration exception is raised. */
77 int ag_closed;
78
79 int ag_running_async;
80} PyAsyncGenObject;
81
82PyAPI_DATA(PyTypeObject) PyAsyncGen_Type;
83PyAPI_DATA(PyTypeObject) _PyAsyncGenASend_Type;
84PyAPI_DATA(PyTypeObject) _PyAsyncGenWrappedValue_Type;
85PyAPI_DATA(PyTypeObject) _PyAsyncGenAThrow_Type;
86
87PyAPI_FUNC(PyObject *) PyAsyncGen_New(PyFrameObject *,
88 PyObject *name, PyObject *qualname);
89
90#define PyAsyncGen_CheckExact(op) Py_IS_TYPE(op, &PyAsyncGen_Type)
91
92PyObject *_PyAsyncGenValueWrapperNew(PyObject *);
93
94#endif
95
96#undef _PyGenObject_HEAD
97
98#ifdef __cplusplus
99}
100#endif
101#endif /* !Py_GENOBJECT_H */
102#endif /* Py_LIMITED_API */