diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2021-11-25 09:41:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-25 09:41:28 (GMT) |
commit | c456dfafe9f9f6614fbcf2213a93707f0e101f4e (patch) | |
tree | 4c83ea059d9dc4eefe8d7e0a414e824c786c5128 /Python/ceval.c | |
parent | 24c10d2943c482c4d3ecc71d45df2d8c10fa5bb1 (diff) | |
download | cpython-c456dfafe9f9f6614fbcf2213a93707f0e101f4e.zip cpython-c456dfafe9f9f6614fbcf2213a93707f0e101f4e.tar.gz cpython-c456dfafe9f9f6614fbcf2213a93707f0e101f4e.tar.bz2 |
bpo-45711: use exc_value instead of exc_type to determine if exc_info is valid. Add more assertions. (GH-29627)
Diffstat (limited to 'Python/ceval.c')
-rw-r--r-- | Python/ceval.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 0aec5aa..9beb1a4 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -1102,7 +1102,7 @@ static void _assert_exception_type_is_redundant(PyObject* type, PyObject* val) { if (type == NULL || type == Py_None) { - assert(val == NULL || val == Py_None); + assert(val == type); } else { assert(PyExceptionInstance_Check(val)); @@ -3738,7 +3738,9 @@ check_eval_breaker: TARGET(JUMP_IF_NOT_EXC_MATCH) { PyObject *right = POP(); - PyObject *left = TOP(); + ASSERT_EXC_TYPE_IS_REDUNDANT(TOP(), SECOND()); + PyObject *left = SECOND(); + assert(PyExceptionInstance_Check(left)); if (check_except_type_valid(tstate, right) < 0) { Py_DECREF(right); goto error; @@ -4198,7 +4200,13 @@ check_eval_breaker: ASSERT_EXC_TYPE_IS_REDUNDANT(type, value); _PyErr_StackItem *exc_info = tstate->exc_info; SET_THIRD(exc_info->exc_traceback); - SET_SECOND(exc_info->exc_value); + if (exc_info->exc_value != NULL) { + SET_SECOND(exc_info->exc_value); + } + else { + Py_INCREF(Py_None); + SET_SECOND(Py_None); + } if (exc_info->exc_type != NULL) { SET_TOP(exc_info->exc_type); } @@ -5916,7 +5924,9 @@ do_raise(PyThreadState *tstate, PyObject *exc, PyObject *cause) type = exc_info->exc_type; value = exc_info->exc_value; tb = exc_info->exc_traceback; - if (Py_IsNone(type) || type == NULL) { + assert(((Py_IsNone(value) || value == NULL)) == + ((Py_IsNone(type) || type == NULL))); + if (Py_IsNone(value) || value == NULL) { _PyErr_SetString(tstate, PyExc_RuntimeError, "No active exception to reraise"); return 0; |