FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-45711: assert that the type of exc_info is redundant by iritkatriel · Pull Request #29518 · python/cpython · GitHub

/ cpython Public
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension .c  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Next Next commit
bpo-45711: assert that the type of exc_info is redundant
  • Loading branch information
iritkatriel committed Nov 10, 2021
commit d7c8d15e2b558e2e6e4c8b78148908f387be09f8
19 changes: 19 additions & 0 deletions Python/ceval.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,17 @@ match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
static int do_raise(PyThreadState *tstate, PyObject *exc, PyObject *cause);
static int unpack_iterable(PyThreadState *, PyObject *, int, int, PyObject **);

static void
_assert_exception_type_is_redundant(PyObject* type, PyObject* val)
{
if (type == NULL || type == Py_None) {
assert(val == NULL || val == Py_None);
}
else {
assert(PyExceptionInstance_Check(val));
assert(PyExceptionInstance_Class(val) == type);
}
}

PyObject *
PyEval_EvalCode(PyObject *co, PyObject *globals, PyObject *locals)
Expand Down Expand Up @@ -2847,6 +2858,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
exc_info->exc_type = POP();
exc_info->exc_value = POP();
exc_info->exc_traceback = POP();
_assert_exception_type_is_redundant(exc_info->exc_type, exc_info->exc_value);
Py_XDECREF(type);
Py_XDECREF(value);
Py_XDECREF(traceback);
Expand All @@ -2868,6 +2880,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
type = POP();
value = POP();
traceback = POP();
_assert_exception_type_is_redundant(type, value);
Py_DECREF(POP()); /* lasti */
_PyErr_Restore(tstate, type, value, traceback);
exc_info = tstate->exc_info;
Expand All @@ -2877,6 +2890,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
exc_info->exc_type = POP();
exc_info->exc_value = POP();
exc_info->exc_traceback = POP();
_assert_exception_type_is_redundant(exc_info->exc_type, exc_info->exc_value);
Py_XDECREF(type);
Py_XDECREF(value);
Py_XDECREF(traceback);
Expand All @@ -2899,6 +2913,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
PyObject *exc = POP();
PyObject *val = POP();
PyObject *tb = POP();
_assert_exception_type_is_redundant(exc, val);
assert(PyExceptionClass_Check(exc));
_PyErr_Restore(tstate, exc, val, tb);
goto exception_unwind;
Expand All @@ -2908,6 +2923,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
PyObject *exc = POP();
PyObject *val = POP();
PyObject *tb = POP();
_assert_exception_type_is_redundant(exc, val);
assert(PyExceptionClass_Check(exc));
if (PyErr_GivenExceptionMatches(exc, PyExc_StopAsyncIteration)) {
Py_DECREF(exc);
Expand Down Expand Up @@ -4362,6 +4378,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
exc = TOP();
val = SECOND();
tb = THIRD();
_assert_exception_type_is_redundant(exc, val);
assert(!Py_IsNone(exc));
assert(!PyLong_Check(exc));
assert(PyLong_Check(PEEK(7)));
Expand All @@ -4380,6 +4397,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
PyObject *type = TOP();
PyObject *value = SECOND();
PyObject *tb = THIRD();
_assert_exception_type_is_redundant(type, value);
_PyErr_StackItem *exc_info = tstate->exc_info;
SET_THIRD(exc_info->exc_traceback);
SET_SECOND(exc_info->exc_value);
Expand Down Expand Up @@ -5238,6 +5256,7 @@ MISS_WITH_OPARG_COUNTER(BINARY_MULTIPLY)
PUSH(tb);
PUSH(val);
PUSH(exc);
_assert_exception_type_is_redundant(exc, val);
JUMPTO(handler);
/* Resume normal execution */
frame->f_state = FRAME_EXECUTING;
Expand Down

Back | FazBrowse Home | New Git URL