3#ifndef __NUITKA_COMPILED_COROUTINE_H__
4#define __NUITKA_COMPILED_COROUTINE_H__
11#if PYTHON_VERSION >= 0x350
15#include "nuitka/prelude.h"
20struct Nuitka_CoroutineObject {
30 PyObject *m_yield_from;
45 PyCodeObject *m_code_object;
49 Nuitka_ThreadStateFrameType *m_resume_frame;
52 Generator_Status m_status;
54#if PYTHON_VERSION >= 0x370
62 int m_yield_return_index;
78 Py_ssize_t m_closure_given;
82extern PyTypeObject Nuitka_Coroutine_Type;
84typedef PyObject *(*coroutine_code)(PyThreadState *tstate,
struct Nuitka_CoroutineObject *, PyObject *);
86extern PyObject *Nuitka_Coroutine_New(PyThreadState *tstate, coroutine_code code, PyObject *module, PyObject *name,
87 PyObject *qualname, PyCodeObject *code_object,
struct Nuitka_CellObject **closure,
88 Py_ssize_t closure_given, Py_ssize_t heap_storage_size);
90static inline bool Nuitka_Coroutine_Check(PyObject *
object) {
return Py_TYPE(
object) == &Nuitka_Coroutine_Type; }
92struct Nuitka_CoroutineWrapperObject {
96 struct Nuitka_CoroutineObject *m_coroutine;
99extern PyTypeObject Nuitka_CoroutineWrapper_Type;
101static inline bool Nuitka_CoroutineWrapper_Check(PyObject *
object) {
102 return Py_TYPE(
object) == &Nuitka_CoroutineWrapper_Type;
105static inline void SAVE_COROUTINE_EXCEPTION(PyThreadState *tstate,
struct Nuitka_CoroutineObject *coroutine) {
114#if PYTHON_VERSION < 0x3b0
115 PyObject *saved_exception_type = EXC_TYPE(tstate);
117 PyObject *saved_exception_value = EXC_VALUE(tstate);
118#if PYTHON_VERSION < 0x3b0
119 PyTracebackObject *saved_exception_traceback = EXC_TRACEBACK(tstate);
122#if PYTHON_VERSION < 0x370
123 EXC_TYPE(tstate) = tstate->frame->f_exc_type;
124 EXC_VALUE(tstate) = tstate->frame->f_exc_value;
125 SET_EXC_TRACEBACK(tstate, tstate->frame->f_exc_traceback);
127#if PYTHON_VERSION < 0x3b0
128 EXC_TYPE(tstate) = coroutine->m_exc_state.exception_type;
130 EXC_VALUE(tstate) = coroutine->m_exc_state.exception_value;
131#if PYTHON_VERSION < 0x3b0
132 SET_EXC_TRACEBACK(tstate, coroutine->m_exc_state.exception_tb);
136#if PYTHON_VERSION < 0x370
137 tstate->frame->f_exc_type = saved_exception_type;
138 tstate->frame->f_exc_value = saved_exception_value;
139 tstate->frame->f_exc_traceback = (PyObject *)saved_exception_traceback;
141#if PYTHON_VERSION < 0x3b0
142 coroutine->m_exc_state.exception_type = saved_exception_type;
144 coroutine->m_exc_state.exception_value = saved_exception_value;
145#if PYTHON_VERSION < 0x3b0
146 coroutine->m_exc_state.exception_tb = (PyTracebackObject *)saved_exception_traceback;
151static inline void RESTORE_COROUTINE_EXCEPTION(PyThreadState *tstate,
struct Nuitka_CoroutineObject *coroutine) {
155#if PYTHON_VERSION < 0x3b0
156 PyObject *saved_exception_type = EXC_TYPE(tstate);
158 PyObject *saved_exception_value = EXC_VALUE(tstate);
159#if PYTHON_VERSION < 0x3b0
160 PyTracebackObject *saved_exception_traceback = EXC_TRACEBACK(tstate);
163#if PYTHON_VERSION < 0x370
164 EXC_TYPE(tstate) = tstate->frame->f_exc_type;
165 EXC_VALUE(tstate) = tstate->frame->f_exc_value;
166 SET_EXC_TRACEBACK(tstate, tstate->frame->f_exc_traceback);
168 tstate->frame->f_exc_type = saved_exception_type;
169 tstate->frame->f_exc_value = saved_exception_value;
170 tstate->frame->f_exc_traceback = (PyObject *)saved_exception_traceback;
172#if PYTHON_VERSION < 0x3b0
173 EXC_TYPE(tstate) = coroutine->m_exc_state.exception_type;
175 EXC_VALUE(tstate) = coroutine->m_exc_state.exception_value;
176#if PYTHON_VERSION < 0x3b0
177 SET_EXC_TRACEBACK(tstate, coroutine->m_exc_state.exception_tb);
180#if PYTHON_VERSION < 0x3b0
181 coroutine->m_exc_state.exception_type = saved_exception_type;
183 coroutine->m_exc_state.exception_value = saved_exception_value;
184#if PYTHON_VERSION < 0x3b0
185 coroutine->m_exc_state.exception_tb = (PyTracebackObject *)saved_exception_traceback;
197typedef int Generator_Status;
198static const int await_normal = 0;
199static const int await_enter = 1;
200static const int await_exit = 2;
204extern PyObject *ASYNC_MAKE_ITERATOR(PyThreadState *tstate, PyObject *value);
207extern PyObject *ASYNC_ITERATOR_NEXT(PyThreadState *tstate, PyObject *value);
210extern PyObject *ASYNC_AWAIT(PyThreadState *tstate, PyObject *awaitable,
int await_kind);
212NUITKA_MAY_BE_UNUSED
static void STORE_COROUTINE_EXCEPTION(PyThreadState *tstate,
213 struct Nuitka_CoroutineObject *coroutine) {
214#if PYTHON_VERSION < 0x3b0
215 EXC_TYPE_F(coroutine) = EXC_TYPE(tstate);
216 if (EXC_TYPE_F(coroutine) == Py_None) {
217 EXC_TYPE_F(coroutine) = NULL;
219 Py_XINCREF(EXC_TYPE_F(coroutine));
221 EXC_VALUE_F(coroutine) = EXC_VALUE(tstate);
222 Py_XINCREF(EXC_VALUE_F(coroutine));
223#if PYTHON_VERSION < 0x3b0
224 ASSIGN_EXC_TRACEBACK_F(coroutine, EXC_TRACEBACK(tstate));
225 Py_XINCREF(EXC_TRACEBACK_F(coroutine));
229NUITKA_MAY_BE_UNUSED
static void DROP_COROUTINE_EXCEPTION(
struct Nuitka_CoroutineObject *coroutine) {
230#if PYTHON_VERSION < 0x3b0
231 Py_CLEAR(EXC_TYPE_F(coroutine));
233 Py_CLEAR(EXC_VALUE_F(coroutine));
234#if PYTHON_VERSION < 0x3b0
235 Py_CLEAR(EXC_TRACEBACK_F(coroutine));
241extern int count_active_Nuitka_Coroutine_Type;
242extern int count_allocated_Nuitka_Coroutine_Type;
243extern int count_released_Nuitka_Coroutine_Type;
245extern int count_active_Nuitka_CoroutineWrapper_Type;
246extern int count_allocated_Nuitka_CoroutineWrapper_Type;
247extern int count_released_Nuitka_CoroutineWrapper_Type;
249extern int count_active_Nuitka_AIterWrapper_Type;
250extern int count_allocated_Nuitka_AIterWrapper_Type;
251extern int count_released_Nuitka_AIterWrapper_Type;
Definition compiled_cell.h:14
Definition exceptions.h:222
Definition compiled_frame.h:117