bpo-45711: use exc_value instead of exc_type to determine if exc_info is valid. Add more assertions. by iritkatriel · Pull Request #29627 · python/cpython (original) (raw)
I noticed that in some places you require type and value to be both "nullish" or both "not nullish" (where "nullish" means either NULL or Py_None), and in other places (in particular in
_assert_exception_type_is_redundant()
) they are required to both be the same nullishness (i.e., both NULL or both Py_None or neither of them nullish). Is there a reason for the difference?
Yes. Most of these assertions are verifying that the change right next to them is valid. So if I replace if(exc_type is nullish)
by if(exc_value is nullish)
then I only care that their nullishness is the same. In the case of the triplets pushed to the stack, it used to be that no-exc was pushed as "NULL, NULL, None" (None for type, NULL for value and tb). I change that in this PR (ceval.c lines 5907-9 sorry - 4182-88) so now it's "NULL, None, None". There are places where "None at the top of the stack" means there is no exc_info. So when we will remove the type we need the value to be None and not NULL, otherwise we'll get segfaults.