Skip to content

Commit

Permalink
bpo-45953: Preserve backward compatibility on some PyThreadState fiel…
Browse files Browse the repository at this point in the history
…d names. (GH-31038)

The gevent project is using the two `PyThreadState` fields I renamed in gh-30590.  This PR fixes the names.  See #msg412046.
  • Loading branch information
ericsnowcurrently authored Feb 1, 2022
1 parent 64568ac commit f78be59
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions Include/cpython/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,19 @@ struct _ts {
/* The following fields are here to avoid allocation during init.
The data is exposed through PyThreadState pointer fields.
These fields should not be accessed directly outside of init.
This is indicated by an underscore prefix on the field names.
All other PyInterpreterState pointer fields are populated when
needed and default to NULL.
*/
// Note some fields do not have a leading underscore for backward
// compatibility. See https://bugs.python.org/issue45953#msg412046.

/* The thread's exception stack entry. (Always the last entry.) */
_PyErr_StackItem _exc_state;
_PyErr_StackItem exc_state;

/* The bottom-most frame on the stack. */
CFrame _root_cframe;
CFrame root_cframe;
};


Expand Down
8 changes: 4 additions & 4 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,9 @@ init_threadstate(PyThreadState *tstate,
tstate->recursion_limit = interp->ceval.recursion_limit,
tstate->recursion_remaining = interp->ceval.recursion_limit,

tstate->exc_info = &tstate->_exc_state;
tstate->exc_info = &tstate->exc_state;

tstate->cframe = &tstate->_root_cframe;
tstate->cframe = &tstate->root_cframe;
tstate->datastack_chunk = NULL;
tstate->datastack_top = NULL;
tstate->datastack_limit = NULL;
Expand Down Expand Up @@ -1016,10 +1016,10 @@ PyThreadState_Clear(PyThreadState *tstate)
Py_CLEAR(tstate->curexc_value);
Py_CLEAR(tstate->curexc_traceback);

Py_CLEAR(tstate->_exc_state.exc_value);
Py_CLEAR(tstate->exc_state.exc_value);

/* The stack of exception states should contain just this thread. */
if (verbose && tstate->exc_info != &tstate->_exc_state) {
if (verbose && tstate->exc_info != &tstate->exc_state) {
fprintf(stderr,
"PyThreadState_Clear: warning: thread still has a generator\n");
}
Expand Down

0 comments on commit f78be59

Please sign in to comment.