mirror of
https://github.com/python/cpython.git
synced 2025-10-21 06:02:21 +00:00
bpo-45711: use exc_value instead of exc_type to determine if exc_info is valid. Add more assertions. (GH-29627)
This commit is contained in:
parent
24c10d2943
commit
c456dfafe9
5 changed files with 93 additions and 36 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue