Skip to content

Commit 28ce9d2

Browse files
committed
remove exc_type from exc_info
1 parent c5c23bd commit 28ce9d2

File tree

8 files changed

+7
-56
lines changed

8 files changed

+7
-56
lines changed

Include/cpython/pystate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ typedef struct _err_stackitem {
5656
* This ensures that the exception state is not impacted by "yields"
5757
* from an except handler.
5858
*/
59-
PyObject *exc_type, *exc_value;
59+
PyObject *exc_value;
6060

6161
struct _err_stackitem *previous_item;
6262

Include/internal/pycore_pyerrors.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@ static inline PyObject* _PyErr_Occurred(PyThreadState *tstate)
2424

2525
static inline void _PyErr_ClearExcState(_PyErr_StackItem *exc_state)
2626
{
27-
PyObject *t, *v;
28-
t = exc_state->exc_type;
27+
PyObject *v;
2928
v = exc_state->exc_value;
30-
exc_state->exc_type = NULL;
3129
exc_state->exc_value = NULL;
32-
Py_XDECREF(t);
3330
Py_XDECREF(v);
3431
}
3532

Lib/test/test_sys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ def bar(cls):
13401340
check(bar, size('PP'))
13411341
# generator
13421342
def get_gen(): yield 1
1343-
check(get_gen(), size('P2PP4P4c8P2iciP'))
1343+
check(get_gen(), size('P2P4P4c8P2iciP'))
13441344
# iterator
13451345
check(iter('abc'), size('lP'))
13461346
# callable-iterator

Modules/_asynciomodule.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,6 @@ FutureObj_traverse(FutureObj *fut, visitproc visit, void *arg)
810810
Py_VISIT(fut->dict);
811811

812812
_PyErr_StackItem *exc_state = &fut->fut_cancelled_exc_state;
813-
Py_VISIT(exc_state->exc_type);
814813
Py_VISIT(exc_state->exc_value);
815814

816815
return 0;
@@ -1375,9 +1374,6 @@ _asyncio_Future__make_cancelled_error_impl(FutureObj *self)
13751374
PyException_SetContext(exc, Py_NewRef(exc_state->exc_value));
13761375
_PyErr_ClearExcState(exc_state);
13771376
}
1378-
else {
1379-
assert(exc_state->exc_type == NULL);
1380-
}
13811377

13821378
return exc;
13831379
}
@@ -2706,10 +2702,10 @@ task_step_impl(TaskObj *task, PyObject *exc)
27062702
PyException_SetTraceback(ev, tb);
27072703
Py_DECREF(tb);
27082704
}
2705+
Py_XDECREF(et);
27092706

27102707
FutureObj *fut = (FutureObj*)task;
27112708
_PyErr_StackItem *exc_state = &fut->fut_cancelled_exc_state;
2712-
exc_state->exc_type = et;
27132709
exc_state->exc_value = ev;
27142710

27152711
return future_cancel(fut, NULL);

Objects/genobject.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ static const char *ASYNC_GEN_IGNORED_EXIT_MSG =
2525
static inline int
2626
exc_state_traverse(_PyErr_StackItem *exc_state, visitproc visit, void *arg)
2727
{
28-
Py_VISIT(exc_state->exc_type);
2928
Py_VISIT(exc_state->exc_value);
3029
return 0;
3130
}
@@ -881,7 +880,6 @@ make_gen(PyTypeObject *type, PyFunctionObject *func)
881880
gen->gi_code = (PyCodeObject *)func->func_code;
882881
Py_INCREF(gen->gi_code);
883882
gen->gi_weakreflist = NULL;
884-
gen->gi_exc_state.exc_type = NULL;
885883
gen->gi_exc_state.exc_value = NULL;
886884
gen->gi_exc_state.previous_item = NULL;
887885
if (func->func_name != NULL)
@@ -969,7 +967,6 @@ gen_new_with_qualname(PyTypeObject *type, PyFrameObject *f,
969967
Py_INCREF(gen->gi_code);
970968
Py_DECREF(f);
971969
gen->gi_weakreflist = NULL;
972-
gen->gi_exc_state.exc_type = NULL;
973970
gen->gi_exc_state.exc_value = NULL;
974971
gen->gi_exc_state.previous_item = NULL;
975972
if (name != NULL)

Python/ceval.c

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,25 +2710,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
27102710
}
27112711

