Home | History | Annotate | Download | only in Include
      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 struct _frame; /* Avoid including frameobject.h */
     12 
     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     _PyErr_StackItem prefix##_exc_state;
     30 
     31 typedef struct {
     32     /* The gi_ prefix is intended to remind of generator-iterator. */
     33     _PyGenObject_HEAD(gi)
     34 } PyGenObject;
     35 
     36 PyAPI_DATA(PyTypeObject) PyGen_Type;
     37 
     38 #define PyGen_Check(op) PyObject_TypeCheck(op, &PyGen_Type)
     39 #define PyGen_CheckExact(op) (Py_TYPE(op) == &PyGen_Type)
     40 
     41 PyAPI_FUNC(PyObject *) PyGen_New(struct _frame *);
     42 PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(struct _frame *,
     43     PyObject *name, PyObject *qualname);
     44 PyAPI_FUNC(int) PyGen_NeedsFinalizing(PyGenObject *);
     45 PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *);
     46 PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);
     47 PyAPI_FUNC(PyObject *) _PyGen_Send(PyGenObject *, PyObject *);
     48 PyObject *_PyGen_yf(PyGenObject *);
     49 PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self);
     50 
     51 #ifndef Py_LIMITED_API
     52 typedef struct {
     53     _PyGenObject_HEAD(cr)
     54     PyObject *cr_origin;
     55 } PyCoroObject;
     56 
     57 PyAPI_DATA(PyTypeObject) PyCoro_Type;
     58 PyAPI_DATA(PyTypeObject) _PyCoroWrapper_Type;
     59 
     60 PyAPI_DATA(PyTypeObject) _PyAIterWrapper_Type;
     61 
     62 #define PyCoro_CheckExact(op) (Py_TYPE(op) == &PyCoro_Type)
     63 PyObject *_PyCoro_GetAwaitableIter(PyObject *o);
     64 PyAPI_FUNC(PyObject *) PyCoro_New(struct _frame *,
     65     PyObject *name, PyObject *qualname);
     66 
     67 /* Asynchronous Generators */
     68 
     69 typedef struct {
     70     _PyGenObject_HEAD(ag)
     71     PyObject *ag_finalizer;
     72 
     73     /* Flag is set to 1 when hooks set up by sys.set_asyncgen_hooks
     74        were called on the generator, to avoid calling them more
     75        than once. */
     76     int ag_hooks_inited;
     77 
     78     /* Flag is set to 1 when aclose() is called for the first time, or
     79        when a StopAsyncIteration exception is raised. */
     80     int ag_closed;
     81 } PyAsyncGenObject;
     82 
     83 PyAPI_DATA(PyTypeObject) PyAsyncGen_Type;
     84 PyAPI_DATA(PyTypeObject) _PyAsyncGenASend_Type;
     85 PyAPI_DATA(PyTypeObject) _PyAsyncGenWrappedValue_Type;
     86 PyAPI_DATA(PyTypeObject) _PyAsyncGenAThrow_Type;
     87 
     88 PyAPI_FUNC(PyObject *) PyAsyncGen_New(struct _frame *,
     89     PyObject *name, PyObject *qualname);
     90 
     91 #define PyAsyncGen_CheckExact(op) (Py_TYPE(op) == &PyAsyncGen_Type)
     92 
     93 PyObject *_PyAsyncGenValueWrapperNew(PyObject *);
     94 
     95 int PyAsyncGen_ClearFreeLists(void);
     96 
     97 #endif
     98 
     99 #undef _PyGenObject_HEAD
    100 
    101 #ifdef __cplusplus
    102 }
    103 #endif
    104 #endif /* !Py_GENOBJECT_H */
    105 #endif /* Py_LIMITED_API */
    106