Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bpo-45711: remove exc_traceback from _PyErr_StackItem
  • Loading branch information
iritkatriel committed Dec 15, 2021
commit 37c7f12e5379c834168f01acefd761141741c912
2 changes: 1 addition & 1 deletion Include/cpython/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ typedef struct _err_stackitem {
* This ensures that the exception state is not impacted by "yields"
* from an except handler.
*/
PyObject *exc_type, *exc_value, *exc_traceback;
PyObject *exc_type, *exc_value;

struct _err_stackitem *previous_item;

Expand Down
5 changes: 1 addition & 4 deletions Include/internal/pycore_pyerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@ static inline PyObject* _PyErr_Occurred(PyThreadState *tstate)

static inline void _PyErr_ClearExcState(_PyErr_StackItem *exc_state)
{
PyObject *t, *v, *tb;
PyObject *t, *v;
t = exc_state->exc_type;
v = exc_state->exc_value;
tb = exc_state->exc_traceback;
exc_state->exc_type = NULL;
exc_state->exc_value = NULL;
exc_state->exc_traceback = NULL;
Py_XDECREF(t);
Py_XDECREF(v);
Py_XDECREF(tb);
}

PyAPI_FUNC(PyObject*) _PyErr_StackItemToExcInfoTuple(
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ def bar(cls):
check(bar, size('PP'))
# generator
def get_gen(): yield 1
check(get_gen(), size('P2PPP4P4c8P2iciP'))
check(get_gen(), size('P2PP4P4c8P2iciP'))
# iterator
check(iter('abc'), size('lP'))
# callable-iterator
Expand Down
4 changes: 1 addition & 3 deletions Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,6 @@ FutureObj_traverse(FutureObj *fut, visitproc visit, void *arg)
_PyErr_StackItem *exc_state = &fut->fut_cancelled_exc_state;
Py_VISIT(exc_state->exc_type);
Py_VISIT(exc_state->exc_value);
Py_VISIT(exc_state->exc_traceback);

return 0;
}
Expand Down Expand Up @@ -1378,7 +1377,6 @@ _asyncio_Future__make_cancelled_error_impl(FutureObj *self)
}
else {
assert(exc_state->exc_type == NULL);
assert(exc_state->exc_traceback == NULL);
}

return exc;
Expand Down Expand Up @@ -2706,13 +2704,13 @@ task_step_impl(TaskObj *task, PyObject *exc)
PyErr_NormalizeException(&et, &ev, &tb);
if (tb != NULL) {
PyException_SetTraceback(ev, tb);
Py_DECREF(tb);
}

FutureObj *fut = (FutureObj*)task;
_PyErr_StackItem *exc_state = &fut->fut_cancelled_exc_state;
exc_state->exc_type = et;
exc_state->exc_value = ev;
exc_state->exc_traceback = tb;

return future_cancel(fut, NULL);
}
Expand Down
3 changes: 0 additions & 3 deletions Objects/genobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ exc_state_traverse(_PyErr_StackItem *exc_state, visitproc visit, void *arg)
{
Py_VISIT(exc_state->exc_type);
Py_VISIT(exc_state->exc_value);
Py_VISIT(exc_state->exc_traceback);
return 0;
}

Expand Down Expand Up @@ -884,7 +883,6 @@ make_gen(PyTypeObject *type, PyFunctionObject *func)
gen->gi_weakreflist = NULL;
gen->gi_exc_state.exc_type = NULL;
gen->gi_exc_state.exc_value = NULL;
gen->gi_exc_state.exc_traceback = NULL;
gen->gi_exc_state.previous_item = NULL;
if (func->func_name != NULL)
gen->gi_name = func->func_name;
Expand Down Expand Up @@ -973,7 +971,6 @@ gen_new_with_qualname(PyTypeObject *type, PyFrameObject *f,
gen->gi_weakreflist = NULL;
gen->gi_exc_state.exc_type = NULL;
gen->gi_exc_state.exc_value = NULL;
gen->gi_exc_state.exc_traceback = NULL;
gen->gi_exc_state.previous_item = NULL;
if (name != NULL)
gen->gi_name = name;
Expand Down
26 changes: 1 addition & 25 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2728,28 +2728,17 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
}

TARGET(POP_EXCEPT) {
PyObject *type, *value, *traceback;
PyObject *type, *value;
_PyErr_StackItem *exc_info;
exc_info = tstate->exc_info;
type = exc_info->exc_type;
value = exc_info->exc_value;
traceback = exc_info->exc_traceback;

exc_info->exc_type = POP();
exc_info->exc_value = POP();

assert(exc_info->exc_value);
if (exc_info->exc_value != Py_None) {
exc_info->exc_traceback = PyException_GetTraceback(exc_info->exc_value);
}
else {
exc_info->exc_traceback = NULL;
}

ASSERT_EXC_TYPE_IS_REDUNDANT(exc_info->exc_type, exc_info->exc_value);
Py_XDECREF(type);
Py_XDECREF(value);
Py_XDECREF(traceback);
DISPATCH();
}

