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 | #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 | |
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_IS_TYPE(op, &PyGen_Type) |
39 | |
40 | PyAPI_FUNC(PyObject *) PyGen_New(PyFrameObject *); |
41 | PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(PyFrameObject *, |
42 | PyObject *name, PyObject *qualname); |
43 | PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *); |
44 | PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **); |
45 | PyObject *_PyGen_yf(PyGenObject *); |
46 | PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self); |
47 | |
48 | #ifndef Py_LIMITED_API |
49 | typedef struct { |
50 | _PyGenObject_HEAD(cr) |
51 | PyObject *cr_origin; |
52 | } PyCoroObject; |
53 | |
54 | PyAPI_DATA(PyTypeObject) PyCoro_Type; |
55 | PyAPI_DATA(PyTypeObject) _PyCoroWrapper_Type; |
56 | |
57 | #define PyCoro_CheckExact(op) Py_IS_TYPE(op, &PyCoro_Type) |
58 | PyObject *_PyCoro_GetAwaitableIter(PyObject *o); |
59 | PyAPI_FUNC(PyObject *) PyCoro_New(PyFrameObject *, |
60 | PyObject *name, PyObject *qualname); |
61 | |
62 | /* Asynchronous Generators */ |
63 | |
64 | typedef 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 | |
80 | PyAPI_DATA(PyTypeObject) PyAsyncGen_Type; |
81 | PyAPI_DATA(PyTypeObject) _PyAsyncGenASend_Type; |
82 | PyAPI_DATA(PyTypeObject) _PyAsyncGenWrappedValue_Type; |
83 | PyAPI_DATA(PyTypeObject) _PyAsyncGenAThrow_Type; |
84 | |
85 | PyAPI_FUNC(PyObject *) PyAsyncGen_New(PyFrameObject *, |
86 | PyObject *name, PyObject *qualname); |
87 | |
88 | #define PyAsyncGen_CheckExact(op) Py_IS_TYPE(op, &PyAsyncGen_Type) |
89 | |
90 | PyObject *_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 | |