Skip to content
Merged
Prev Previous commit
Next Next commit
Make sure that previous exc-state in thread is initialized properly.
  • Loading branch information
markshannon authored and Mark Shannon committed Oct 22, 2017
commit f2ff96e35bc3e1d93a83018e4c154cf0b4f4dc16
2 changes: 1 addition & 1 deletion Python/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback)
PyExcState *_PyErr_GetExcInfo(PyThreadState *tstate) {
PyExcState *exc_info = tstate->exc_info;
while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) &&
exc_info->exc_previous != NULL && exc_info != &tstate->exc_state)
exc_info->exc_previous != NULL)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another nit, per PEP 7 we now want to use { even for blocks with one statement.

exc_info = exc_info->exc_previous;
return exc_info;
}
Expand Down
3 changes: 2 additions & 1 deletion Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ new_threadstate(PyInterpreterState *interp, int init)
tstate->exc_state.exc_type = NULL;
tstate->exc_state.exc_value = NULL;
tstate->exc_state.exc_traceback = NULL;
tstate->exc_state.exc_previous = NULL;
tstate->exc_info = &tstate->exc_state;

tstate->c_profilefunc = NULL;
Expand Down Expand Up @@ -448,7 +449,7 @@ PyThreadState_Clear(PyThreadState *tstate)
Py_CLEAR(tstate->exc_state.exc_type);
Py_CLEAR(tstate->exc_state.exc_value);
Py_CLEAR(tstate->exc_state.exc_traceback);
assert(tstate->exc_info.exc_previous == NULL);
assert(tstate->exc_info->exc_previous == NULL);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment here?

if (Py_VerboseFlag && tstate->exc_info != &tstate->exc_state)
fprintf(stderr,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can PyErr_WarnEx() or PySys_WriteStderr() be used here?

"PyThreadState_Clear: warning: thread still has a generator\n");
Expand Down