Expand All @@ -2776,21 +2765,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
exc_info = tstate->exc_info;
type = exc_info->exc_type;
value = exc_info->exc_value;
traceback = exc_info->exc_traceback;
exc_info->exc_type = POP();
exc_info->exc_value = POP();

assert(exc_info->exc_value);
if (exc_info->exc_value != Py_None) {
exc_info->exc_traceback = PyException_GetTraceback(exc_info->exc_value);
}
else {
exc_info->exc_traceback = NULL;
}
ASSERT_EXC_TYPE_IS_REDUNDANT(exc_info->exc_type, exc_info->exc_value);
Py_XDECREF(type);
Py_XDECREF(value);
Py_XDECREF(traceback);
goto exception_unwind;
}

Expand Down Expand Up @@ -4510,12 +4490,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
TARGET(PUSH_EXC_INFO) {
PyObject *type = TOP();
PyObject *value = SECOND();
assert(value && PyExceptionInstance_Check(value));
PyObject *tb = PyException_GetTraceback(value);
ASSERT_EXC_TYPE_IS_REDUNDANT(type, value);

_PyErr_StackItem *exc_info = tstate->exc_info;
Py_XDECREF(exc_info->exc_traceback);
if (exc_info->exc_value != NULL) {
SET_SECOND(exc_info->exc_value);
}
Expand All @@ -4530,7 +4507,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
Py_INCREF(Py_None);
SET_TOP(Py_None);
}
exc_info->exc_traceback = tb;

Py_INCREF(value);
PUSH(value);
Expand Down
12 changes: 5 additions & 7 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -3292,18 +3292,16 @@ compiler_try_star_finally(struct compiler *c, stmt_ty s)
[] POP_BLOCK
[] JUMP_FORWARD L0

[tb, val, exc] L1: <evaluate E1> )
[tb, val, exc, E1] JUMP_IF_NOT_EXC_MATCH L2 ) only if E1
[tb, val, exc] POP
[tb, val] <assign to V1> (or POP if no V1)
[tb] POP
[exc] L1: <evaluate E1> )
Comment thread
iritkatriel marked this conversation as resolved.
Outdated
[exc, E1] JUMP_IF_NOT_EXC_MATCH L2 ) only if E1
[exc] <assign to V1> (or POP if no V1)
[] <code for S1>
JUMP_FORWARD L0

[tb, val, exc] L2: <evaluate E2>
[exc] L2: <evaluate E2>
.............................etc.......................

[tb, val, exc] Ln+1: RERAISE # re-raise exception
[exc] Ln+1: RERAISE # re-raise exception

[] L0: <next statement>

Expand Down
6 changes: 1 addition & 5 deletions Python/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,27 +524,23 @@ PyErr_GetExcInfo(PyObject **p_type, PyObject **p_value, PyObject **p_traceback)
void
PyErr_SetExcInfo(PyObject *type, PyObject *value, PyObject *traceback)
{
PyObject *oldtype, *oldvalue, *oldtraceback;
PyObject *oldtype, *oldvalue;
PyThreadState *tstate = _PyThreadState_GET();

oldtype = tstate->exc_info->exc_type;
oldvalue = tstate->exc_info->exc_value;
oldtraceback = tstate->exc_info->exc_traceback;


tstate->exc_info->exc_type = get_exc_type(value);
Py_XINCREF(tstate->exc_info->exc_type);
tstate->exc_info->exc_value = value;
tstate->exc_info->exc_traceback = get_exc_traceback(value);
Py_XINCREF(tstate->exc_info->exc_traceback);

/* These args are no longer used, but we still need to steal a ref */
Py_XDECREF(type);
Py_XDECREF(traceback);

Py_XDECREF(oldtype);
Py_XDECREF(oldvalue);
Py_XDECREF(oldtraceback);
}


Expand Down
1 change: 0 additions & 1 deletion Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,6 @@ PyThreadState_Clear(PyThreadState *tstate)

Py_CLEAR(tstate->exc_state.exc_type);
Py_CLEAR(tstate->exc_state.exc_value);
Py_CLEAR(tstate->exc_state.exc_traceback);

/* The stack of exception states should contain just this thread. */
if (verbose && tstate->exc_info != &tstate->exc_state) {
Expand Down