Skip to content

Commit 74f076e

Browse files
iritkatrielwarsaw
authored andcommitted
pythongh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives (python#102760)
1 parent ea7d6fe commit 74f076e

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Python/traceback.c

+10-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "pycore_interp.h" // PyInterpreterState.gc
1212
#include "pycore_parser.h" // _PyParser_ASTFromString
1313
#include "pycore_pyarena.h" // _PyArena_Free()
14-
#include "pycore_pyerrors.h" // _PyErr_Fetch()
14+
#include "pycore_pyerrors.h" // _PyErr_GetRaisedException()
1515
#include "pycore_pystate.h" // _PyThreadState_GET()
1616
#include "pycore_traceback.h" // EXCEPTION_TB_HEADER
1717

@@ -242,17 +242,18 @@ _PyTraceBack_FromFrame(PyObject *tb_next, PyFrameObject *frame)
242242
int
243243
PyTraceBack_Here(PyFrameObject *frame)
244244
{
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);
248250
if (newtb == NULL) {
249-
_PyErr_ChainExceptions(exc, val, tb);
251+
_PyErr_ChainExceptions1(exc);
250252
return -1;
251253
}
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);
256257
return 0;
257258
}
258259

0 commit comments

Comments
 (0)