Skip to content

Commit 6723e93

Browse files
authored
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.
1 parent fd1e1a1 commit 6723e93

File tree

7 files changed

+14
-34
lines changed

7 files changed

+14
-34
lines changed

Doc/whatsnew/3.9.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,10 @@ Build and C API Changes
533533
scheduled calls.
534534
(Contributed by Victor Stinner in :issue:`39984`.)
535535

536+
* Remove ``_PyRuntime.getframe`` hook and remove ``_PyThreadState_GetFrame``
537+
macro which was an alias to ``_PyRuntime.getframe``. They were only exposed
538+
by the internal C API. Remove also ``PyThreadFrameGetter`` type.
539+
(Contributed by Victor Stinner in :issue:`39946`.)
536540

537541
Deprecated
538542
==========

Include/cpython/pystate.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,6 @@ PyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *);
179179
PyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *);
180180
PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
181181

182-
typedef struct _frame *(*PyThreadFrameGetter)(PyThreadState *self_);
183-
184182
/* Frame evaluation API */
185183

186184
typedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, struct _frame *, int);

Include/internal/pycore_pystate.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ struct _gilstate_runtime_state {
192192
/* Assuming the current thread holds the GIL, this is the
193193
PyThreadState for the current thread. */
194194
_Py_atomic_address tstate_current;
195-
PyThreadFrameGetter getframe;
196195
/* The single PyInterpreterState used by this process'
197196
GILState implementation
198197
*/
@@ -201,9 +200,6 @@ struct _gilstate_runtime_state {
201200
Py_tss_t autoTSSkey;
202201
};
203202

204-
/* hook for PyEval_GetFrame(), requested for Psyco */
205-
#define _PyThreadState_GetFrame _PyRuntime.gilstate.getframe
206-
207203
/* Issue #26558: Flag to disable PyGILState_Check().
208204
If set to non-zero, PyGILState_Check() always return 1. */
209205
#define _PyGILState_check_enabled _PyRuntime.gilstate.check_enabled
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Remove ``_PyRuntime.getframe`` hook and remove ``_PyThreadState_GetFrame``
2+
macro which was an alias to ``_PyRuntime.getframe``. They were only exposed
3+
by the internal C API. Remove also ``PyThreadFrameGetter`` type.

Python/ceval.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4825,25 +4825,18 @@ _PyEval_GetAsyncGenFinalizer(void)
48254825
return tstate->async_gen_finalizer;
48264826
}
48274827

4828-
static PyFrameObject *
4829-
_PyEval_GetFrame(PyThreadState *tstate)
4830-
{
4831-
_PyRuntimeState *runtime = tstate->interp->runtime;
4832-
return runtime->gilstate.getframe(tstate);
4833-
}
4834-
48354828
PyFrameObject *
48364829
PyEval_GetFrame(void)
48374830
{
48384831
PyThreadState *tstate = _PyThreadState_GET();
4839-
return _PyEval_GetFrame(tstate);
4832+
return tstate->frame;
48404833
}
48414834

48424835
PyObject *
48434836
PyEval_GetBuiltins(void)
48444837
{
48454838
PyThreadState *tstate = _PyThreadState_GET();
4846-
PyFrameObject *current_frame = _PyEval_GetFrame(tstate);
4839+
PyFrameObject *current_frame = tstate->frame;
48474840
if (current_frame == NULL)
48484841
return tstate->interp->builtins;
48494842
else
@@ -4869,7 +4862,7 @@ PyObject *
48694862
PyEval_GetLocals(void)
48704863
{
48714864
PyThreadState *tstate = _PyThreadState_GET();
4872-
PyFrameObject *current_frame = _PyEval_GetFrame(tstate);
4865+
PyFrameObject *current_frame = tstate->frame;
48734866
if (current_frame == NULL) {
48744867
_PyErr_SetString(tstate, PyExc_SystemError, "frame does not exist");
48754868
return NULL;
@@ -4887,7 +4880,7 @@ PyObject *
48874880
PyEval_GetGlobals(void)
48884881
{
48894882
PyThreadState *tstate = _PyThreadState_GET();
4890-
PyFrameObject *current_frame = _PyEval_GetFrame(tstate);
4883+
PyFrameObject *current_frame = tstate->frame;
48914884
if (current_frame == NULL) {
48924885
return NULL;
48934886
}
@@ -4900,7 +4893,7 @@ int
49004893
PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
49014894
{
49024895
PyThreadState *tstate = _PyThreadState_GET();
4903-
PyFrameObject *current_frame = _PyEval_GetFrame(tstate);
4896+
PyFrameObject *current_frame = tstate->frame;
49044897
int result = cf->cf_flags != 0;
49054898

49064899
if (current_frame != NULL) {

Python/pystate.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -546,13 +546,6 @@ PyInterpreterState_GetDict(PyInterpreterState *interp)
546546
return interp->dict;
547547
}
548548

549-
/* Default implementation for _PyThreadState_GetFrame */
550-
static struct _frame *
551-
threadstate_getframe(PyThreadState *self)
552-
{
553-
return self->frame;
554-
}
555-
556549
static PyThreadState *
557550
new_threadstate(PyInterpreterState *interp, int init)
558551
{
@@ -562,10 +555,6 @@ new_threadstate(PyInterpreterState *interp, int init)
562555
return NULL;
563556
}
564557

565-
if (_PyThreadState_GetFrame == NULL) {
566-
_PyThreadState_GetFrame = threadstate_getframe;
567-
}
568-
569558
tstate->interp = interp;
570559

571560
tstate->frame = NULL;
@@ -1000,9 +989,6 @@ PyInterpreterState *
1000989
PyThreadState_GetInterpreter(PyThreadState *tstate)
1001990
{
1002991
assert(tstate != NULL);
1003-
if (tstate == NULL) {
1004-
return NULL;
1005-
}
1006992
return tstate->interp;
1007993
}
1008994

@@ -1011,7 +997,7 @@ struct _frame*
1011997
PyThreadState_GetFrame(PyThreadState *tstate)
1012998
{
1013999
assert(tstate != NULL);
1014-
return _PyThreadState_GetFrame(tstate);
1000+
return tstate->frame;
10151001
}
10161002

10171003

Python/traceback.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ dump_traceback(int fd, PyThreadState *tstate, int write_header)
801801
PUTS(fd, "Stack (most recent call first):\n");
802802
}
803803

804-
frame = _PyThreadState_GetFrame(tstate);
804+
frame = tstate->frame;
805805
if (frame == NULL) {
806806
PUTS(fd, "<no Python frame>\n");
807807
return;

0 commit comments

Comments
 (0)