27122712
TARGET(POP_EXCEPT) {
2713-
PyObject *type, *value;
2713+
PyObject *value;
27142714
_PyErr_StackItem *exc_info;
27152715
exc_info = tstate->exc_info;
2716-
type = exc_info->exc_type;
27172716
value = exc_info->exc_value;
2718-
27192717
exc_info->exc_value = POP();
2720-
2721-
assert(exc_info->exc_value);
2722-
if (exc_info->exc_value != Py_None) {
2723-
assert(PyExceptionInstance_Check(exc_info->exc_value));
2724-
exc_info->exc_type = Py_NewRef(
2725-
PyExceptionInstance_Class(exc_info->exc_value));
2726-
}
2727-
else {
2728-
exc_info->exc_type = Py_NewRef(Py_None);
2729-
}
2730-
2731-
Py_XDECREF(type);
27322718
Py_XDECREF(value);
27332719
DISPATCH();
27342720
}
@@ -2752,20 +2738,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
27522738
traceback = PyException_GetTraceback(value);
27532739
Py_DECREF(POP()); /* lasti */
27542740
_PyErr_Restore(tstate, type, value, traceback);
2741+
27552742
exc_info = tstate->exc_info;
2756-
type = exc_info->exc_type;
27572743
value = exc_info->exc_value;
27582744
exc_info->exc_value = POP();
2759-
if (exc_info->exc_value && exc_info->exc_value != Py_None) {
2760-
assert(PyExceptionInstance_Check(exc_info->exc_value));
2761-
exc_info->exc_type = Py_NewRef(
2762-
PyExceptionInstance_Class(exc_info->exc_value));
2763-
}
2764-
else {
2765-
exc_info->exc_type = Py_NewRef(Py_None);
2766-
}
2767-
2768-
Py_XDECREF(type);
27692745
Py_XDECREF(value);
27702746
goto exception_unwind;
27712747
}
@@ -4483,15 +4459,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
44834459
Py_INCREF(Py_None);
44844460
SET_TOP(Py_None);
44854461
}
4486-
Py_XDECREF(exc_info->exc_type);
44874462

44884463
Py_INCREF(value);
44894464
PUSH(value);
44904465
assert(PyExceptionInstance_Check(value));
4491-
44924466
exc_info->exc_value = value;
4493-
exc_info->exc_type = Py_NewRef(
4494-
PyExceptionInstance_Class(exc_info->exc_value));
44954467

44964468
DISPATCH();
44974469
}

Python/errors.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,8 @@ _PyErr_GetTopmostException(PyThreadState *tstate)
8484
while ((exc_info->exc_value == NULL || exc_info->exc_value == Py_None) &&
8585
exc_info->previous_item != NULL)
8686
{
87-
assert(exc_info->exc_type == NULL || exc_info->exc_type == Py_None);
8887
exc_info = exc_info->previous_item;
8988
}
90-
assert(exc_info->previous_item == NULL ||
91-
(exc_info->exc_type != NULL && exc_info->exc_type != Py_None));
9289
return exc_info;
9390
}
9491

@@ -524,22 +521,18 @@ PyErr_GetExcInfo(PyObject **p_type, PyObject **p_value, PyObject **p_traceback)
524521
void
525522
PyErr_SetExcInfo(PyObject *type, PyObject *value, PyObject *traceback)
526523
{
527-
PyObject *oldtype, *oldvalue;
524+
PyObject *oldvalue;
528525
PyThreadState *tstate = _PyThreadState_GET();
529526

530-
oldtype = tstate->exc_info->exc_type;
531527
oldvalue = tstate->exc_info->exc_value;
532528

533529

534-
tstate->exc_info->exc_type = get_exc_type(value);
535-
Py_XINCREF(tstate->exc_info->exc_type);
536530
tstate->exc_info->exc_value = value;
537531

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

542-
Py_XDECREF(oldtype);
543536
Py_XDECREF(oldvalue);
544537
}
545538

@@ -625,9 +618,6 @@ _PyErr_ChainStackItem(_PyErr_StackItem *exc_info)
625618
exc_info_given = 1;
626619
}
627620

628-
assert( (exc_info->exc_type == NULL || exc_info->exc_type == Py_None) ==
629-
(exc_info->exc_value == NULL || exc_info->exc_value == Py_None) );
630-
631621
if (exc_info->exc_value == NULL || exc_info->exc_value == Py_None) {
632622
return;
633623
}

Python/pystate.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,6 @@ PyThreadState_Clear(PyThreadState *tstate)
10281028
Py_CLEAR(tstate->curexc_value);
10291029
Py_CLEAR(tstate->curexc_traceback);
10301030

1031-
Py_CLEAR(tstate->exc_state.exc_type);
10321031
Py_CLEAR(tstate->exc_state.exc_value);
10331032

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

0 commit comments

Comments
 (0)