mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives (#102760)
This commit is contained in:
parent
0f175766e2
commit
6372e290c0
1 changed files with 10 additions and 9 deletions
|
@ -11,7 +11,7 @@
|
||||||
#include "pycore_interp.h" // PyInterpreterState.gc
|
#include "pycore_interp.h" // PyInterpreterState.gc
|
||||||
#include "pycore_parser.h" // _PyParser_ASTFromString
|
#include "pycore_parser.h" // _PyParser_ASTFromString
|
||||||
#include "pycore_pyarena.h" // _PyArena_Free()
|
#include "pycore_pyarena.h" // _PyArena_Free()
|
||||||
#include "pycore_pyerrors.h" // _PyErr_Fetch()
|
#include "pycore_pyerrors.h" // _PyErr_GetRaisedException()
|
||||||
#include "pycore_pystate.h" // _PyThreadState_GET()
|
#include "pycore_pystate.h" // _PyThreadState_GET()
|
||||||
#include "pycore_traceback.h" // EXCEPTION_TB_HEADER
|
#include "pycore_traceback.h" // EXCEPTION_TB_HEADER
|
||||||
|
|
||||||
|
@ -242,17 +242,18 @@ _PyTraceBack_FromFrame(PyObject *tb_next, PyFrameObject *frame)
|
||||||
int
|
int
|
||||||
PyTraceBack_Here(PyFrameObject *frame)
|
PyTraceBack_Here(PyFrameObject *frame)
|
||||||
{
|
{
|
||||||
PyObject *exc, *val, *tb, *newtb;
|
PyObject *exc = PyErr_GetRaisedException();
|
||||||
PyErr_Fetch(&exc, &val, &tb);
|
assert(PyExceptionInstance_Check(exc));
|
||||||
newtb = _PyTraceBack_FromFrame(tb, frame);
|
PyObject *tb = PyException_GetTraceback(exc);
|
||||||
|
PyObject *newtb = _PyTraceBack_FromFrame(tb, frame);
|
||||||
|
Py_XDECREF(tb);
|
||||||
if (newtb == NULL) {
|
if (newtb == NULL) {
|
||||||
_PyErr_ChainExceptions(exc, val, tb);
|
_PyErr_ChainExceptions1(exc);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
assert(PyExceptionInstance_Check(val));
|
PyException_SetTraceback(exc, newtb);
|
||||||
PyException_SetTraceback(val, newtb);
|
Py_XDECREF(newtb);
|
||||||
PyErr_Restore(exc, val, newtb);
|
PyErr_SetRaisedException(exc);
|
||||||
Py_XDECREF(tb);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue