Message412292
> __Pyx_PyErr_GetTopmostException(PyThreadState *tstate)
Python provides a *private* _PyErr_GetTopmostException(tstate) function, but Cython reimplements its own function. I'm not sure why.
GH-30531 proposes adding PyErr_GetActiveException() function which has no parameter, but Cython __Pyx_PyErr_GetTopmostException() has a tstate parameter.
Simplified example numpy/random/_mt19937.c code:
static CYTHON_INLINE void
__Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type,
PyObject **value, PyObject **tb)
{
_PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate);
*type = exc_info->exc_type;
*value = exc_info->exc_value;
*tb = exc_info->exc_traceback;
Py_XINCREF(*type);
Py_XINCREF(*value);
Py_XINCREF(*tb);
}
static CYTHON_INLINE void
__Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type,
PyObject *value, PyObject *tb)
{
PyObject *tmp_type, *tmp_value, *tmp_tb;
_PyErr_StackItem *exc_info = tstate->exc_info;
tmp_type = exc_info->exc_type;
tmp_value = exc_info->exc_value;
tmp_tb = exc_info->exc_traceback;
exc_info->exc_type = type;
exc_info->exc_value = value;
exc_info->exc_traceback = tb;
Py_XDECREF(tmp_type);
Py_XDECREF(tmp_value);
Py_XDECREF(tmp_tb);
}
Cython saves/restores the current exception of tstate. Maybe we need to provide a high-level API for that as well? |
|
Date |
User |
Action |
Args |
2022-02-01 17:08:38 | vstinner | set | recipients:
+ vstinner, gvanrossum, terry.reedy, scoder, Mark.Shannon, brandtbucher, iritkatriel |
2022-02-01 17:08:38 | vstinner | set | messageid: <1643735318.52.0.758250758908.issue45711@roundup.psfhosted.org> |
2022-02-01 17:08:38 | vstinner | link | issue45711 messages |
2022-02-01 17:08:38 | vstinner | create | |
|