blob: 30cb02323440846581663ec3a3ffae9ec7552c95 [file] [log] [blame]
Martin v. Löwise440e472004-06-01 15:22:42 +00001
2/* Generator object interface */
3
Martin v. Löwis4d0d4712010-12-03 20:14:31 +00004#ifndef Py_LIMITED_API
Martin v. Löwise440e472004-06-01 15:22:42 +00005#ifndef Py_GENOBJECT_H
6#define Py_GENOBJECT_H
7#ifdef __cplusplus
8extern "C" {
9#endif
10
Martin v. Löwis8d97e332004-06-27 15:43:12 +000011struct _frame; /* Avoid including frameobject.h */
12
Yury Selivanov5376ba92015-06-22 12:19:30 -040013/* _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öwise440e472004-06-01 15:22:42 +000030typedef struct {
Nick Coghlan76e1bb02012-01-14 16:08:08 +100031 /* The gi_ prefix is intended to remind of generator-iterator. */
Yury Selivanov5376ba92015-06-22 12:19:30 -040032 _PyGenObject_HEAD(gi)
Martin v. Löwise440e472004-06-01 15:22:42 +000033} PyGenObject;
34
35PyAPI_DATA(PyTypeObject) PyGen_Type;
36
37#define PyGen_Check(op) PyObject_TypeCheck(op, &PyGen_Type)
Christian Heimes90aa7642007-12-19 02:45:37 +000038#define PyGen_CheckExact(op) (Py_TYPE(op) == &PyGen_Type)
Martin v. Löwise440e472004-06-01 15:22:42 +000039
Martin v. Löwis8d97e332004-06-27 15:43:12 +000040PyAPI_FUNC(PyObject *) PyGen_New(struct _frame *);
Victor Stinner40ee3012014-06-16 15:59:28 +020041PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(struct _frame *,
42 PyObject *name, PyObject *qualname);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000043PyAPI_FUNC(int) PyGen_NeedsFinalizing(PyGenObject *);
Nick Coghlanc40bc092012-06-17 15:15:49 +100044PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);
Benjamin Peterson2afe6ae2012-03-15 15:37:39 -050045PyObject *_PyGen_Send(PyGenObject *, PyObject *);
Yury Selivanovc724bae2016-03-02 11:30:46 -050046PyObject *_PyGen_yf(PyGenObject *);
Antoine Pitrou58720d62013-08-05 23:26:40 +020047PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self);
48
Yury Selivanov5376ba92015-06-22 12:19:30 -040049#ifndef Py_LIMITED_API
50typedef struct {
51 _PyGenObject_HEAD(cr)
52} PyCoroObject;
53
54PyAPI_DATA(PyTypeObject) PyCoro_Type;
55PyAPI_DATA(PyTypeObject) _PyCoroWrapper_Type;
56
57#define PyCoro_CheckExact(op) (Py_TYPE(op) == &PyCoro_Type)
58PyObject *_PyCoro_GetAwaitableIter(PyObject *o);
59PyAPI_FUNC(PyObject *) PyCoro_New(struct _frame *,
60 PyObject *name, PyObject *qualname);
61#endif
62
63#undef _PyGenObject_HEAD
Martin v. Löwise440e472004-06-01 15:22:42 +000064
65#ifdef __cplusplus
66}
67#endif
68#endif /* !Py_GENOBJECT_H */
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000069#endif /* Py_LIMITED_API */