Skip to content

Commit 1a5cae1

Browse files
committed
Python/ceval.c
1 parent c3a1783 commit 1a5cae1

File tree

2 files changed

+17
-34
lines changed

2 files changed

+17
-34
lines changed

Python/bytecodes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "pycore_object.h" // _PyObject_GC_TRACK()
1818
#include "pycore_moduleobject.h" // PyModuleObject
1919
#include "pycore_opcode.h" // EXTRA_CASES
20-
#include "pycore_pyerrors.h" // _PyErr_Fetch()
20+
#include "pycore_pyerrors.h" // _PyErr_GetRaisedException()
2121
#include "pycore_pymem.h" // _PyMem_IsPtrFreed()
2222
#include "pycore_pystate.h" // _PyInterpreterState_GET()
2323
#include "pycore_range.h" // _PyRangeIterObject

Python/ceval.c

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "pycore_object.h" // _PyObject_GC_TRACK()
1414
#include "pycore_moduleobject.h" // PyModuleObject
1515
#include "pycore_opcode.h" // EXTRA_CASES
16-
#include "pycore_pyerrors.h" // _PyErr_Fetch()
16+
#include "pycore_pyerrors.h" // _PyErr_Fetch(), _PyErr_GetRaisedException()
1717
#include "pycore_pymem.h" // _PyMem_IsPtrFreed()
1818
#include "pycore_pystate.h" // _PyInterpreterState_GET()
1919
#include "pycore_range.h" // _PyRangeIterObject
@@ -105,8 +105,7 @@ static void
105105
dump_stack(_PyInterpreterFrame *frame, PyObject **stack_pointer)
106106
{
107107
PyObject **stack_base = _PyFrame_Stackbase(frame);
108-
PyObject *type, *value, *traceback;
109-
PyErr_Fetch(&type, &value, &traceback);
108+
PyObject *exc = PyErr_GetRaisedException();
110109
printf(" stack=[");
111110
for (PyObject **ptr = stack_base; ptr < stack_pointer; ptr++) {
112111
if (ptr != stack_base) {
@@ -120,7 +119,7 @@ dump_stack(_PyInterpreterFrame *frame, PyObject **stack_pointer)
120119
}
121120
printf("]\n");
122121
fflush(stdout);
123-
PyErr_Restore(type, value, traceback);
122+
PyErr_SetRaisedException(exc);
124123
}
125124

126125
static void
@@ -157,8 +156,7 @@ lltrace_resume_frame(_PyInterpreterFrame *frame)
157156
return;
158157
}
159158
PyFunctionObject *f = (PyFunctionObject *)fobj;
160-
PyObject *type, *value, *traceback;
161-
PyErr_Fetch(&type, &value, &traceback);
159+
PyObject *exc = PyErr_GetRaisedException();
162160
PyObject *name = f->func_qualname;
163161
if (name == NULL) {
164162
name = f->func_name;
@@ -178,7 +176,7 @@ lltrace_resume_frame(_PyInterpreterFrame *frame)
178176
}
179177
printf("\n");
180178
fflush(stdout);
181-
PyErr_Restore(type, value, traceback);
179+
PyErr_SetRaisedException(exc);
182180
}
183181
#endif
184182
static int call_trace(Py_tracefunc, PyObject *,
@@ -1032,7 +1030,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
10321030
PyObject *v = POP();
10331031
Py_XDECREF(v);
10341032
}
1035-
PyObject *exc, *val, *tb;
10361033
if (lasti) {
10371034
int frame_lasti = _PyInterpreterFrame_LASTI(frame);
10381035
PyObject *lasti = PyLong_FromLong(frame_lasti);
@@ -1041,19 +1038,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
10411038
}
10421039
PUSH(lasti);
10431040
}
1044-
_PyErr_Fetch(tstate, &exc, &val, &tb);
1041+
10451042
/* Make the raw exception data
10461043
available to the handler,
10471044
so a program can emulate the
10481045
Python main loop. */
1049-
_PyErr_NormalizeException(tstate, &exc, &val, &tb);
1050-
if (tb != NULL)
1051-
PyException_SetTraceback(val, tb);
1052-
else
1053-
PyException_SetTraceback(val, Py_None);
1054-
Py_XDECREF(tb);
1055-
Py_XDECREF(exc);
1056-
PUSH(val);
1046+
PUSH(_PyErr_GetRaisedException(tstate));
10571047
JUMPTO(handler);
10581048
/* Resume normal execution */
10591049
DISPATCH();
@@ -2075,19 +2065,15 @@ call_trace_protected(Py_tracefunc func, PyObject *obj,
20752065
PyThreadState *tstate, _PyInterpreterFrame *frame,
20762066
int what, PyObject *arg)
20772067
{
2078-
PyObject *type, *value, *traceback;
2079-
int err;
2080-
_PyErr_Fetch(tstate, &type, &value, &traceback);
2081-
err = call_trace(func, obj, tstate, frame, what, arg);
2068+
PyObject *exc = _PyErr_GetRaisedException(tstate);
2069+
int err = call_trace(func, obj, tstate, frame, what, arg);
20822070
if (err == 0)
20832071
{
2084-
_PyErr_Restore(tstate, type, value, traceback);
2072+
_PyErr_SetRaisedException(tstate, exc);
20852073
return 0;
20862074
}
20872075
else {
2088-
Py_XDECREF(type);
2089-
Py_XDECREF(value);
2090-
Py_XDECREF(traceback);
2076+
Py_XDECREF(exc);
20912077
return -1;
20922078
}
20932079
}
@@ -2935,18 +2921,15 @@ format_exc_check_arg(PyThreadState *tstate, PyObject *exc,
29352921

29362922
if (exc == PyExc_NameError) {
29372923
// Include the name in the NameError exceptions to offer suggestions later.
2938-
PyObject *type, *value, *traceback;
2939-
PyErr_Fetch(&type, &value, &traceback);
2940-
PyErr_NormalizeException(&type, &value, &traceback);
2941-
if (PyErr_GivenExceptionMatches(value, PyExc_NameError)) {
2942-
PyNameErrorObject* exc = (PyNameErrorObject*) value;
2943-
if (exc->name == NULL) {
2924+
PyObject *exc = PyErr_GetRaisedException();
2925+
if (PyErr_GivenExceptionMatches(exc, PyExc_NameError)) {
2926+
if (((PyNameErrorObject*)exc)->name == NULL) {
29442927
// We do not care if this fails because we are going to restore the
29452928
// NameError anyway.
2946-
(void)PyObject_SetAttr(value, &_Py_ID(name), obj);
2929+
(void)PyObject_SetAttr(exc, &_Py_ID(name), obj);
29472930
}
29482931
}
2949-
PyErr_Restore(type, value, traceback);
2932+
PyErr_SetRaisedException(exc);
29502933
}
29512934
}
29522935

0 commit comments

Comments
 (0)