Haibo Huang | d883030 | 2020-03-03 10:09:46 -0800 | [diff] [blame] | 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 */ |
Yi Kong | 7119932 | 2022-08-30 15:53:45 +0800 | [diff] [blame] | 12 | #include "abstract.h" /* PySendResult */ |
Haibo Huang | d883030 | 2020-03-03 10:09:46 -0800 | [diff] [blame] | 13 | |
Haibo Huang | d883030 | 2020-03-03 10:09:46 -0800 | [diff] [blame] | 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" */ \ |
Haibo Huang | 5eba2b4 | 2021-01-22 11:22:02 -0800 | [diff] [blame] | 19 | PyFrameObject *prefix##_frame; \ |
Haibo Huang | d883030 | 2020-03-03 10:09:46 -0800 | [diff] [blame] | 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) |
Haibo Huang | 5eba2b4 | 2021-01-22 11:22:02 -0800 | [diff] [blame] | 38 | #define PyGen_CheckExact(op) Py_IS_TYPE(op, &PyGen_Type) |
Haibo Huang | d883030 | 2020-03-03 10:09:46 -0800 | [diff] [blame] | 39 | |
Haibo Huang | 5eba2b4 | 2021-01-22 11:22:02 -0800 | [diff] [blame] | 40 | PyAPI_FUNC(PyObject *) PyGen_New(PyFrameObject *); |
| 41 | PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(PyFrameObject *, |
Haibo Huang | d883030 | 2020-03-03 10:09:46 -0800 | [diff] [blame] | 42 | PyObject *name, PyObject *qualname); |
Haibo Huang | d883030 | 2020-03-03 10:09:46 -0800 | [diff] [blame] | 43 | PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *); |
| 44 | PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **); |
Haibo Huang | d883030 | 2020-03-03 10:09:46 -0800 | [diff] [blame] | 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 | |
Haibo Huang | 5eba2b4 | 2021-01-22 11:22:02 -0800 | [diff] [blame] | 57 | #define PyCoro_CheckExact(op) Py_IS_TYPE(op, &PyCoro_Type) |
Haibo Huang | d883030 | 2020-03-03 10:09:46 -0800 | [diff] [blame] | 58 | PyObject *_PyCoro_GetAwaitableIter(PyObject *o); |
Haibo Huang | 5eba2b4 | 2021-01-22 11:22:02 -0800 | [diff] [blame] | 59 | PyAPI_FUNC(PyObject *) PyCoro_New(PyFrameObject *, |
Haibo Huang | d883030 | 2020-03-03 10:09:46 -0800 | [diff] [blame] | 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 | |
Haibo Huang | 5eba2b4 | 2021-01-22 11:22:02 -0800 | [diff] [blame] | 85 | PyAPI_FUNC(PyObject *) PyAsyncGen_New(PyFrameObject *, |
Haibo Huang | d883030 | 2020-03-03 10:09:46 -0800 | [diff] [blame] | 86 | PyObject *name, PyObject *qualname); |
| 87 | |
Haibo Huang | 5eba2b4 | 2021-01-22 11:22:02 -0800 | [diff] [blame] | 88 | #define PyAsyncGen_CheckExact(op) Py_IS_TYPE(op, &PyAsyncGen_Type) |
Haibo Huang | d883030 | 2020-03-03 10:09:46 -0800 | [diff] [blame] | 89 | |
| 90 | PyObject *_PyAsyncGenValueWrapperNew(PyObject *); |
| 91 | |
Haibo Huang | d883030 | 2020-03-03 10:09:46 -0800 | [diff] [blame] | 92 | #endif |
| 93 | |
| 94 | #undef _PyGenObject_HEAD |
| 95 | |
| 96 | #ifdef __cplusplus |
| 97 | } |
| 98 | #endif |
| 99 | #endif /* !Py_GENOBJECT_H */ |
| 100 | #endif /* Py_LIMITED_API */ |