Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a2dd0e7

Browse files
authored
gh-111375: Use NULL rather than None in the exception stack to indicate that an exception was handled (#113302)
1 parent 1ff0238 commit a2dd0e7

File tree

6 files changed

+9
-7
lines changed

6 files changed

+9
-7
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Only use ``NULL`` in the exception stack to indicate an exception was
2+
handled. Patch by Carey Metcalfe.

Objects/frameobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore
811811
PyObject *exc = _PyFrame_StackPop(f->f_frame);
812812
assert(PyExceptionInstance_Check(exc) || exc == Py_None);
813813
PyThreadState *tstate = _PyThreadState_GET();
814-
Py_XSETREF(tstate->exc_info->exc_value, exc);
814+
Py_XSETREF(tstate->exc_info->exc_value, exc == Py_None ? NULL : exc);
815815
}
816816
else {
817817
PyObject *v = _PyFrame_StackPop(f->f_frame);

Python/bytecodes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ dummy_func(
11001100

11011101
inst(POP_EXCEPT, (exc_value -- )) {
11021102
_PyErr_StackItem *exc_info = tstate->exc_info;
1103-
Py_XSETREF(exc_info->exc_value, exc_value);
1103+
Py_XSETREF(exc_info->exc_value, exc_value == Py_None ? NULL : exc_value);
11041104
}
11051105

11061106
inst(RERAISE, (values[oparg], exc -- values[oparg])) {

Python/errors.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ _PyErr_GetTopmostException(PyThreadState *tstate)
121121
_PyErr_StackItem *exc_info = tstate->exc_info;
122122
assert(exc_info);
123123

124-
while ((exc_info->exc_value == NULL || exc_info->exc_value == Py_None) &&
125-
exc_info->previous_item != NULL)
124+
while (exc_info->exc_value == NULL && exc_info->previous_item != NULL)
126125
{
127126
exc_info = exc_info->previous_item;
128127
}
128+
assert(!Py_IsNone(exc_info->exc_value));
129129
return exc_info;
130130
}
131131

@@ -592,7 +592,7 @@ PyErr_GetHandledException(void)
592592
void
593593
_PyErr_SetHandledException(PyThreadState *tstate, PyObject *exc)
594594
{
595-
Py_XSETREF(tstate->exc_info->exc_value, Py_XNewRef(exc));
595+
Py_XSETREF(tstate->exc_info->exc_value, Py_XNewRef(exc == Py_None ? NULL : exc));
596596
}
597597

598598
void

Python/executor_cases.c.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)