This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients Mark.Shannon, brandtbucher, gvanrossum, iritkatriel, scoder, terry.reedy, vstinner
Date 2022-02-01.17:08:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1643735318.52.0.758250758908.issue45711@roundup.psfhosted.org>
In-reply-to
Content
> __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?
History
Date User Action Args
2022-02-01 17:08:38vstinnersetrecipients: + vstinner, gvanrossum, terry.reedy, scoder, Mark.Shannon, brandtbucher, iritkatriel
2022-02-01 17:08:38vstinnersetmessageid: <1643735318.52.0.758250758908.issue45711@roundup.psfhosted.org>
2022-02-01 17:08:38vstinnerlinkissue45711 messages
2022-02-01 17:08:38vstinnercreate