Commit 2befc187 authored by Stefan Behnel's avatar Stefan Behnel

Avoid some redundant thread state lookups.

Supply a general macro for fast exception setting without value (e.g. StopIteration).
parent d66eff64
...@@ -725,14 +725,18 @@ static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__pyx_CoroutineO ...@@ -725,14 +725,18 @@ static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__pyx_CoroutineO
static CYTHON_INLINE static CYTHON_INLINE
PyObject *__Pyx_Coroutine_MethodReturn(CYTHON_UNUSED PyObject* gen, PyObject *retval) { PyObject *__Pyx_Coroutine_MethodReturn(CYTHON_UNUSED PyObject* gen, PyObject *retval) {
if (unlikely(!retval && !PyErr_Occurred())) { if (unlikely(!retval)) {
__Pyx_PyThreadState_declare
__Pyx_PyThreadState_assign
if (!__Pyx_PyErr_Occurred()) {
// method call must not terminate with NULL without setting an exception // method call must not terminate with NULL without setting an exception
PyObject *exc = PyExc_StopIteration;
#ifdef __Pyx_AsyncGen_USED #ifdef __Pyx_AsyncGen_USED
if (__Pyx_AsyncGen_CheckExact(gen)) { if (__Pyx_AsyncGen_CheckExact(gen))
PyErr_SetNone(__Pyx_PyExc_StopAsyncIteration); exc = __Pyx_PyExc_StopAsyncIteration;
} else
#endif #endif
PyErr_SetNone(PyExc_StopIteration); __Pyx_PyErr_SetNone(exc);
}
} }
return retval; return retval;
} }
......
...@@ -79,8 +79,15 @@ static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tsta ...@@ -79,8 +79,15 @@ static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tsta
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); /*proto*/ static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); /*proto*/
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); /*proto*/ static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); /*proto*/
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
#else
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
#endif
#else #else
#define __Pyx_PyErr_Clear() PyErr_Clear() #define __Pyx_PyErr_Clear() PyErr_Clear()
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
#define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb) #define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb) #define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb) #define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb)
......
...@@ -161,12 +161,7 @@ static PyObject *__Pyx_PyIter_Next2Default(PyObject* defval) { ...@@ -161,12 +161,7 @@ static PyObject *__Pyx_PyIter_Next2Default(PyObject* defval) {
Py_INCREF(defval); Py_INCREF(defval);
return defval; return defval;
} }
#if CYTHON_COMPILING_IN_CPYTHON __Pyx_PyErr_SetNone(PyExc_StopIteration);
Py_INCREF(PyExc_StopIteration);
__Pyx_ErrRestore(PyExc_StopIteration, NULL, NULL);
#else
PyErr_SetNone(PyExc_StopIteration);
#endif
return NULL; return NULL;
} }
......
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