[Python-checkins] bpo-39946: Remove _PyThreadState_GetFrame (GH-19094)

Victor Stinner webhook-mailer at python.org
Fri Mar 20 12:47:02 EDT 2020


https://github.com/python/cpython/commit/6723e933c4d90a408cf3818362a0e4de6d84c932
commit: 6723e933c4d90a408cf3818362a0e4de6d84c932
branch: master
author: Victor Stinner <vstinner at python.org>
committer: GitHub <noreply at github.com>
date: 2020-03-20T17:46:56+01:00
summary:

bpo-39946: Remove _PyThreadState_GetFrame (GH-19094)

Remove _PyRuntime.getframe hook and remove _PyThreadState_GetFrame
macro which was an alias to _PyRuntime.getframe. They were only
exposed by the internal C API. Remove also PyThreadFrameGetter type.

files:
A Misc/NEWS.d/next/C API/2020-03-20-17-05-52.bpo-39946.3NS-Ls.rst
M Doc/whatsnew/3.9.rst
M Include/cpython/pystate.h
M Include/internal/pycore_pystate.h
M Python/ceval.c
M Python/pystate.c
M Python/traceback.c

diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst
index 3e30f84c2ce22..5c84ca10e2037 100644
--- a/Doc/whatsnew/3.9.rst
+++ b/Doc/whatsnew/3.9.rst
@@ -533,6 +533,10 @@ Build and C API Changes
   scheduled calls.
   (Contributed by Victor Stinner in :issue:`39984`.)
 
+* Remove ``_PyRuntime.getframe`` hook and remove ``_PyThreadState_GetFrame``
+  macro which was an alias to ``_PyRuntime.getframe``. They were only exposed
+  by the internal C API. Remove also ``PyThreadFrameGetter`` type.
+  (Contributed by Victor Stinner in :issue:`39946`.)
 
 Deprecated
 ==========
diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h
index 96df0d91fb544..de3529670a845 100644
--- a/Include/cpython/pystate.h
+++ b/Include/cpython/pystate.h
@@ -179,8 +179,6 @@ PyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *);
 PyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *);
 PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
 
-typedef struct _frame *(*PyThreadFrameGetter)(PyThreadState *self_);
-
 /* Frame evaluation API */
 
 typedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, struct _frame *, int);
diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h
index 0073e205bea96..50d906c4c6dde 100644
--- a/Include/internal/pycore_pystate.h
+++ b/Include/internal/pycore_pystate.h
@@ -192,7 +192,6 @@ struct _gilstate_runtime_state {
     /* Assuming the current thread holds the GIL, this is the
        PyThreadState for the current thread. */
     _Py_atomic_address tstate_current;
-    PyThreadFrameGetter getframe;
     /* The single PyInterpreterState used by this process'
        GILState implementation
     */
@@ -201,9 +200,6 @@ struct _gilstate_runtime_state {
     Py_tss_t autoTSSkey;
 };
 
-/* hook for PyEval_GetFrame(), requested for Psyco */
-#define _PyThreadState_GetFrame _PyRuntime.gilstate.getframe
-
 /* Issue #26558: Flag to disable PyGILState_Check().
    If set to non-zero, PyGILState_Check() always return 1. */
 #define _PyGILState_check_enabled _PyRuntime.gilstate.check_enabled
diff --git a/Misc/NEWS.d/next/C API/2020-03-20-17-05-52.bpo-39946.3NS-Ls.rst b/Misc/NEWS.d/next/C API/2020-03-20-17-05-52.bpo-39946.3NS-Ls.rst
new file mode 100644
index 0000000000000..4f0e4b7c68cb0
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2020-03-20-17-05-52.bpo-39946.3NS-Ls.rst	
@@ -0,0 +1,3 @@
+Remove ``_PyRuntime.getframe`` hook and remove ``_PyThreadState_GetFrame``
+macro which was an alias to ``_PyRuntime.getframe``. They were only exposed
+by the internal C API. Remove also ``PyThreadFrameGetter`` type.
diff --git a/Python/ceval.c b/Python/ceval.c
index c80ee4b463cf7..836457d1a57a4 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4825,25 +4825,18 @@ _PyEval_GetAsyncGenFinalizer(void)
     return tstate->async_gen_finalizer;
 }
 
