Commit 226ad371 authored by Stefan Behnel's avatar Stefan Behnel

Reuse known thread state in more places instead of looking it up again.

parent 105aba6b
...@@ -9539,7 +9539,7 @@ class _YieldDelegationExprNode(YieldExprNode): ...@@ -9539,7 +9539,7 @@ class _YieldDelegationExprNode(YieldExprNode):
code.put_gotref(self.result()) code.put_gotref(self.result())
def handle_iteration_exception(self, code): def handle_iteration_exception(self, code):
code.putln("PyObject* exc_type = PyErr_Occurred();") code.putln("PyObject* exc_type = __Pyx_PyErr_Occurred();")
code.putln("if (exc_type) {") code.putln("if (exc_type) {")
code.putln("if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit &&" code.putln("if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit &&"
" __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();") " __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear();")
...@@ -9589,7 +9589,7 @@ class AwaitIterNextExprNode(AwaitExprNode): ...@@ -9589,7 +9589,7 @@ class AwaitIterNextExprNode(AwaitExprNode):
def _generate_break(self, code): def _generate_break(self, code):
code.globalstate.use_utility_code(UtilityCode.load_cached("StopAsyncIteration", "Coroutine.c")) code.globalstate.use_utility_code(UtilityCode.load_cached("StopAsyncIteration", "Coroutine.c"))
code.putln("PyObject* exc_type = PyErr_Occurred();") code.putln("PyObject* exc_type = __Pyx_PyErr_Occurred();")
code.putln("if (unlikely(exc_type && (exc_type == __Pyx_PyExc_StopAsyncIteration || (" code.putln("if (unlikely(exc_type && (exc_type == __Pyx_PyExc_StopAsyncIteration || ("
" exc_type != PyExc_StopIteration && exc_type != PyExc_GeneratorExit &&" " exc_type != PyExc_StopIteration && exc_type != PyExc_GeneratorExit &&"
" __Pyx_PyErr_GivenExceptionMatches(exc_type, __Pyx_PyExc_StopAsyncIteration))))) {") " __Pyx_PyErr_GivenExceptionMatches(exc_type, __Pyx_PyExc_StopAsyncIteration))))) {")
......
...@@ -355,6 +355,7 @@ static void __Pyx_Generator_Replace_StopIteration(CYTHON_UNUSED int in_async_gen ...@@ -355,6 +355,7 @@ static void __Pyx_Generator_Replace_StopIteration(CYTHON_UNUSED int in_async_gen
//////////////////// CoroutineBase.proto //////////////////// //////////////////// CoroutineBase.proto ////////////////////
//@substitute: naming
typedef PyObject *(*__pyx_coroutine_body_t)(PyObject *, PyObject *); typedef PyObject *(*__pyx_coroutine_body_t)(PyObject *, PyObject *);
...@@ -401,12 +402,14 @@ static PyObject *__Pyx_Coroutine_Throw(PyObject *gen, PyObject *args); /*proto*/ ...@@ -401,12 +402,14 @@ static PyObject *__Pyx_Coroutine_Throw(PyObject *gen, PyObject *args); /*proto*/
} }
static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__pyx_CoroutineObject *self); static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__pyx_CoroutineObject *self);
#if 1 || PY_VERSION_HEX < 0x030300B0 #if CYTHON_FAST_THREAD_STATE
static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue); /*proto*/ #define __Pyx_PyGen_FetchStopIterationValue(pvalue) \
__Pyx_PyGen__FetchStopIterationValue($local_tstate_cname, pvalue)
#else #else
#define __Pyx_PyGen_FetchStopIterationValue(pvalue) PyGen_FetchStopIterationValue(pvalue) #define __Pyx_PyGen_FetchStopIterationValue(pvalue) \
__Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, pvalue)
#endif #endif
static int __Pyx_PyGen__FetchStopIterationValue(PyThreadState *tstate, PyObject **pvalue); /*proto*/
//////////////////// Coroutine.proto //////////////////// //////////////////// Coroutine.proto ////////////////////
...@@ -462,12 +465,9 @@ static int __pyx_Generator_init(void); /*proto*/ ...@@ -462,12 +465,9 @@ static int __pyx_Generator_init(void); /*proto*/
// Returns 0 if no exception or StopIteration is set. // Returns 0 if no exception or StopIteration is set.
// If any other exception is set, returns -1 and leaves // If any other exception is set, returns -1 and leaves
// pvalue unchanged. // pvalue unchanged.
#if 1 || PY_VERSION_HEX < 0x030300B0 static int __Pyx_PyGen__FetchStopIterationValue(CYTHON_UNUSED PyThreadState *$local_tstate_cname, PyObject **pvalue) {
static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue) {
PyObject *et, *ev, *tb; PyObject *et, *ev, *tb;
PyObject *value = NULL; PyObject *value = NULL;
__Pyx_PyThreadState_declare
__Pyx_PyThreadState_assign
__Pyx_ErrFetch(&et, &ev, &tb); __Pyx_ErrFetch(&et, &ev, &tb);
...@@ -554,7 +554,6 @@ static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue) { ...@@ -554,7 +554,6 @@ static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue) {
*pvalue = value; *pvalue = value;
return 0; return 0;
} }
#endif
static CYTHON_INLINE static CYTHON_INLINE
void __Pyx_Coroutine_ExceptionClear(__pyx_CoroutineObject *self) { void __Pyx_Coroutine_ExceptionClear(__pyx_CoroutineObject *self) {
...@@ -714,7 +713,7 @@ PyObject *__Pyx_Coroutine_FinishDelegation(__pyx_CoroutineObject *gen) { ...@@ -714,7 +713,7 @@ PyObject *__Pyx_Coroutine_FinishDelegation(__pyx_CoroutineObject *gen) {
PyObject *ret; PyObject *ret;
PyObject *val = NULL; PyObject *val = NULL;
__Pyx_Coroutine_Undelegate(gen); __Pyx_Coroutine_Undelegate(gen);
__Pyx_PyGen_FetchStopIterationValue(&val); __Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, &val);
// val == NULL on failure => pass on exception // val == NULL on failure => pass on exception
ret = __Pyx_Coroutine_SendEx(gen, val, 0); ret = __Pyx_Coroutine_SendEx(gen, val, 0);
Py_XDECREF(val); Py_XDECREF(val);
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#if CYTHON_FAST_THREAD_STATE #if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyThreadState_declare PyThreadState *$local_tstate_cname; #define __Pyx_PyThreadState_declare PyThreadState *$local_tstate_cname;
#define __Pyx_PyErr_Occurred() $local_tstate_cname->curexc_type
#if PY_VERSION_HEX >= 0x03050000 #if PY_VERSION_HEX >= 0x03050000
#define __Pyx_PyThreadState_assign $local_tstate_cname = _PyThreadState_UncheckedGet(); #define __Pyx_PyThreadState_assign $local_tstate_cname = _PyThreadState_UncheckedGet();
#elif PY_VERSION_HEX >= 0x03000000 #elif PY_VERSION_HEX >= 0x03000000
...@@ -23,6 +24,7 @@ ...@@ -23,6 +24,7 @@
#else #else
#define __Pyx_PyThreadState_declare #define __Pyx_PyThreadState_declare
#define __Pyx_PyThreadState_assign #define __Pyx_PyThreadState_assign
#define __Pyx_PyErr_Occurred() PyErr_Occurred()
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment