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

source code of include/python3.10/genobject.h