[Python-checkins] bpo-45953: Preserve backward compatibility on some PyThreadState field names. (GH-31038)

miss-islington webhook-mailer at python.org
Tue Feb 1 12:02:42 EST 2022


https://github.com/python/cpython/commit/f78be59c83c151d94902daef56218530c52e29e7
commit: f78be59c83c151d94902daef56218530c52e29e7
branch: main
author: Eric Snow <ericsnowcurrently at gmail.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-02-01T09:02:25-08:00
summary:

bpo-45953: Preserve backward compatibility on some PyThreadState field names. (GH-31038)



The gevent project is using the two `PyThreadState` fields I renamed in gh-30590.  This PR fixes the names.  See #msg412046.

files:
M Include/cpython/pystate.h
M Python/pystate.c

diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h
index a35e5b803bd08..74dd44d6edccb 100644
--- a/Include/cpython/pystate.h
+++ b/Include/cpython/pystate.h
@@ -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;
 };
 
 
diff --git a/Python/pystate.c b/Python/pystate.c
index 4b698f2b1d771..4378d78a8b781 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -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;
@@ -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");
     }



More information about the Python-checkins mailing list