Martin v. Löwis | e440e47 | 2004-06-01 15:22:42 +0000 | [diff] [blame] | 1 | |
| 2 | /* Generator object interface */ |
| 3 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 4 | #ifndef Py_LIMITED_API |
Martin v. Löwis | e440e47 | 2004-06-01 15:22:42 +0000 | [diff] [blame] | 5 | #ifndef Py_GENOBJECT_H |
| 6 | #define Py_GENOBJECT_H |
| 7 | #ifdef __cplusplus |
| 8 | extern "C" { |
| 9 | #endif |
| 10 | |
Martin v. Löwis | 8d97e33 | 2004-06-27 15:43:12 +0000 | [diff] [blame] | 11 | struct _frame; /* Avoid including frameobject.h */ |
| 12 | |
Yury Selivanov | 5376ba9 | 2015-06-22 12:19:30 -0400 | [diff] [blame] | 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 | struct _frame *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. */ \ |
Mark Shannon | ae3087c | 2017-10-22 22:41:51 +0100 | [diff] [blame] | 28 | PyObject *prefix##_qualname; \ |
| 29 | _PyErr_StackItem prefix##_exc_state; |
Yury Selivanov | 5376ba9 | 2015-06-22 12:19:30 -0400 | [diff] [blame] | 30 | |
Martin v. Löwis | e440e47 | 2004-06-01 15:22:42 +0000 | [diff] [blame] | 31 | typedef struct { |
Nick Coghlan | 76e1bb0 | 2012-01-14 16:08:08 +1000 | [diff] [blame] | 32 | /* The gi_ prefix is intended to remind of generator-iterator. */ |
Yury Selivanov | 5376ba9 | 2015-06-22 12:19:30 -0400 | [diff] [blame] | 33 | _PyGenObject_HEAD(gi) |
Martin v. Löwis | e440e47 | 2004-06-01 15:22:42 +0000 | [diff] [blame] | 34 | } PyGenObject; |
| 35 | |
| 36 | PyAPI_DATA(PyTypeObject) PyGen_Type; |
| 37 | |
| 38 | #define PyGen_Check(op) PyObject_TypeCheck(op, &PyGen_Type) |
Christian Heimes | 90aa764 | 2007-12-19 02:45:37 +0000 | [diff] [blame] | 39 | #define PyGen_CheckExact(op) (Py_TYPE(op) == &PyGen_Type) |
Martin v. Löwis | e440e47 | 2004-06-01 15:22:42 +0000 | [diff] [blame] | 40 | |
Martin v. Löwis | 8d97e33 | 2004-06-27 15:43:12 +0000 | [diff] [blame] | 41 | PyAPI_FUNC(PyObject *) PyGen_New(struct _frame *); |
Victor Stinner | 40ee301 | 2014-06-16 15:59:28 +0200 | [diff] [blame] | 42 | PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(struct _frame *, |
| 43 | PyObject *name, PyObject *qualname); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 44 | PyAPI_FUNC(int) PyGen_NeedsFinalizing(PyGenObject *); |
Serhiy Storchaka | 24411f8 | 2016-11-06 18:44:42 +0200 | [diff] [blame] | 45 | PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *); |
Nick Coghlan | c40bc09 | 2012-06-17 15:15:49 +1000 | [diff] [blame] | 46 | PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **); |
Yury Selivanov | 833c626 | 2016-10-28 18:48:50 -0400 | [diff] [blame] | 47 | PyAPI_FUNC(PyObject *) _PyGen_Send(PyGenObject *, PyObject *); |
Yury Selivanov | c724bae | 2016-03-02 11:30:46 -0500 | [diff] [blame] | 48 | PyObject *_PyGen_yf(PyGenObject *); |
Antoine Pitrou | 58720d6 | 2013-08-05 23:26:40 +0200 | [diff] [blame] | 49 | PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self); |
| 50 | |
Yury Selivanov | 5376ba9 | 2015-06-22 12:19:30 -0400 | [diff] [blame] | 51 | #ifndef Py_LIMITED_API |
| 52 | typedef struct { |
| 53 | _PyGenObject_HEAD(cr) |
| 54 | } PyCoroObject; |
| 55 | |
| 56 | PyAPI_DATA(PyTypeObject) PyCoro_Type; |
| 57 | PyAPI_DATA(PyTypeObject) _PyCoroWrapper_Type; |
| 58 | |
Yury Selivanov | a6f6edb | 2016-06-09 15:08:31 -0400 | [diff] [blame] | 59 | PyAPI_DATA(PyTypeObject) _PyAIterWrapper_Type; |
Yury Selivanov | a6f6edb | 2016-06-09 15:08:31 -0400 | [diff] [blame] | 60 | |
Yury Selivanov | 5376ba9 | 2015-06-22 12:19:30 -0400 | [diff] [blame] | 61 | #define PyCoro_CheckExact(op) (Py_TYPE(op) == &PyCoro_Type) |
| 62 | PyObject *_PyCoro_GetAwaitableIter(PyObject *o); |
| 63 | PyAPI_FUNC(PyObject *) PyCoro_New(struct _frame *, |
| 64 | PyObject *name, PyObject *qualname); |
Yury Selivanov | eb63645 | 2016-09-08 22:01:51 -0700 | [diff] [blame] | 65 | |
| 66 | /* Asynchronous Generators */ |
| 67 | |
| 68 | typedef struct { |
| 69 | _PyGenObject_HEAD(ag) |
| 70 | PyObject *ag_finalizer; |
| 71 | |
| 72 | /* Flag is set to 1 when hooks set up by sys.set_asyncgen_hooks |
| 73 | were called on the generator, to avoid calling them more |
| 74 | than once. */ |
| 75 | int ag_hooks_inited; |
| 76 | |
| 77 | /* Flag is set to 1 when aclose() is called for the first time, or |
| 78 | when a StopAsyncIteration exception is raised. */ |
| 79 | int ag_closed; |
| 80 | } PyAsyncGenObject; |
| 81 | |
| 82 | PyAPI_DATA(PyTypeObject) PyAsyncGen_Type; |
| 83 | PyAPI_DATA(PyTypeObject) _PyAsyncGenASend_Type; |
| 84 | PyAPI_DATA(PyTypeObject) _PyAsyncGenWrappedValue_Type; |
| 85 | PyAPI_DATA(PyTypeObject) _PyAsyncGenAThrow_Type; |
| 86 | |
| 87 | PyAPI_FUNC(PyObject *) PyAsyncGen_New(struct _frame *, |
| 88 | PyObject *name, PyObject *qualname); |
| 89 | |
| 90 | #define PyAsyncGen_CheckExact(op) (Py_TYPE(op) == &PyAsyncGen_Type) |
| 91 | |
| 92 | PyObject *_PyAsyncGenValueWrapperNew(PyObject *); |
| 93 | |
| 94 | int PyAsyncGen_ClearFreeLists(void); |
| 95 | |
Yury Selivanov | 5376ba9 | 2015-06-22 12:19:30 -0400 | [diff] [blame] | 96 | #endif |
| 97 | |
| 98 | #undef _PyGenObject_HEAD |
Martin v. Löwis | e440e47 | 2004-06-01 15:22:42 +0000 | [diff] [blame] | 99 | |
| 100 | #ifdef __cplusplus |
| 101 | } |
| 102 | #endif |
| 103 | #endif /* !Py_GENOBJECT_H */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 104 | #endif /* Py_LIMITED_API */ |