mirror of
https://github.com/python/cpython
synced 2024-09-05 00:05:39 +00:00
gh-111375: Use NULL
rather than None
in the exception stack to indicate that an exception was handled (#113302)
This commit is contained in:
parent
1ff0238594
commit
a2dd0e7038
|
@ -0,0 +1,2 @@
|
||||||
|
Only use ``NULL`` in the exception stack to indicate an exception was
|
||||||
|
handled. Patch by Carey Metcalfe.
|
|
@ -811,7 +811,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore
|
||||||
PyObject *exc = _PyFrame_StackPop(f->f_frame);
|
PyObject *exc = _PyFrame_StackPop(f->f_frame);
|
||||||
assert(PyExceptionInstance_Check(exc) || exc == Py_None);
|
assert(PyExceptionInstance_Check(exc) || exc == Py_None);
|
||||||
PyThreadState *tstate = _PyThreadState_GET();
|
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 {
|
else {
|
||||||
PyObject *v = _PyFrame_StackPop(f->f_frame);
|
PyObject *v = _PyFrame_StackPop(f->f_frame);
|
||||||
|
|
|
@ -1100,7 +1100,7 @@ dummy_func(
|
||||||
|
|
||||||
inst(POP_EXCEPT, (exc_value -- )) {
|
inst(POP_EXCEPT, (exc_value -- )) {
|
||||||
_PyErr_StackItem *exc_info = tstate->exc_info;
|
_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])) {
|
inst(RERAISE, (values[oparg], exc -- values[oparg])) {
|
||||||
|
|
|
@ -121,11 +121,11 @@ _PyErr_GetTopmostException(PyThreadState *tstate)
|
||||||
_PyErr_StackItem *exc_info = tstate->exc_info;
|
_PyErr_StackItem *exc_info = tstate->exc_info;
|
||||||
assert(exc_info);
|
assert(exc_info);
|
||||||
|
|
||||||
while ((exc_info->exc_value == NULL || exc_info->exc_value == Py_None) &&
|
while (exc_info->exc_value == NULL && exc_info->previous_item != NULL)
|
||||||
exc_info->previous_item != NULL)
|
|
||||||
{
|
{
|
||||||
exc_info = exc_info->previous_item;
|
exc_info = exc_info->previous_item;
|
||||||
}
|
}
|
||||||
|
assert(!Py_IsNone(exc_info->exc_value));
|
||||||
return exc_info;
|
return exc_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -592,7 +592,7 @@ PyErr_GetHandledException(void)
|
||||||
void
|
void
|
||||||
_PyErr_SetHandledException(PyThreadState *tstate, PyObject *exc)
|
_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
|
void
|
||||||
|
|
2
Python/executor_cases.c.h
generated
2
Python/executor_cases.c.h
generated
|
@ -806,7 +806,7 @@
|
||||||
PyObject *exc_value;
|
PyObject *exc_value;
|
||||||
exc_value = stack_pointer[-1];
|
exc_value = stack_pointer[-1];
|
||||||
_PyErr_StackItem *exc_info = tstate->exc_info;
|
_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;
|
stack_pointer += -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
2
Python/generated_cases.c.h
generated
2
Python/generated_cases.c.h
generated
|
@ -4567,7 +4567,7 @@
|
||||||
PyObject *exc_value;
|
PyObject *exc_value;
|
||||||
exc_value = stack_pointer[-1];
|
exc_value = stack_pointer[-1];
|
||||||
_PyErr_StackItem *exc_info = tstate->exc_info;
|
_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;
|
stack_pointer += -1;
|
||||||
DISPATCH();
|
DISPATCH();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue