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 | |
Martin v. Löwis | e440e47 | 2004-06-01 15:22:42 +0000 | [diff] [blame] | 13 | typedef struct { |
Nick Coghlan | 76e1bb0 | 2012-01-14 16:08:08 +1000 | [diff] [blame] | 14 | PyObject_HEAD |
| 15 | /* The gi_ prefix is intended to remind of generator-iterator. */ |
Martin v. Löwis | e440e47 | 2004-06-01 15:22:42 +0000 | [diff] [blame] | 16 | |
Nick Coghlan | 76e1bb0 | 2012-01-14 16:08:08 +1000 | [diff] [blame] | 17 | /* Note: gi_frame can be NULL if the generator is "finished" */ |
| 18 | struct _frame *gi_frame; |
Martin v. Löwis | e440e47 | 2004-06-01 15:22:42 +0000 | [diff] [blame] | 19 | |
Nick Coghlan | 76e1bb0 | 2012-01-14 16:08:08 +1000 | [diff] [blame] | 20 | /* True if generator is being executed. */ |
Antoine Pitrou | b4a9237 | 2012-03-10 23:43:12 +0100 | [diff] [blame] | 21 | char gi_running; |
Benjamin Peterson | 2afe6ae | 2012-03-15 15:37:39 -0500 | [diff] [blame] | 22 | |
Nick Coghlan | 76e1bb0 | 2012-01-14 16:08:08 +1000 | [diff] [blame] | 23 | /* The code object backing the generator */ |
| 24 | PyObject *gi_code; |
Martin v. Löwis | e440e47 | 2004-06-01 15:22:42 +0000 | [diff] [blame] | 25 | |
Nick Coghlan | 76e1bb0 | 2012-01-14 16:08:08 +1000 | [diff] [blame] | 26 | /* List of weak reference. */ |
| 27 | PyObject *gi_weakreflist; |
Martin v. Löwis | e440e47 | 2004-06-01 15:22:42 +0000 | [diff] [blame] | 28 | } PyGenObject; |
| 29 | |
| 30 | PyAPI_DATA(PyTypeObject) PyGen_Type; |
| 31 | |
| 32 | #define PyGen_Check(op) PyObject_TypeCheck(op, &PyGen_Type) |
Christian Heimes | 90aa764 | 2007-12-19 02:45:37 +0000 | [diff] [blame] | 33 | #define PyGen_CheckExact(op) (Py_TYPE(op) == &PyGen_Type) |
Martin v. Löwis | e440e47 | 2004-06-01 15:22:42 +0000 | [diff] [blame] | 34 | |
Martin v. Löwis | 8d97e33 | 2004-06-27 15:43:12 +0000 | [diff] [blame] | 35 | PyAPI_FUNC(PyObject *) PyGen_New(struct _frame *); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 36 | PyAPI_FUNC(int) PyGen_NeedsFinalizing(PyGenObject *); |
Nick Coghlan | c40bc09 | 2012-06-17 15:15:49 +1000 | [diff] [blame] | 37 | PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **); |
Benjamin Peterson | 2afe6ae | 2012-03-15 15:37:39 -0500 | [diff] [blame] | 38 | PyObject *_PyGen_Send(PyGenObject *, PyObject *); |
Martin v. Löwis | e440e47 | 2004-06-01 15:22:42 +0000 | [diff] [blame] | 39 | |
| 40 | #ifdef __cplusplus |
| 41 | } |
| 42 | #endif |
| 43 | #endif /* !Py_GENOBJECT_H */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 44 | #endif /* Py_LIMITED_API */ |