|
11 | 11 | #include "pycore_interp.h" // PyInterpreterState.gc
|
12 | 12 | #include "pycore_parser.h" // _PyParser_ASTFromString
|
13 | 13 | #include "pycore_pyarena.h" // _PyArena_Free()
|
14 |
| -#include "pycore_pyerrors.h" // _PyErr_Fetch() |
| 14 | +#include "pycore_pyerrors.h" // _PyErr_GetRaisedException() |
15 | 15 | #include "pycore_pystate.h" // _PyThreadState_GET()
|
16 | 16 | #include "pycore_traceback.h" // EXCEPTION_TB_HEADER
|
17 | 17 |
|
@@ -242,17 +242,18 @@ _PyTraceBack_FromFrame(PyObject *tb_next, PyFrameObject *frame)
|
242 | 242 | int
|
243 | 243 | PyTraceBack_Here(PyFrameObject *frame)
|
244 | 244 | {
|
245 |
| - PyObject *exc, *val, *tb, *newtb; |
246 |
| - PyErr_Fetch(&exc, &val, &tb); |
247 |
| - newtb = _PyTraceBack_FromFrame(tb, frame); |
| 245 | + PyObject *exc = PyErr_GetRaisedException(); |
| 246 | + assert(PyExceptionInstance_Check(exc)); |
| 247 | + PyObject *tb = PyException_GetTraceback(exc); |
| 248 | + PyObject *newtb = _PyTraceBack_FromFrame(tb, frame); |
| 249 | + Py_XDECREF(tb); |
248 | 250 | if (newtb == NULL) {
|
249 |
| - _PyErr_ChainExceptions(exc, val, tb); |
| 251 | + _PyErr_ChainExceptions1(exc); |
250 | 252 | return -1;
|
251 | 253 | }
|
252 |
| - assert(PyExceptionInstance_Check(val)); |
253 |
| - PyException_SetTraceback(val, newtb); |
254 |
| - PyErr_Restore(exc, val, newtb); |
255 |
| - Py_XDECREF(tb); |
| 254 | + PyException_SetTraceback(exc, newtb); |
| 255 | + Py_XDECREF(newtb); |
| 256 | + PyErr_SetRaisedException(exc); |
256 | 257 | return 0;
|
257 | 258 | }
|
258 | 259 |
|
|
0 commit comments