diff options
-rw-r--r-- | Include/cpython/pyerrors.h | 1 | ||||
-rw-r--r-- | Misc/NEWS.d/next/C API/2019-12-30-10-43-52.bpo-39164.WEV0uu.rst | 1 | ||||
-rw-r--r-- | Python/errors.c | 14 |
3 files changed, 12 insertions, 4 deletions
diff --git a/Include/cpython/pyerrors.h b/Include/cpython/pyerrors.h index e3098b3925..f8480fb79e 100644 --- a/Include/cpython/pyerrors.h +++ b/Include/cpython/pyerrors.h @@ -76,6 +76,7 @@ typedef PyOSErrorObject PyWindowsErrorObject; PyAPI_FUNC(void) _PyErr_SetKeyError(PyObject *); _PyErr_StackItem *_PyErr_GetTopmostException(PyThreadState *tstate); +PyAPI_FUNC(void) _PyErr_GetExcInfo(PyThreadState *, PyObject **, PyObject **, PyObject **); /* Context manipulation (PEP 3134) */ diff --git a/Misc/NEWS.d/next/C API/2019-12-30-10-43-52.bpo-39164.WEV0uu.rst b/Misc/NEWS.d/next/C API/2019-12-30-10-43-52.bpo-39164.WEV0uu.rst new file mode 100644 index 0000000000..bb72ac70d5 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2019-12-30-10-43-52.bpo-39164.WEV0uu.rst @@ -0,0 +1 @@ +Add a private ``_PyErr_GetExcInfo()`` function to retrieve exception information of the specified Python thread state. diff --git a/Python/errors.c b/Python/errors.c index d65707e7f9..cdb4460505 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -433,21 +433,27 @@ PyErr_Clear(void) void -PyErr_GetExcInfo(PyObject **p_type, PyObject **p_value, PyObject **p_traceback) +_PyErr_GetExcInfo(PyThreadState *tstate, + PyObject **p_type, PyObject **p_value, PyObject **p_traceback) { - PyThreadState *tstate = _PyThreadState_GET(); - _PyErr_StackItem *exc_info = _PyErr_GetTopmostException(tstate); *p_type = exc_info->exc_type; *p_value = exc_info->exc_value; *p_traceback = exc_info->exc_traceback; - Py_XINCREF(*p_type); Py_XINCREF(*p_value); Py_XINCREF(*p_traceback); } + +void +PyErr_GetExcInfo(PyObject **p_type, PyObject **p_value, PyObject **p_traceback) +{ + PyThreadState *tstate = _PyThreadState_GET(); + return _PyErr_GetExcInfo(tstate, p_type, p_value, p_traceback); +} + void PyErr_SetExcInfo(PyObject *p_type, PyObject *p_value, PyObject *p_traceback) { |