--- /dev/null
+Only use ``NULL`` in the exception stack to indicate an exception was
+handled. Patch by Carey Metcalfe.
PyObject *exc = _PyFrame_StackPop(f->f_frame);
assert(PyExceptionInstance_Check(exc) || exc == Py_None);
PyThreadState *tstate = _PyThreadState_GET();
- Py_XSETREF(tstate->exc_info->exc_value, exc);
+ Py_XSETREF(tstate->exc_info->exc_value, exc == Py_None ? NULL : exc);
}
else {
PyObject *v = _PyFrame_StackPop(f->f_frame);
inst(POP_EXCEPT, (exc_value -- )) {
_PyErr_StackItem *exc_info = tstate->exc_info;
- Py_XSETREF(exc_info->exc_value, exc_value);
+ Py_XSETREF(exc_info->exc_value, exc_value == Py_None ? NULL : exc_value);
}
inst(RERAISE, (values[oparg], exc -- values[oparg])) {
_PyErr_StackItem *exc_info = tstate->exc_info;
assert(exc_info);
- while ((exc_info->exc_value == NULL || exc_info->exc_value == Py_None) &&
- exc_info->previous_item != NULL)
+ while (exc_info->exc_value == NULL && exc_info->previous_item != NULL)
{
exc_info = exc_info->previous_item;
}
+ assert(!Py_IsNone(exc_info->exc_value));
return exc_info;
}
void
_PyErr_SetHandledException(PyThreadState *tstate, PyObject *exc)
{
- Py_XSETREF(tstate->exc_info->exc_value, Py_XNewRef(exc));
+ Py_XSETREF(tstate->exc_info->exc_value, Py_XNewRef(exc == Py_None ? NULL : exc));
}
void
PyObject *exc_value;
exc_value = stack_pointer[-1];
_PyErr_StackItem *exc_info = tstate->exc_info;
- Py_XSETREF(exc_info->exc_value, exc_value);
+ Py_XSETREF(exc_info->exc_value, exc_value == Py_None ? NULL : exc_value);
stack_pointer += -1;
break;
}
PyObject *exc_value;
exc_value = stack_pointer[-1];
_PyErr_StackItem *exc_info = tstate->exc_info;
- Py_XSETREF(exc_info->exc_value, exc_value);
+ Py_XSETREF(exc_info->exc_value, exc_value == Py_None ? NULL : exc_value);
stack_pointer += -1;
DISPATCH();
}