Thanks to visit codestin.com
Credit goes to github.com

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
remove exc_type from exc_info
  • Loading branch information
iritkatriel committed Dec 15, 2021
commit 28ce9d2fe3262a55d06c03327cd2d53f93d043db
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;
PyObject *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,12 +24,9 @@ static inline PyObject* _PyErr_Occurred(PyThreadState *tstate)

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

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('P2PP4P4c8P2iciP'))
check(get_gen(), size('P2P4P4c8P2iciP'))
# iterator
check(iter('abc'), size('lP'))
# callable-iterator
Expand Down
6 changes: 1 addition & 5 deletions Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,6 @@ FutureObj_traverse(FutureObj *fut, visitproc visit, void *arg)
Py_VISIT(fut->dict);

_PyErr_StackItem *exc_state = &fut->fut_cancelled_exc_state;
Py_VISIT(exc_state->exc_type);
Py_VISIT(exc_state->exc_value);

return 0;
Expand Down Expand Up @@ -1375,9 +1374,6 @@ _asyncio_Future__make_cancelled_error_impl(FutureObj *self)
PyException_SetContext(exc, Py_NewRef(exc_state->exc_value));
_PyErr_ClearExcState(exc_state);
}
else {
assert(exc_state->exc_type == NULL);
}

return exc;
}
Expand Down Expand Up @@ -2706,10 +2702,10 @@ task_step_impl(TaskObj *task, PyObject *exc)
PyException_SetTraceback(ev, tb);
Py_DECREF(tb);
}
Py_XDECREF(et);

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

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 @@ -25,7 +25,6 @@ static const char *ASYNC_GEN_IGNORED_EXIT_MSG =
static inline int
exc_state_traverse(_PyErr_StackItem *exc_state, visitproc visit, void *arg)
{
Py_VISIT(exc_state->exc_type);
Py_VISIT(exc_state->exc_value);
return 0;
}
Expand Down Expand Up @@ -881,7 +880,6 @@ make_gen(PyTypeObject *type, PyFunctionObject *func)
gen->gi_code = (PyCodeObject *)func->func_code;
Py_INCREF(gen->gi_code);
gen->gi_weakreflist = NULL;
gen->gi_exc_state.exc_type = NULL;
gen->gi_exc_state.exc_value = NULL;
gen->gi_exc_state.previous_item = NULL;
if (func->func_name != NULL)
Expand Down Expand Up @@ -969,7 +967,6 @@ gen_new_with_qualname(PyTypeObject *type, PyFrameObject *f,
Py_INCREF(gen->gi_code);
Py_DECREF(f);
gen->gi_weakreflist = NULL;
gen->gi_exc_state.exc_type = NULL;
gen->gi_exc_state.exc_value = NULL;
gen->gi_exc_state.previous_item = NULL;
if (name != NULL)
Expand Down
32 changes: 2 additions & 30 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2710,25 +2710,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
}

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

exc_info->exc_value = POP();

assert(exc_info->exc_value);
if (exc_info->exc_value != Py_None) {
assert(PyExceptionInstance_Check(exc_info->exc_value));
exc_info->exc_type = Py_NewRef(
PyExceptionInstance_Class(exc_info->exc_value));
}
else {
exc_info->exc_type = Py_NewRef(Py_None);
}

Py_XDECREF(type);
Py_XDECREF(value);
DISPATCH();
}
Expand All @@ -2752,20 +2738,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
traceback = PyException_GetTraceback(value);
Py_DECREF(POP()); /* lasti */
_PyErr_Restore(tstate, type, value, traceback);

exc_info = tstate->exc_info;
type = exc_info->exc_type;
value = exc_info->exc_value;
exc_info->exc_value = POP();
if (exc_info->exc_value && exc_info->exc_value != Py_None) {
assert(PyExceptionInstance_Check(exc_info->exc_value));
exc_info->exc_type = Py_NewRef(
PyExceptionInstance_Class(exc_info->exc_value));
}
else {
exc_info->exc_type = Py_NewRef(Py_None);
}

Py_XDECREF(type);
Py_XDECREF(value);
goto exception_unwind;
}
Expand Down Expand Up @@ -4483,15 +4459,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
Py_INCREF(Py_None);
SET_TOP(Py_None);
}
Py_XDECREF(exc_info->exc_type);

Py_INCREF(value);
PUSH(value);
assert(PyExceptionInstance_Check(value));

exc_info->exc_value = value;
exc_info->exc_type = Py_NewRef(
PyExceptionInstance_Class(exc_info->exc_value));

DISPATCH();
}
Expand Down
12 changes: 1 addition & 11 deletions Python/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,8 @@ _PyErr_GetTopmostException(PyThreadState *tstate)
while ((exc_info->exc_value == NULL || exc_info->exc_value == Py_None) &&
exc_info->previous_item != NULL)
{
assert(exc_info->exc_type == NULL || exc_info->exc_type == Py_None);
exc_info = exc_info->previous_item;
}
assert(exc_info->previous_item == NULL ||
(exc_info->exc_type != NULL && exc_info->exc_type != Py_None));
return exc_info;
}

Expand Down Expand Up @@ -524,22 +521,18 @@ PyErr_GetExcInfo(PyObject **p_type, PyObject **p_value, PyObject **p_traceback)
void
PyErr_SetExcInfo(PyObject *type, PyObject *value, PyObject *traceback)
{
PyObject *oldtype, *oldvalue;
PyObject *oldvalue;
PyThreadState *tstate = _PyThreadState_GET();

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


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

/* 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);
}

Expand Down Expand Up @@ -625,9 +618,6 @@ _PyErr_ChainStackItem(_PyErr_StackItem *exc_info)
exc_info_given = 1;
}

assert( (exc_info->exc_type == NULL || exc_info->exc_type == Py_None) ==
(exc_info->exc_value == NULL || exc_info->exc_value == Py_None) );

if (exc_info->exc_value == NULL || exc_info->exc_value == Py_None) {
return;
}
Expand Down
1 change: 0 additions & 1 deletion Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,6 @@ PyThreadState_Clear(PyThreadState *tstate)
Py_CLEAR(tstate->curexc_value);
Py_CLEAR(tstate->curexc_traceback);

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

/* The stack of exception states should contain just this thread. */
Expand Down