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. */ \ |
| 28 | PyObject *prefix##_qualname; |
| 29 | |
Martin v. Löwis | e440e47 | 2004-06-01 15:22:42 +0000 | [diff] [blame] | 30 | typedef struct { |
Nick Coghlan | 76e1bb0 | 2012-01-14 16:08:08 +1000 | [diff] [blame] | 31 | /* The gi_ prefix is intended to remind of generator-iterator. */ |
Yury Selivanov | 5376ba9 | 2015-06-22 12:19:30 -0400 | [diff] [blame] | 32 | _PyGenObject_HEAD(gi) |
Martin v. Löwis | e440e47 | 2004-06-01 15:22:42 +0000 | [diff] [blame] | 33 | } PyGenObject; |
| 34 | |
| 35 | PyAPI_DATA(PyTypeObject) PyGen_Type; |
| 36 | |
| 37 | #define PyGen_Check(op) PyObject_TypeCheck(op, &PyGen_Type) |
Christian Heimes | 90aa764 | 2007-12-19 02:45:37 +0000 | [diff] [blame] | 38 | #define PyGen_CheckExact(op) (Py_TYPE(op) == &PyGen_Type) |
Martin v. Löwis | e440e47 | 2004-06-01 15:22:42 +0000 | [diff] [blame] | 39 | |
Martin v. Löwis | 8d97e33 | 2004-06-27 15:43:12 +0000 | [diff] [blame] | 40 | PyAPI_FUNC(PyObject *) PyGen_New(struct _frame *); |
Victor Stinner | 40ee301 | 2014-06-16 15:59:28 +0200 | [diff] [blame] | 41 | PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(struct _frame *, |
| 42 | PyObject *name, PyObject *qualname); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 43 | PyAPI_FUNC(int) PyGen_NeedsFinalizing(PyGenObject *); |
Nick Coghlan | c40bc09 | 2012-06-17 15:15:49 +1000 | [diff] [blame] | 44 | PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **); |
Benjamin Peterson | 2afe6ae | 2012-03-15 15:37:39 -0500 | [diff] [blame] | 45 | PyObject *_PyGen_Send(PyGenObject *, PyObject *); |
Yury Selivanov | c724bae | 2016-03-02 11:30:46 -0500 | [diff] [blame] | 46 | PyObject *_PyGen_yf(PyGenObject *); |
Antoine Pitrou | 58720d6 | 2013-08-05 23:26:40 +0200 | [diff] [blame] | 47 | PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self); |
| 48 | |
Yury Selivanov | 5376ba9 | 2015-06-22 12:19:30 -0400 | [diff] [blame] | 49 | #ifndef Py_LIMITED_API |
| 50 | typedef struct { |
| 51 | _PyGenObject_HEAD(cr) |
| 52 | } PyCoroObject; |
| 53 | |
| 54 | PyAPI_DATA(PyTypeObject) PyCoro_Type; |
| 55 | PyAPI_DATA(PyTypeObject) _PyCoroWrapper_Type; |
| 56 | |
| 57 | #define PyCoro_CheckExact(op) (Py_TYPE(op) == &PyCoro_Type) |
| 58 | PyObject *_PyCoro_GetAwaitableIter(PyObject *o); |
| 59 | PyAPI_FUNC(PyObject *) PyCoro_New(struct _frame *, |
| 60 | PyObject *name, PyObject *qualname); |
| 61 | #endif |
| 62 | |
| 63 | #undef _PyGenObject_HEAD |
Martin v. Löwis | e440e47 | 2004-06-01 15:22:42 +0000 | [diff] [blame] | 64 | |
| 65 | #ifdef __cplusplus |
| 66 | } |
| 67 | #endif |
| 68 | #endif /* !Py_GENOBJECT_H */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 69 | #endif /* Py_LIMITED_API */ |