-static PyFrameObject *
-_PyEval_GetFrame(PyThreadState *tstate)
-{
-    _PyRuntimeState *runtime = tstate->interp->runtime;
-    return runtime->gilstate.getframe(tstate);
-}
-
 PyFrameObject *
 PyEval_GetFrame(void)
 {
     PyThreadState *tstate = _PyThreadState_GET();
-    return _PyEval_GetFrame(tstate);
+    return tstate->frame;
 }
 
 PyObject *
 PyEval_GetBuiltins(void)
 {
     PyThreadState *tstate = _PyThreadState_GET();
-    PyFrameObject *current_frame = _PyEval_GetFrame(tstate);
+    PyFrameObject *current_frame = tstate->frame;
     if (current_frame == NULL)
         return tstate->interp->builtins;
     else
@@ -4869,7 +4862,7 @@ PyObject *
 PyEval_GetLocals(void)
 {
     PyThreadState *tstate = _PyThreadState_GET();
-    PyFrameObject *current_frame = _PyEval_GetFrame(tstate);
+    PyFrameObject *current_frame = tstate->frame;
     if (current_frame == NULL) {
         _PyErr_SetString(tstate, PyExc_SystemError, "frame does not exist");
         return NULL;
@@ -4887,7 +4880,7 @@ PyObject *
 PyEval_GetGlobals(void)
 {
     PyThreadState *tstate = _PyThreadState_GET();
-    PyFrameObject *current_frame = _PyEval_GetFrame(tstate);
+    PyFrameObject *current_frame = tstate->frame;
     if (current_frame == NULL) {
         return NULL;
     }
@@ -4900,7 +4893,7 @@ int
 PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
 {
     PyThreadState *tstate = _PyThreadState_GET();
-    PyFrameObject *current_frame = _PyEval_GetFrame(tstate);
+    PyFrameObject *current_frame = tstate->frame;
     int result = cf->cf_flags != 0;
 
     if (current_frame != NULL) {
diff --git a/Python/pystate.c b/Python/pystate.c
index eea666b7e5b6d..6331a854c810f 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -546,13 +546,6 @@ PyInterpreterState_GetDict(PyInterpreterState *interp)
     return interp->dict;
 }
 
-/* Default implementation for _PyThreadState_GetFrame */
-static struct _frame *
-threadstate_getframe(PyThreadState *self)
-{
-    return self->frame;
-}
-
 static PyThreadState *
 new_threadstate(PyInterpreterState *interp, int init)
 {
@@ -562,10 +555,6 @@ new_threadstate(PyInterpreterState *interp, int init)
         return NULL;
     }
 
-    if (_PyThreadState_GetFrame == NULL) {
-        _PyThreadState_GetFrame = threadstate_getframe;
-    }
-
     tstate->interp = interp;
 
     tstate->frame = NULL;
@@ -1000,9 +989,6 @@ PyInterpreterState *
 PyThreadState_GetInterpreter(PyThreadState *tstate)
 {
     assert(tstate != NULL);
-    if (tstate == NULL) {
-        return NULL;
-    }
     return tstate->interp;
 }
 
@@ -1011,7 +997,7 @@ struct _frame*
 PyThreadState_GetFrame(PyThreadState *tstate)
 {
     assert(tstate != NULL);
-    return _PyThreadState_GetFrame(tstate);
+    return tstate->frame;
 }
 
 
diff --git a/Python/traceback.c b/Python/traceback.c
index 8aaee12031d29..f88ba1d0ad55a 100644
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -801,7 +801,7 @@ dump_traceback(int fd, PyThreadState *tstate, int write_header)
         PUTS(fd, "Stack (most recent call first):\n");
     }
 
-    frame = _PyThreadState_GetFrame(tstate);
+    frame = tstate->frame;
     if (frame == NULL) {
         PUTS(fd, "<no Python frame>\n");
         return;



More information about the Python-checkins mailing list