Commit 2d339246 authored by Thomas A Caswell's avatar Thomas A Caswell Committed by Stefan Behnel

FIX: account for change in how exception information is stored

CPython change how the exception information is stored internally in
3.7a3.

This simply adds fences based on python version around how to access
the objects.

Xref:

https://github.com/python/cpython/commit/ae3087c6382011c47db82fea4d05f8bbf514265d
https://bugs.python.org/issue25612
https://github.com/python/cpython/pull/1773
parent ce2e53c9
...@@ -359,12 +359,21 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) ...@@ -359,12 +359,21 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb)
*value = local_value; *value = local_value;
*tb = local_tb; *tb = local_tb;
#if CYTHON_FAST_THREAD_STATE #if CYTHON_FAST_THREAD_STATE
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 7
tmp_type = tstate->exc_state.exc_type;
tmp_value = tstate->exc_state.exc_value;
tmp_tb = tstate->exc_state.exc_traceback;
tstate->exc_state.exc_type = local_type;
tstate->exc_state.exc_value = local_value;
tstate->exc_state.exc_traceback = local_tb;
#else
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;
tstate->exc_type = local_type; tstate->exc_type = local_type;
tstate->exc_value = local_value; tstate->exc_value = local_value;
tstate->exc_traceback = local_tb; tstate->exc_traceback = local_tb;
#endif
// Make sure tstate is in a consistent state when we XDECREF // Make sure tstate is in a consistent state when we XDECREF
// these objects (DECREF may run arbitrary code). // these objects (DECREF may run arbitrary code).
Py_XDECREF(tmp_type); Py_XDECREF(tmp_type);
...@@ -394,9 +403,15 @@ static CYTHON_INLINE void __Pyx_ReraiseException(void) { ...@@ -394,9 +403,15 @@ static CYTHON_INLINE void __Pyx_ReraiseException(void) {
PyObject *type = NULL, *value = NULL, *tb = NULL; PyObject *type = NULL, *value = NULL, *tb = NULL;
#if CYTHON_FAST_THREAD_STATE #if CYTHON_FAST_THREAD_STATE
PyThreadState *tstate = PyThreadState_GET(); PyThreadState *tstate = PyThreadState_GET();
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 7
type = tstate->exc_state.exc_type;
value = tstate->exc_state.exc_value;
tb = tstate->exc_state.exc_traceback;
#else
type = tstate->exc_type; type = tstate->exc_type;
value = tstate->exc_value; value = tstate->exc_value;
tb = tstate->exc_traceback; tb = tstate->exc_traceback;
#endif
#else #else
PyErr_GetExcInfo(&type, &value, &tb); PyErr_GetExcInfo(&type, &value, &tb);
#endif #endif
...@@ -440,9 +455,15 @@ static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject ...@@ -440,9 +455,15 @@ static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject
#if CYTHON_FAST_THREAD_STATE #if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 7
*type = tstate->exc_state.exc_type;
*value = tstate->exc_state.exc_value;
*tb = tstate->exc_state.exc_traceback;
#else
*type = tstate->exc_type; *type = tstate->exc_type;
*value = tstate->exc_value; *value = tstate->exc_value;
*tb = tstate->exc_traceback; *tb = tstate->exc_traceback;
#endif
Py_XINCREF(*type); Py_XINCREF(*type);
Py_XINCREF(*value); Py_XINCREF(*value);
Py_XINCREF(*tb); Py_XINCREF(*tb);
...@@ -450,12 +471,22 @@ static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject * ...@@ -450,12 +471,22 @@ static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject *
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
PyObject *tmp_type, *tmp_value, *tmp_tb; PyObject *tmp_type, *tmp_value, *tmp_tb;
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 7
tmp_type = tstate->exc_state.exc_type;
tmp_value = tstate->exc_state.exc_value;
tmp_tb = tstate->exc_state.exc_traceback;
tstate->exc_state.exc_type = type;
tstate->exc_state.exc_value = value;
tstate->exc_state.exc_traceback = tb;
#else
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;
tstate->exc_type = type; tstate->exc_type = type;
tstate->exc_value = value; tstate->exc_value = value;
tstate->exc_traceback = tb; tstate->exc_traceback = tb;
#endif
Py_XDECREF(tmp_type); Py_XDECREF(tmp_type);
Py_XDECREF(tmp_value); Py_XDECREF(tmp_value);
Py_XDECREF(tmp_tb); Py_XDECREF(tmp_tb);
...@@ -478,6 +509,16 @@ static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, ...@@ -478,6 +509,16 @@ static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value,
#if CYTHON_FAST_THREAD_STATE #if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
PyObject *tmp_type, *tmp_value, *tmp_tb; PyObject *tmp_type, *tmp_value, *tmp_tb;
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 7
tmp_type = tstate->exc_state.exc_type;
tmp_value = tstate->exc_state.exc_value;
tmp_tb = tstate->exc_state.exc_traceback;
tstate->exc_state.exc_type = *type;
tstate->exc_state.exc_value = *value;
tstate->exc_state.exc_traceback = *tb;
#else
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;
...@@ -486,6 +527,7 @@ static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject * ...@@ -486,6 +527,7 @@ static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject *
tstate->exc_value = *value; tstate->exc_value = *value;
tstate->exc_traceback = *tb; tstate->exc_traceback = *tb;
#endif
*type = tmp_type; *type = tmp_type;
*value = tmp_value; *value = tmp_value;
*tb = tmp_tb; *tb = tmp_tb;
......
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