Commit 832da3bf authored by Stefan Behnel's avatar Stefan Behnel

avoid some redundant calls to PyThreadState_GET() to reduce locking etc. during exception handling

parent 8782d92a
...@@ -2253,11 +2253,9 @@ class NameNode(AtomicExprNode): ...@@ -2253,11 +2253,9 @@ class NameNode(AtomicExprNode):
key_error_code = ( key_error_code = (
'{ PyErr_Clear(); PyErr_Format(PyExc_NameError, "name \'%%s\' is not defined", "%s"); }' % '{ PyErr_Clear(); PyErr_Format(PyExc_NameError, "name \'%%s\' is not defined", "%s"); }' %
self.entry.name) self.entry.name)
code.globalstate.use_utility_code(
UtilityCode.load_cached("PyErrExceptionMatches", "Exceptions.c"))
code.putln( code.putln(
'if (unlikely(PyObject_DelItem(%s, %s) < 0)) {' 'if (unlikely(PyObject_DelItem(%s, %s) < 0)) {'
' if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_KeyError))) %s' ' if (likely(PyErr_ExceptionMatches(PyExc_KeyError))) %s'
' %s ' ' %s '
'}' % (namespace, interned_cname, '}' % (namespace, interned_cname,
key_error_code, key_error_code,
...@@ -2269,11 +2267,9 @@ class NameNode(AtomicExprNode): ...@@ -2269,11 +2267,9 @@ class NameNode(AtomicExprNode):
del_code = '__Pyx_PyObject_DelAttrStr(%s, %s)' % ( del_code = '__Pyx_PyObject_DelAttrStr(%s, %s)' % (
Naming.module_cname, interned_cname) Naming.module_cname, interned_cname)
if ignore_nonexisting: if ignore_nonexisting:
code.globalstate.use_utility_code(
UtilityCode.load_cached("PyErrExceptionMatches", "Exceptions.c"))
code.putln( code.putln(
'if (unlikely(%s < 0)) {' 'if (unlikely(%s < 0)) {'
' if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) PyErr_Clear(); else %s ' ' if (likely(PyErr_ExceptionMatches(PyExc_AttributeError))) PyErr_Clear(); else %s '
'}' % (del_code, code.error_goto(self.pos))) '}' % (del_code, code.error_goto(self.pos)))
else: else:
code.put_error_if_neg(self.pos, del_code) code.put_error_if_neg(self.pos, del_code)
......
...@@ -1725,9 +1725,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1725,9 +1725,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln( code.putln(
"PyObject *v = PyObject_GenericGetAttr(o, n);") "PyObject *v = PyObject_GenericGetAttr(o, n);")
if getattr_entry is not None: if getattr_entry is not None:
code.globalstate.use_utility_code(UtilityCode.load_cached("PyErrExceptionMatches", "Exceptions.c"))
code.putln( code.putln(
"if (!v && __Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)) {") "if (!v && PyErr_ExceptionMatches(PyExc_AttributeError)) {")
code.putln( code.putln(
"PyErr_Clear();") "PyErr_Clear();")
code.putln( code.putln(
......
...@@ -82,6 +82,7 @@ kwds_cname = pyrex_prefix + "kwds" ...@@ -82,6 +82,7 @@ kwds_cname = pyrex_prefix + "kwds"
lineno_cname = pyrex_prefix + "lineno" lineno_cname = pyrex_prefix + "lineno"
clineno_cname = pyrex_prefix + "clineno" clineno_cname = pyrex_prefix + "clineno"
cfilenm_cname = pyrex_prefix + "cfilenm" cfilenm_cname = pyrex_prefix + "cfilenm"
local_tstate_cname = pyrex_prefix + "tstate"
module_cname = pyrex_prefix + "m" module_cname = pyrex_prefix + "m"
moddoc_cname = pyrex_prefix + "mdoc" moddoc_cname = pyrex_prefix + "mdoc"
methtable_cname = pyrex_prefix + "methods" methtable_cname = pyrex_prefix + "methods"
......
...@@ -4122,8 +4122,7 @@ class GeneratorBodyDefNode(DefNode): ...@@ -4122,8 +4122,7 @@ class GeneratorBodyDefNode(DefNode):
if Future.generator_stop in env.global_scope().context.future_directives: if Future.generator_stop in env.global_scope().context.future_directives:
# PEP 479: turn accidental StopIteration exceptions into a RuntimeError # PEP 479: turn accidental StopIteration exceptions into a RuntimeError
code.globalstate.use_utility_code(UtilityCode.load_cached("pep479", "Coroutine.c")) code.globalstate.use_utility_code(UtilityCode.load_cached("pep479", "Coroutine.c"))
code.globalstate.use_utility_code(UtilityCode.load_cached("PyErrExceptionMatches", "Exceptions.c")) code.putln("if (unlikely(PyErr_ExceptionMatches(PyExc_StopIteration))) "
code.putln("if (unlikely(__Pyx_PyErr_ExceptionMatches(PyExc_StopIteration))) "
"__Pyx_Generator_Replace_StopIteration();") "__Pyx_Generator_Replace_StopIteration();")
for cname, type in code.funcstate.all_managed_temps(): for cname, type in code.funcstate.all_managed_temps():
code.put_xdecref(cname, type) code.put_xdecref(cname, type)
...@@ -6710,8 +6709,10 @@ class TryExceptStatNode(StatNode): ...@@ -6710,8 +6709,10 @@ class TryExceptStatNode(StatNode):
if can_raise: if can_raise:
# inject code before the try block to save away the exception state # inject code before the try block to save away the exception state
code.globalstate.use_utility_code(reset_exception_utility_code) code.globalstate.use_utility_code(reset_exception_utility_code)
save_exc.putln("__Pyx_ExceptionSave(%s);" % save_exc.putln("__Pyx_PyThreadState_declare")
', '.join(['&%s' % var for var in exc_save_vars])) save_exc.putln("__Pyx_PyThreadState_assign")
save_exc.putln("__Pyx_ExceptionSave(%s);" % (
', '.join(['&%s' % var for var in exc_save_vars])))
for var in exc_save_vars: for var in exc_save_vars:
save_exc.put_xgotref(var) save_exc.put_xgotref(var)
...@@ -6747,6 +6748,7 @@ class TryExceptStatNode(StatNode): ...@@ -6747,6 +6748,7 @@ class TryExceptStatNode(StatNode):
code.put_xdecref_clear(var, py_object_type) code.put_xdecref_clear(var, py_object_type)
code.put_goto(try_end_label) code.put_goto(try_end_label)
code.put_label(our_error_label) code.put_label(our_error_label)
code.putln("__Pyx_PyThreadState_assign") # re-assign in case a generator yielded
for temp_name, temp_type in temps_to_clean_up: for temp_name, temp_type in temps_to_clean_up:
code.put_xdecref_clear(temp_name, temp_type) code.put_xdecref_clear(temp_name, temp_type)
for except_clause in self.except_clauses: for except_clause in self.except_clauses:
...@@ -6764,14 +6766,18 @@ class TryExceptStatNode(StatNode): ...@@ -6764,14 +6766,18 @@ class TryExceptStatNode(StatNode):
code.put_goto(try_end_label) code.put_goto(try_end_label)
code.put_label(exit_label) code.put_label(exit_label)
code.mark_pos(self.pos, trace=False) code.mark_pos(self.pos, trace=False)
restore_saved_exception() if can_raise:
code.putln("__Pyx_PyThreadState_assign") # re-assign in case a generator yielded
restore_saved_exception()
code.put_goto(old_label) code.put_goto(old_label)
if code.label_used(except_end_label): if code.label_used(except_end_label):
if not normal_case_terminates and not code.label_used(try_end_label): if not normal_case_terminates and not code.label_used(try_end_label):
code.put_goto(try_end_label) code.put_goto(try_end_label)
code.put_label(except_end_label) code.put_label(except_end_label)
restore_saved_exception() if can_raise:
code.putln("__Pyx_PyThreadState_assign") # re-assign in case a generator yielded
restore_saved_exception()
if code.label_used(try_end_label): if code.label_used(try_end_label):
code.put_label(try_end_label) code.put_label(try_end_label)
code.putln("}") code.putln("}")
...@@ -7043,6 +7049,7 @@ class TryFinallyStatNode(StatNode): ...@@ -7043,6 +7049,7 @@ class TryFinallyStatNode(StatNode):
if preserve_error: if preserve_error:
code.putln('/*exception exit:*/{') code.putln('/*exception exit:*/{')
code.putln("__Pyx_PyThreadState_declare")
if self.is_try_finally_in_nogil: if self.is_try_finally_in_nogil:
code.declare_gilstate() code.declare_gilstate()
if needs_success_cleanup: if needs_success_cleanup:
...@@ -7139,6 +7146,7 @@ class TryFinallyStatNode(StatNode): ...@@ -7139,6 +7146,7 @@ class TryFinallyStatNode(StatNode):
code.putln(' '.join(["%s = 0;"]*len(exc_vars)) % exc_vars) code.putln(' '.join(["%s = 0;"]*len(exc_vars)) % exc_vars)
if self.is_try_finally_in_nogil: if self.is_try_finally_in_nogil:
code.put_ensure_gil(declare_gilstate=False) code.put_ensure_gil(declare_gilstate=False)
code.putln("__Pyx_PyThreadState_assign")
for temp_name, type in temps_to_clean_up: for temp_name, type in temps_to_clean_up:
code.put_xdecref_clear(temp_name, type) code.put_xdecref_clear(temp_name, type)
...@@ -7169,6 +7177,7 @@ class TryFinallyStatNode(StatNode): ...@@ -7169,6 +7177,7 @@ class TryFinallyStatNode(StatNode):
if self.is_try_finally_in_nogil: if self.is_try_finally_in_nogil:
code.put_ensure_gil(declare_gilstate=False) code.put_ensure_gil(declare_gilstate=False)
code.putln("__Pyx_PyThreadState_assign") # re-assign in case a generator yielded
# not using preprocessor here to avoid warnings about # not using preprocessor here to avoid warnings about
# unused utility functions and/or temps # unused utility functions and/or temps
...@@ -7195,6 +7204,8 @@ class TryFinallyStatNode(StatNode): ...@@ -7195,6 +7204,8 @@ class TryFinallyStatNode(StatNode):
code.globalstate.use_utility_code(reset_exception_utility_code) code.globalstate.use_utility_code(reset_exception_utility_code)
if self.is_try_finally_in_nogil: if self.is_try_finally_in_nogil:
code.put_ensure_gil(declare_gilstate=False) code.put_ensure_gil(declare_gilstate=False)
code.putln("__Pyx_PyThreadState_assign") # re-assign in case a generator yielded
# not using preprocessor here to avoid warnings about # not using preprocessor here to avoid warnings about
# unused utility functions and/or temps # unused utility functions and/or temps
code.putln("if (PY_MAJOR_VERSION >= 3) {") code.putln("if (PY_MAJOR_VERSION >= 3) {")
...@@ -8836,13 +8847,14 @@ traceback_utility_code = UtilityCode.load_cached("AddTraceback", "Exceptions.c") ...@@ -8836,13 +8847,14 @@ traceback_utility_code = UtilityCode.load_cached("AddTraceback", "Exceptions.c")
#------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------
get_exception_tuple_utility_code = UtilityCode(proto=""" get_exception_tuple_utility_code = UtilityCode(proto="""
static PyObject *__Pyx_GetExceptionTuple(void); /*proto*/ static PyObject *__Pyx_GetExceptionTuple(PyThreadState *__pyx_tstate); /*proto*/
""", """,
# I doubt that calling __Pyx_GetException() here is correct as it moves # I doubt that calling __Pyx_GetException() here is correct as it moves
# the exception from tstate->curexc_* to tstate->exc_*, which prevents # the exception from tstate->curexc_* to tstate->exc_*, which prevents
# exception handlers later on from receiving it. # exception handlers later on from receiving it.
# NOTE: "__pyx_tstate" may be used by __Pyx_GetException() macro
impl = """ impl = """
static PyObject *__Pyx_GetExceptionTuple(void) { static PyObject *__Pyx_GetExceptionTuple(CYTHON_UNUSED PyThreadState *__pyx_tstate) {
PyObject *type = NULL, *value = NULL, *tb = NULL; PyObject *type = NULL, *value = NULL, *tb = NULL;
if (__Pyx_GetException(&type, &value, &tb) == 0) { if (__Pyx_GetException(&type, &value, &tb) == 0) {
PyObject* exc_info = PyTuple_New(3); PyObject* exc_info = PyTuple_New(3);
......
...@@ -167,13 +167,12 @@ bad: ...@@ -167,13 +167,12 @@ bad:
static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *); /*proto*/ static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *); /*proto*/
//////////////////// GetAttr3 //////////////////// //////////////////// GetAttr3 ////////////////////
//@requires: Exceptions.c::PyErrExceptionMatches
//@requires: ObjectHandling.c::GetAttr //@requires: ObjectHandling.c::GetAttr
static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) { static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) {
PyObject *r = __Pyx_GetAttr(o, n); PyObject *r = __Pyx_GetAttr(o, n);
if (unlikely(!r)) { if (unlikely(!r)) {
if (!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)) if (!PyErr_ExceptionMatches(PyExc_AttributeError))
goto bad; goto bad;
PyErr_Clear(); PyErr_Clear();
r = d; r = d;
......
...@@ -177,7 +177,6 @@ static CYTHON_INLINE PyObject *__Pyx_Coroutine_AsyncIterNext(PyObject *o); /*pro ...@@ -177,7 +177,6 @@ static CYTHON_INLINE PyObject *__Pyx_Coroutine_AsyncIterNext(PyObject *o); /*pro
//////////////////// AsyncIter //////////////////// //////////////////// AsyncIter ////////////////////
//@requires: GetAwaitIter //@requires: GetAwaitIter
//@requires: Exceptions.c::PyErrExceptionMatches
//@requires: ObjectHandling.c::PyObjectCallMethod0 //@requires: ObjectHandling.c::PyObjectCallMethod0
static CYTHON_INLINE PyObject *__Pyx_Coroutine_GetAsyncIter(PyObject *obj) { static CYTHON_INLINE PyObject *__Pyx_Coroutine_GetAsyncIter(PyObject *obj) {
...@@ -193,7 +192,7 @@ static CYTHON_INLINE PyObject *__Pyx_Coroutine_GetAsyncIter(PyObject *obj) { ...@@ -193,7 +192,7 @@ static CYTHON_INLINE PyObject *__Pyx_Coroutine_GetAsyncIter(PyObject *obj) {
if (likely(iter)) if (likely(iter))
return iter; return iter;
// FIXME: for the sake of a nicely conforming exception message, assume any AttributeError meant '__aiter__' // FIXME: for the sake of a nicely conforming exception message, assume any AttributeError meant '__aiter__'
if (!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)) if (!PyErr_ExceptionMatches(PyExc_AttributeError))
return NULL; return NULL;
} }
#else #else
...@@ -220,7 +219,7 @@ static CYTHON_INLINE PyObject *__Pyx_Coroutine_AsyncIterNext(PyObject *obj) { ...@@ -220,7 +219,7 @@ static CYTHON_INLINE PyObject *__Pyx_Coroutine_AsyncIterNext(PyObject *obj) {
return value; return value;
} }
// FIXME: for the sake of a nicely conforming exception message, assume any AttributeError meant '__anext__' // FIXME: for the sake of a nicely conforming exception message, assume any AttributeError meant '__anext__'
if (__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)) if (PyErr_ExceptionMatches(PyExc_AttributeError))
#endif #endif
PyErr_Format(PyExc_TypeError, "'async for' requires an object with __anext__ method, got %.100s", PyErr_Format(PyExc_TypeError, "'async for' requires an object with __anext__ method, got %.100s",
Py_TYPE(obj)->tp_name); Py_TYPE(obj)->tp_name);
...@@ -307,10 +306,10 @@ static int __pyx_Generator_init(void); /*proto*/ ...@@ -307,10 +306,10 @@ static int __pyx_Generator_init(void); /*proto*/
//////////////////// CoroutineBase //////////////////// //////////////////// CoroutineBase ////////////////////
//@substitute: naming
//@requires: Exceptions.c::PyErrFetchRestore //@requires: Exceptions.c::PyErrFetchRestore
//@requires: Exceptions.c::SwapException //@requires: Exceptions.c::SwapException
//@requires: Exceptions.c::RaiseException //@requires: Exceptions.c::RaiseException
//@requires: Exceptions.c::PyErrExceptionMatches
//@requires: ObjectHandling.c::PyObjectCallMethod1 //@requires: ObjectHandling.c::PyObjectCallMethod1
//@requires: ObjectHandling.c::PyObjectGetAttrStr //@requires: ObjectHandling.c::PyObjectGetAttrStr
//@requires: CommonTypes.c::FetchCommonType //@requires: CommonTypes.c::FetchCommonType
...@@ -452,6 +451,7 @@ int __Pyx_Coroutine_CheckRunning(__pyx_CoroutineObject *gen) { ...@@ -452,6 +451,7 @@ int __Pyx_Coroutine_CheckRunning(__pyx_CoroutineObject *gen) {
static CYTHON_INLINE static CYTHON_INLINE
PyObject *__Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value) { PyObject *__Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value) {
PyObject *retval; PyObject *retval;
__Pyx_PyThreadState_declare
assert(!self->is_running); assert(!self->is_running);
...@@ -469,7 +469,7 @@ PyObject *__Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value) { ...@@ -469,7 +469,7 @@ PyObject *__Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value) {
return NULL; return NULL;
} }
__Pyx_PyThreadState_assign
if (value) { if (value) {
#if CYTHON_COMPILING_IN_PYPY #if CYTHON_COMPILING_IN_PYPY
// FIXME: what to do in PyPy? // FIXME: what to do in PyPy?
...@@ -477,13 +477,12 @@ PyObject *__Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value) { ...@@ -477,13 +477,12 @@ PyObject *__Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value) {
// Generators always return to their most recent caller, not // Generators always return to their most recent caller, not
// necessarily their creator. // necessarily their creator.
if (self->exc_traceback) { if (self->exc_traceback) {
PyThreadState *tstate = PyThreadState_GET();
PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback; PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback;
PyFrameObject *f = tb->tb_frame; PyFrameObject *f = tb->tb_frame;
Py_XINCREF(tstate->frame); Py_XINCREF($local_tstate_cname->frame);
assert(f->f_back == NULL); assert(f->f_back == NULL);
f->f_back = tstate->frame; f->f_back = $local_tstate_cname->frame;
} }
#endif #endif
__Pyx_ExceptionSwap(&self->exc_type, &self->exc_value, __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value,
...@@ -604,7 +603,7 @@ static int __Pyx_Coroutine_CloseIter(__pyx_CoroutineObject *gen, PyObject *yf) { ...@@ -604,7 +603,7 @@ static int __Pyx_Coroutine_CloseIter(__pyx_CoroutineObject *gen, PyObject *yf) {
gen->is_running = 1; gen->is_running = 1;
meth = __Pyx_PyObject_GetAttrStr(yf, PYIDENT("close")); meth = __Pyx_PyObject_GetAttrStr(yf, PYIDENT("close"));
if (unlikely(!meth)) { if (unlikely(!meth)) {
if (!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)) { if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
PyErr_WriteUnraisable(yf); PyErr_WriteUnraisable(yf);
} }
PyErr_Clear(); PyErr_Clear();
...@@ -720,7 +719,7 @@ static PyObject *__Pyx_Coroutine_Throw(PyObject *self, PyObject *args) { ...@@ -720,7 +719,7 @@ static PyObject *__Pyx_Coroutine_Throw(PyObject *self, PyObject *args) {
PyObject *meth = __Pyx_PyObject_GetAttrStr(yf, PYIDENT("throw")); PyObject *meth = __Pyx_PyObject_GetAttrStr(yf, PYIDENT("throw"));
if (unlikely(!meth)) { if (unlikely(!meth)) {
Py_DECREF(yf); Py_DECREF(yf);
if (!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)) { if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
gen->is_running = 0; gen->is_running = 0;
return NULL; return NULL;
} }
......
...@@ -5,19 +5,33 @@ ...@@ -5,19 +5,33 @@
// 'except' statement, curexc_* is moved over to exc_* by // 'except' statement, curexc_* is moved over to exc_* by
// __Pyx_GetException() // __Pyx_GetException()
/////////////// PyThreadStateGet.proto ///////////////
//@substitute: naming
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_PyThreadState_declare PyThreadState *$local_tstate_cname;
#define __Pyx_PyThreadState_assign $local_tstate_cname = PyThreadState_GET();
#else
#define __Pyx_PyThreadState_declare
#define __Pyx_PyThreadState_assign
#endif
/////////////// PyErrExceptionMatches.proto /////////////// /////////////// PyErrExceptionMatches.proto ///////////////
//@substitute: naming
#if CYTHON_COMPILING_IN_CPYTHON #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatches(PyObject* err); #define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesState(err, $local_tstate_cname)
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesState(PyObject* err, PyThreadState* tstate);
#else #else
#define __Pyx_PyErr_ExceptionMatches(exc_type) PyErr_ExceptionMatches(exc_type) #define __Pyx_PyErr_ExceptionMatches(err) PyErr_ExceptionMatches(exc_type)
#endif #endif
/////////////// PyErrExceptionMatches /////////////// /////////////// PyErrExceptionMatches ///////////////
#if CYTHON_COMPILING_IN_CPYTHON #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatches(PyObject* err) { static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesState(PyObject* err, PyThreadState* tstate) {
PyObject *exc_type = PyThreadState_GET()->curexc_type; PyObject *exc_type = tstate->curexc_type;
if (exc_type == err) return 1; if (exc_type == err) return 1;
if (unlikely(!exc_type)) return 0; if (unlikely(!exc_type)) return 0;
return PyErr_GivenExceptionMatches(exc_type, err); return PyErr_GivenExceptionMatches(exc_type, err);
...@@ -260,16 +274,25 @@ bad: ...@@ -260,16 +274,25 @@ bad:
#endif #endif
/////////////// GetException.proto /////////////// /////////////// GetException.proto ///////////////
//@substitute: naming
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_GetException(type, value, tb) __Pyx__GetException($local_tstate_cname, type, value, tb)
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); /*proto*/
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
#endif
/////////////// GetException /////////////// /////////////// GetException ///////////////
#if CYTHON_COMPILING_IN_CPYTHON
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) { static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
#endif
PyObject *local_type, *local_value, *local_tb; PyObject *local_type, *local_value, *local_tb;
#if CYTHON_COMPILING_IN_CPYTHON #if CYTHON_COMPILING_IN_CPYTHON
PyObject *tmp_type, *tmp_value, *tmp_tb; PyObject *tmp_type, *tmp_value, *tmp_tb;
PyThreadState *tstate = PyThreadState_GET();
local_type = tstate->curexc_type; local_type = tstate->curexc_type;
local_value = tstate->curexc_value; local_value = tstate->curexc_value;
local_tb = tstate->curexc_traceback; local_tb = tstate->curexc_traceback;
...@@ -363,30 +386,35 @@ static CYTHON_INLINE void __Pyx_ReraiseException(void) { ...@@ -363,30 +386,35 @@ static CYTHON_INLINE void __Pyx_ReraiseException(void) {
} }
/////////////// SaveResetException.proto /////////////// /////////////// SaveResetException.proto ///////////////
//@substitute: naming
//@requires: PyThreadStateGet
static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ #if CYTHON_COMPILING_IN_CPYTHON
static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ #define __Pyx_ExceptionSave(type, value, tb) __Pyx__ExceptionSave($local_tstate_cname, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); /*proto*/
#define __Pyx_ExceptionReset(type, value, tb) __Pyx__ExceptionReset($local_tstate_cname, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); /*proto*/
#else
#define __Pyx_ExceptionSave(type, value, tb) PyErr_GetExcInfo(type, value, tb)
#define __Pyx_ExceptionReset(type, value, tb) PyErr_SetExcInfo(type, value, tb)
#endif
/////////////// SaveResetException /////////////// /////////////// SaveResetException ///////////////
static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) {
#if CYTHON_COMPILING_IN_CPYTHON #if CYTHON_COMPILING_IN_CPYTHON
PyThreadState *tstate = PyThreadState_GET(); static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
*type = tstate->exc_type; *type = tstate->exc_type;
*value = tstate->exc_value; *value = tstate->exc_value;
*tb = tstate->exc_traceback; *tb = tstate->exc_traceback;
Py_XINCREF(*type); Py_XINCREF(*type);
Py_XINCREF(*value); Py_XINCREF(*value);
Py_XINCREF(*tb); Py_XINCREF(*tb);
#else
PyErr_GetExcInfo(type, value, tb);
#endif
} }
static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) { static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
#if CYTHON_COMPILING_IN_CPYTHON
PyObject *tmp_type, *tmp_value, *tmp_tb; PyObject *tmp_type, *tmp_value, *tmp_tb;
PyThreadState *tstate = PyThreadState_GET();
tmp_type = tstate->exc_type; tmp_type = tstate->exc_type;
tmp_value = tstate->exc_value; tmp_value = tstate->exc_value;
tmp_tb = tstate->exc_traceback; tmp_tb = tstate->exc_traceback;
...@@ -396,22 +424,25 @@ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) ...@@ -396,22 +424,25 @@ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb)
Py_XDECREF(tmp_type); Py_XDECREF(tmp_type);
Py_XDECREF(tmp_value); Py_XDECREF(tmp_value);
Py_XDECREF(tmp_tb); Py_XDECREF(tmp_tb);
#else
PyErr_SetExcInfo(type, value, tb);
#endif
} }
#endif
/////////////// SwapException.proto /////////////// /////////////// SwapException.proto ///////////////
//@substitute: naming
//@requires: PyThreadStateGet
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_ExceptionSwap(type, value, tb) __Pyx__ExceptionSwap($local_tstate_cname, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); /*proto*/
#else
static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
#endif
/////////////// SwapException /////////////// /////////////// SwapException ///////////////
static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
PyObject *tmp_type, *tmp_value, *tmp_tb;
#if CYTHON_COMPILING_IN_CPYTHON #if CYTHON_COMPILING_IN_CPYTHON
PyThreadState *tstate = PyThreadState_GET(); static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
PyObject *tmp_type, *tmp_value, *tmp_tb;
tmp_type = tstate->exc_type; tmp_type = tstate->exc_type;
tmp_value = tstate->exc_value; tmp_value = tstate->exc_value;
tmp_tb = tstate->exc_traceback; tmp_tb = tstate->exc_traceback;
...@@ -419,15 +450,23 @@ static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, ...@@ -419,15 +450,23 @@ static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value,
tstate->exc_type = *type; tstate->exc_type = *type;
tstate->exc_value = *value; tstate->exc_value = *value;
tstate->exc_traceback = *tb; tstate->exc_traceback = *tb;
*type = tmp_type;
*value = tmp_value;
*tb = tmp_tb;
}
#else #else
static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
PyObject *tmp_type, *tmp_value, *tmp_tb;
PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb); PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb);
PyErr_SetExcInfo(*type, *value, *tb); PyErr_SetExcInfo(*type, *value, *tb);
#endif
*type = tmp_type; *type = tmp_type;
*value = tmp_value; *value = tmp_value;
*tb = tmp_tb; *tb = tmp_tb;
} }
#endif
/////////////// WriteUnraisableException.proto /////////////// /////////////// WriteUnraisableException.proto ///////////////
......
...@@ -308,7 +308,6 @@ bad: ...@@ -308,7 +308,6 @@ bad:
static int __Pyx_MergeKeywords(PyObject *kwdict, PyObject *source_mapping); /*proto*/ static int __Pyx_MergeKeywords(PyObject *kwdict, PyObject *source_mapping); /*proto*/
//////////////////// MergeKeywords //////////////////// //////////////////// MergeKeywords ////////////////////
//@requires: Exceptions.c::PyErrExceptionMatches
//@requires: RaiseDoubleKeywords //@requires: RaiseDoubleKeywords
//@requires: Optimize.c::dict_iter //@requires: Optimize.c::dict_iter
...@@ -321,7 +320,7 @@ static int __Pyx_MergeKeywords(PyObject *kwdict, PyObject *source_mapping) { ...@@ -321,7 +320,7 @@ static int __Pyx_MergeKeywords(PyObject *kwdict, PyObject *source_mapping) {
if (unlikely(!iter)) { if (unlikely(!iter)) {
// slow fallback: try converting to dict, then iterate // slow fallback: try converting to dict, then iterate
PyObject *args; PyObject *args;
if (!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad; if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
PyErr_Clear(); PyErr_Clear();
args = PyTuple_Pack(1, source_mapping); args = PyTuple_Pack(1, source_mapping);
if (likely(args)) { if (likely(args)) {
......
...@@ -268,7 +268,6 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, ...@@ -268,7 +268,6 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
int is_list, int wraparound, int boundscheck); int is_list, int wraparound, int boundscheck);
/////////////// GetItemInt /////////////// /////////////// GetItemInt ///////////////
//@requires: Exceptions.c::PyErrExceptionMatches
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
PyObject *r; PyObject *r;
...@@ -325,7 +324,7 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, ...@@ -325,7 +324,7 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
i += l; i += l;
} else { } else {
// if length > max(Py_ssize_t), maybe the object can wrap around itself? // if length > max(Py_ssize_t), maybe the object can wrap around itself?
if (!__Pyx_PyErr_ExceptionMatches(PyExc_OverflowError)) if (!PyErr_ExceptionMatches(PyExc_OverflowError))
return NULL; return NULL;
PyErr_Clear(); PyErr_Clear();
} }
...@@ -354,7 +353,6 @@ static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObje ...@@ -354,7 +353,6 @@ static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObje
int is_list, int wraparound, int boundscheck); int is_list, int wraparound, int boundscheck);
/////////////// SetItemInt /////////////// /////////////// SetItemInt ///////////////
//@requires: Exceptions.c::PyErrExceptionMatches
static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) { static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) {
int r; int r;
...@@ -386,7 +384,7 @@ static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObje ...@@ -386,7 +384,7 @@ static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObje
i += l; i += l;
} else { } else {
// if length > max(Py_ssize_t), maybe the object can wrap around itself? // if length > max(Py_ssize_t), maybe the object can wrap around itself?
if (!__Pyx_PyErr_ExceptionMatches(PyExc_OverflowError)) if (!PyErr_ExceptionMatches(PyExc_OverflowError))
return -1; return -1;
PyErr_Clear(); PyErr_Clear();
} }
...@@ -420,7 +418,6 @@ static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i, ...@@ -420,7 +418,6 @@ static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i,
int is_list, int wraparound); int is_list, int wraparound);
/////////////// DelItemInt /////////////// /////////////// DelItemInt ///////////////
//@requires: Exceptions.c::PyErrExceptionMatches
static CYTHON_INLINE int __Pyx_DelItem_Generic(PyObject *o, PyObject *j) { static CYTHON_INLINE int __Pyx_DelItem_Generic(PyObject *o, PyObject *j) {
int r; int r;
...@@ -446,7 +443,7 @@ static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i, ...@@ -446,7 +443,7 @@ static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i,
i += l; i += l;
} else { } else {
// if length > max(Py_ssize_t), maybe the object can wrap around itself? // if length > max(Py_ssize_t), maybe the object can wrap around itself?
if (!__Pyx_PyErr_ExceptionMatches(PyExc_OverflowError)) if (!PyErr_ExceptionMatches(PyExc_OverflowError))
return -1; return -1;
PyErr_Clear(); PyErr_Clear();
} }
...@@ -478,7 +475,6 @@ static CYTHON_INLINE int __Pyx_PyObject_SetSlice( ...@@ -478,7 +475,6 @@ static CYTHON_INLINE int __Pyx_PyObject_SetSlice(
{{endif}} {{endif}}
/////////////// SliceObject /////////////// /////////////// SliceObject ///////////////
//@requires: Exceptions.c::PyErrExceptionMatches
{{if access == 'Get'}} {{if access == 'Get'}}
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj, static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj,
...@@ -520,7 +516,7 @@ static CYTHON_INLINE int __Pyx_PyObject_SetSlice(PyObject* obj, PyObject* value, ...@@ -520,7 +516,7 @@ static CYTHON_INLINE int __Pyx_PyObject_SetSlice(PyObject* obj, PyObject* value,
} }
} else { } else {
// if length > max(Py_ssize_t), maybe the object can wrap around itself? // if length > max(Py_ssize_t), maybe the object can wrap around itself?
if (!__Pyx_PyErr_ExceptionMatches(PyExc_OverflowError)) if (!PyErr_ExceptionMatches(PyExc_OverflowError))
goto bad; goto bad;
PyErr_Clear(); PyErr_Clear();
} }
...@@ -833,7 +829,6 @@ static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObj ...@@ -833,7 +829,6 @@ static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObj
PyObject *mkw, int calculate_metaclass, int allow_py2_metaclass); /*proto*/ PyObject *mkw, int calculate_metaclass, int allow_py2_metaclass); /*proto*/
/////////////// Py3ClassCreate /////////////// /////////////// Py3ClassCreate ///////////////
//@requires: Exceptions.c::PyErrExceptionMatches
//@requires: PyObjectGetAttrStr //@requires: PyObjectGetAttrStr
//@requires: CalculateMetaclass //@requires: CalculateMetaclass
...@@ -852,7 +847,7 @@ static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, ...@@ -852,7 +847,7 @@ static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases,
Py_DECREF(prep); Py_DECREF(prep);
Py_DECREF(pargs); Py_DECREF(pargs);
} else { } else {
if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) if (unlikely(!PyErr_ExceptionMatches(PyExc_AttributeError)))
return NULL; return NULL;
PyErr_Clear(); PyErr_Clear();
ns = PyDict_New(); ns = PyDict_New();
...@@ -884,7 +879,7 @@ static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObj ...@@ -884,7 +879,7 @@ static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObj
owned_metaclass = PyObject_GetItem(dict, PYIDENT("__metaclass__")); owned_metaclass = PyObject_GetItem(dict, PYIDENT("__metaclass__"));
if (owned_metaclass) { if (owned_metaclass) {
metaclass = owned_metaclass; metaclass = owned_metaclass;
} else if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_KeyError))) { } else if (likely(PyErr_ExceptionMatches(PyExc_KeyError))) {
PyErr_Clear(); PyErr_Clear();
} else { } else {
return NULL; return NULL;
...@@ -1496,7 +1491,6 @@ static PyObject* __Pyx_PyNumber_InPlaceMatrixMultiply(PyObject* x, PyObject* y); ...@@ -1496,7 +1491,6 @@ static PyObject* __Pyx_PyNumber_InPlaceMatrixMultiply(PyObject* x, PyObject* y);
#endif #endif
/////////////// MatrixMultiply /////////////// /////////////// MatrixMultiply ///////////////
//@requires: Exceptions.c::PyErrExceptionMatches
//@requires: PyObjectGetAttrStr //@requires: PyObjectGetAttrStr
//@requires: PyObjectCallOneArg //@requires: PyObjectCallOneArg
...@@ -1539,7 +1533,7 @@ bad: ...@@ -1539,7 +1533,7 @@ bad:
return result; \ return result; \
Py_DECREF(result); \ Py_DECREF(result); \
} else { \ } else { \
if (!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)) \ if (!PyErr_ExceptionMatches(PyExc_AttributeError)) \
return NULL; \ return NULL; \
PyErr_Clear(); \ PyErr_Clear(); \
} \ } \
......
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
(tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) { \ (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) { \
tstate->tracing++; \ tstate->tracing++; \
tstate->use_tracing = 0; \ tstate->use_tracing = 0; \
PyObject *exc_info = __Pyx_GetExceptionTuple(); \ PyObject *exc_info = __Pyx_GetExceptionTuple(tstate); \
if (exc_info) { \ if (exc_info) { \
if (CYTHON_TRACE && tstate->c_tracefunc) \ if (CYTHON_TRACE && tstate->c_tracefunc) \
tstate->c_tracefunc( \ tstate->c_tracefunc( \
......
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