Skip to content

Commit 87af12b

Browse files
authored
bpo-46836: Rename InterpreterFrame to _PyInterpreterFrame (pythonGH-31583)
Rename also struct _interpreter_frame to struct _PyInterpreterFrame. Reduce risk of name conflicts if a project includes pycore_frame.h.
1 parent f780d96 commit 87af12b

15 files changed

+138
-138
lines changed

Include/cpython/ceval.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ PyAPI_FUNC(PyObject *) _PyEval_GetBuiltinId(_Py_Identifier *);
2222
flag was set, else return 0. */
2323
PyAPI_FUNC(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf);
2424

25-
PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(PyThreadState *tstate, struct _interpreter_frame *f, int exc);
25+
PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(PyThreadState *tstate, struct _PyInterpreterFrame *f, int exc);
2626

2727
PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds);
2828
PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void);

Include/cpython/pystate.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ typedef struct _cframe {
4646
*/
4747
int use_tracing;
4848
/* Pointer to the currently executing frame (it can be NULL) */
49-
struct _interpreter_frame *current_frame;
49+
struct _PyInterpreterFrame *current_frame;
5050
struct _cframe *previous;
5151
} CFrame;
5252

@@ -258,7 +258,7 @@ PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
258258

259259
/* Frame evaluation API */
260260

261-
typedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, struct _interpreter_frame *, int);
261+
typedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, struct _PyInterpreterFrame *, int);
262262

263263
PyAPI_FUNC(_PyFrameEvalFunction) _PyInterpreterState_GetEvalFrameFunc(
264264
PyInterpreterState *interp);

Include/internal/pycore_ceval.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extern PyObject *_PyEval_BuiltinsFromGlobals(
4747

4848

4949
static inline PyObject*
50-
_PyEval_EvalFrame(PyThreadState *tstate, struct _interpreter_frame *frame, int throwflag)
50+
_PyEval_EvalFrame(PyThreadState *tstate, struct _PyInterpreterFrame *frame, int throwflag)
5151
{
5252
if (tstate->interp->eval_frame == NULL) {
5353
return _PyEval_EvalFrameDefault(tstate, frame, throwflag);
@@ -116,7 +116,7 @@ static inline void _Py_LeaveRecursiveCall_inline(void) {
116116

117117
#define Py_LeaveRecursiveCall() _Py_LeaveRecursiveCall_inline()
118118

119-
struct _interpreter_frame *_PyEval_GetFrame(void);
119+
struct _PyInterpreterFrame *_PyEval_GetFrame(void);
120120

121121
PyObject *_Py_MakeCoro(PyFunctionObject *func);
122122

Include/internal/pycore_frame.h

+29-29
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extern "C" {
99
struct _frame {
1010
PyObject_HEAD
1111
PyFrameObject *f_back; /* previous frame, or NULL */
12-
struct _interpreter_frame *f_frame; /* points to the frame data */
12+
struct _PyInterpreterFrame *f_frame; /* points to the frame data */
1313
PyObject *f_trace; /* Trace function */
1414
int f_lineno; /* Current line number. Only valid if non-zero */
1515
char f_trace_lines; /* Emit per-line trace events? */
@@ -48,63 +48,63 @@ typedef signed char PyFrameState;
4848
unless it's -1 in which case next_instr should be first_instr.
4949
*/
5050

51-
typedef struct _interpreter_frame {
51+
typedef struct _PyInterpreterFrame {
5252
PyFunctionObject *f_func; /* Strong reference */
5353
PyObject *f_globals; /* Borrowed reference */
5454
PyObject *f_builtins; /* Borrowed reference */
5555
PyObject *f_locals; /* Strong reference, may be NULL */
5656
PyCodeObject *f_code; /* Strong reference */
5757
PyFrameObject *frame_obj; /* Strong reference, may be NULL */
58-
struct _interpreter_frame *previous;
58+
struct _PyInterpreterFrame *previous;
5959
int f_lasti; /* Last instruction if called */
6060
int stacktop; /* Offset of TOS from localsplus */
6161
PyFrameState f_state; /* What state the frame is in */
6262
bool is_entry; // Whether this is the "root" frame for the current CFrame.
6363
bool is_generator;
6464
PyObject *localsplus[1];
65-
} InterpreterFrame;
65+
} _PyInterpreterFrame;
6666

67-
static inline int _PyFrame_IsRunnable(InterpreterFrame *f) {
67+
static inline int _PyFrame_IsRunnable(_PyInterpreterFrame *f) {
6868
return f->f_state < FRAME_EXECUTING;
6969
}
7070

71-
static inline int _PyFrame_IsExecuting(InterpreterFrame *f) {
71+
static inline int _PyFrame_IsExecuting(_PyInterpreterFrame *f) {
7272
return f->f_state == FRAME_EXECUTING;
7373
}
7474

75-
static inline int _PyFrameHasCompleted(InterpreterFrame *f) {
75+
static inline int _PyFrameHasCompleted(_PyInterpreterFrame *f) {
7676
return f->f_state > FRAME_EXECUTING;
7777
}
7878

79-
static inline PyObject **_PyFrame_Stackbase(InterpreterFrame *f) {
79+
static inline PyObject **_PyFrame_Stackbase(_PyInterpreterFrame *f) {
8080
return f->localsplus + f->f_code->co_nlocalsplus;
8181
}
8282

83-
static inline PyObject *_PyFrame_StackPeek(InterpreterFrame *f) {
83+
static inline PyObject *_PyFrame_StackPeek(_PyInterpreterFrame *f) {
8484
assert(f->stacktop > f->f_code->co_nlocalsplus);
8585
assert(f->localsplus[f->stacktop-1] != NULL);
8686
return f->localsplus[f->stacktop-1];
8787
}
8888

89-
static inline PyObject *_PyFrame_StackPop(InterpreterFrame *f) {
89+
static inline PyObject *_PyFrame_StackPop(_PyInterpreterFrame *f) {
9090
assert(f->stacktop > f->f_code->co_nlocalsplus);
9191
f->stacktop--;
9292
return f->localsplus[f->stacktop];
9393
}
9494

95-
static inline void _PyFrame_StackPush(InterpreterFrame *f, PyObject *value) {
95+
static inline void _PyFrame_StackPush(_PyInterpreterFrame *f, PyObject *value) {
9696
f->localsplus[f->stacktop] = value;
9797
f->stacktop++;
9898
}
9999

100-
#define FRAME_SPECIALS_SIZE ((sizeof(InterpreterFrame)-1)/sizeof(PyObject *))
100+
#define FRAME_SPECIALS_SIZE ((sizeof(_PyInterpreterFrame)-1)/sizeof(PyObject *))
101101

102-
void _PyFrame_Copy(InterpreterFrame *src, InterpreterFrame *dest);
102+
void _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *dest);
103103

104104
/* Consumes reference to func */
105105
static inline void
106106
_PyFrame_InitializeSpecials(
107-
InterpreterFrame *frame, PyFunctionObject *func,
107+
_PyInterpreterFrame *frame, PyFunctionObject *func,
108108
PyObject *locals, int nlocalsplus)
109109
{
110110
frame->f_func = func;
@@ -124,33 +124,33 @@ _PyFrame_InitializeSpecials(
124124
* that precedes this frame.
125125
*/
126126
static inline PyObject**
127-
_PyFrame_GetLocalsArray(InterpreterFrame *frame)
127+
_PyFrame_GetLocalsArray(_PyInterpreterFrame *frame)
128128
{
129129
return frame->localsplus;
130130
}
131131

132132
static inline PyObject**
133-
_PyFrame_GetStackPointer(InterpreterFrame *frame)
133+
_PyFrame_GetStackPointer(_PyInterpreterFrame *frame)
134134
{
135135
return frame->localsplus+frame->stacktop;
136136
}
137137

138138
static inline void
139-
_PyFrame_SetStackPointer(InterpreterFrame *frame, PyObject **stack_pointer)
139+
_PyFrame_SetStackPointer(_PyInterpreterFrame *frame, PyObject **stack_pointer)
140140
{
141141
frame->stacktop = (int)(stack_pointer - frame->localsplus);
142142
}
143143

144144
/* For use by _PyFrame_GetFrameObject
145145
Do not call directly. */
146146
PyFrameObject *
147-
_PyFrame_MakeAndSetFrameObject(InterpreterFrame *frame);
147+
_PyFrame_MakeAndSetFrameObject(_PyInterpreterFrame *frame);
148148

149149
/* Gets the PyFrameObject for this frame, lazily
150150
* creating it if necessary.
151151
* Returns a borrowed referennce */
152152
static inline PyFrameObject *
153-
_PyFrame_GetFrameObject(InterpreterFrame *frame)
153+
_PyFrame_GetFrameObject(_PyInterpreterFrame *frame)
154154
{
155155
PyFrameObject *res = frame->frame_obj;
156156
if (res != NULL) {
@@ -160,7 +160,7 @@ _PyFrame_GetFrameObject(InterpreterFrame *frame)
160160
}
161161

162162
/* Clears all references in the frame.
163-
* If take is non-zero, then the InterpreterFrame frame
163+
* If take is non-zero, then the _PyInterpreterFrame frame
164164
* may be transferred to the frame object it references
165165
* instead of being cleared. Either way
166166
* the caller no longer owns the references
@@ -169,21 +169,21 @@ _PyFrame_GetFrameObject(InterpreterFrame *frame)
169169
* frames like the ones in generators and coroutines.
170170
*/
171171
void
172-
_PyFrame_Clear(InterpreterFrame * frame);
172+
_PyFrame_Clear(_PyInterpreterFrame * frame);
173173

174174
int
175-
_PyFrame_Traverse(InterpreterFrame *frame, visitproc visit, void *arg);
175+
_PyFrame_Traverse(_PyInterpreterFrame *frame, visitproc visit, void *arg);
176176

177177
int
178-
_PyFrame_FastToLocalsWithError(InterpreterFrame *frame);
178+
_PyFrame_FastToLocalsWithError(_PyInterpreterFrame *frame);
179179

180180
void
181-
_PyFrame_LocalsToFast(InterpreterFrame *frame, int clear);
181+
_PyFrame_LocalsToFast(_PyInterpreterFrame *frame, int clear);
182182

183-
extern InterpreterFrame *
183+
extern _PyInterpreterFrame *
184184
_PyThreadState_BumpFramePointerSlow(PyThreadState *tstate, size_t size);
185185

186-
static inline InterpreterFrame *
186+
static inline _PyInterpreterFrame *
187187
_PyThreadState_BumpFramePointer(PyThreadState *tstate, size_t size)
188188
{
189189
PyObject **base = tstate->datastack_top;
@@ -192,16 +192,16 @@ _PyThreadState_BumpFramePointer(PyThreadState *tstate, size_t size)
192192
assert(tstate->datastack_limit);
193193
if (top < tstate->datastack_limit) {
194194
tstate->datastack_top = top;
195-
return (InterpreterFrame *)base;
195+
return (_PyInterpreterFrame *)base;
196196
}
197197
}
198198
return _PyThreadState_BumpFramePointerSlow(tstate, size);
199199
}
200200

201-
void _PyThreadState_PopFrame(PyThreadState *tstate, InterpreterFrame *frame);
201+
void _PyThreadState_PopFrame(PyThreadState *tstate, _PyInterpreterFrame *frame);
202202

203203
/* Consume reference to func */
204-
InterpreterFrame *
204+
_PyInterpreterFrame *
205205
_PyFrame_Push(PyThreadState *tstate, PyFunctionObject *func);
206206

207207
#ifdef __cplusplus

Modules/_tracemalloc.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ hashtable_compare_traceback(const void *key1, const void *key2)
305305

306306

307307
static void
308-
tracemalloc_get_frame(InterpreterFrame *pyframe, frame_t *frame)
308+
tracemalloc_get_frame(_PyInterpreterFrame *pyframe, frame_t *frame)
309309
{
310310
frame->filename = &_Py_STR(anon_unknown);
311311
int lineno = PyCode_Addr2Line(pyframe->f_code, pyframe->f_lasti*sizeof(_Py_CODEUNIT));
@@ -399,7 +399,7 @@ traceback_get_frames(traceback_t *traceback)
399399
return;
400400
}
401401

402-
InterpreterFrame *pyframe = tstate->cframe->current_frame;
402+
_PyInterpreterFrame *pyframe = tstate->cframe->current_frame;
403403
for (; pyframe != NULL;) {
404404
if (traceback->nframe < _Py_tracemalloc_config.max_nframe) {
405405
tracemalloc_get_frame(pyframe, &traceback->frames[traceback->nframe]);
@@ -410,7 +410,7 @@ traceback_get_frames(traceback_t *traceback)
410410
traceback->total_nframe++;
411411
}
412412

413-
InterpreterFrame *back = pyframe->previous;
413+
_PyInterpreterFrame *back = pyframe->previous;
414414
pyframe = back;
415415
}
416416
}

Modules/_xxsubinterpretersmodule.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,7 @@ _is_running(PyInterpreterState *interp)
18391839
}
18401840

18411841
assert(!PyErr_Occurred());
1842-
InterpreterFrame *frame = tstate->cframe->current_frame;
1842+
_PyInterpreterFrame *frame = tstate->cframe->current_frame;
18431843
if (frame == NULL) {
18441844
return 0;
18451845
}

Modules/signalmodule.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "pycore_call.h" // _PyObject_Call()
99
#include "pycore_ceval.h" // _PyEval_SignalReceived()
1010
#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
11-
#include "pycore_frame.h" // InterpreterFrame
11+
#include "pycore_frame.h" // _PyInterpreterFrame
1212
#include "pycore_moduleobject.h" // _PyModule_GetState()
1313
#include "pycore_pyerrors.h" // _PyErr_SetString()
1414
#include "pycore_pylifecycle.h" // NSIG
@@ -1809,7 +1809,7 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate)
18091809
*/
18101810
_Py_atomic_store(&is_tripped, 0);
18111811

1812-
InterpreterFrame *frame = tstate->cframe->current_frame;
1812+
_PyInterpreterFrame *frame = tstate->cframe->current_frame;
18131813
signal_state_t *state = &signal_global_state;
18141814
for (int i = 1; i < NSIG; i++) {
18151815
if (!_Py_atomic_load_relaxed(&Handlers[i].tripped)) {

Objects/frameobject.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,8 @@ frame_dealloc(PyFrameObject *f)
629629
/* Kill all local variables including specials, if we own them */
630630
if (f->f_owns_frame) {
631631
f->f_owns_frame = 0;
632-
assert(f->f_frame == (InterpreterFrame *)f->_f_frame_data);
633-
InterpreterFrame *frame = (InterpreterFrame *)f->_f_frame_data;
632+
assert(f->f_frame == (_PyInterpreterFrame *)f->_f_frame_data);
633+
_PyInterpreterFrame *frame = (_PyInterpreterFrame *)f->_f_frame_data;
634634
/* Don't clear code object until the end */
635635
co = frame->f_code;
636636
frame->f_code = NULL;
@@ -707,7 +707,7 @@ static PyObject *
707707
frame_sizeof(PyFrameObject *f, PyObject *Py_UNUSED(ignored))
708708
{
709709
Py_ssize_t res;
710-
res = offsetof(PyFrameObject, _f_frame_data) + offsetof(InterpreterFrame, localsplus);
710+
res = offsetof(PyFrameObject, _f_frame_data) + offsetof(_PyInterpreterFrame, localsplus);
711711
PyCodeObject *code = f->f_frame->f_code;
712712
res += (code->co_nlocalsplus+code->co_stacksize) * sizeof(PyObject *);
713713
return PyLong_FromSsize_t(res);
@@ -738,7 +738,7 @@ PyTypeObject PyFrame_Type = {
738738
PyVarObject_HEAD_INIT(&PyType_Type, 0)
739739
"frame",
740740
offsetof(PyFrameObject, _f_frame_data) +
741-
offsetof(InterpreterFrame, localsplus),
741+
offsetof(_PyInterpreterFrame, localsplus),
742742
sizeof(PyObject *),
743743
(destructor)frame_dealloc, /* tp_dealloc */
744744
0, /* tp_vectorcall_offset */
@@ -771,7 +771,7 @@ PyTypeObject PyFrame_Type = {
771771
};
772772

773773
static void
774-
init_frame(InterpreterFrame *frame, PyFunctionObject *func, PyObject *locals)
774+
init_frame(_PyInterpreterFrame *frame, PyFunctionObject *func, PyObject *locals)
775775
{
776776
/* _PyFrame_InitializeSpecials consumes reference to func */
777777
Py_INCREF(func);
@@ -827,16 +827,16 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code,
827827
Py_DECREF(func);
828828
return NULL;
829829
}
830-
init_frame((InterpreterFrame *)f->_f_frame_data, func, locals);
831-
f->f_frame = (InterpreterFrame *)f->_f_frame_data;
830+
init_frame((_PyInterpreterFrame *)f->_f_frame_data, func, locals);
831+
f->f_frame = (_PyInterpreterFrame *)f->_f_frame_data;
832832
f->f_owns_frame = 1;
833833
Py_DECREF(func);
834834
_PyObject_GC_TRACK(f);
835835
return f;
836836
}
837837

838838
static int
839-
_PyFrame_OpAlreadyRan(InterpreterFrame *frame, int opcode, int oparg)
839+
_PyFrame_OpAlreadyRan(_PyInterpreterFrame *frame, int opcode, int oparg)
840840
{
841841
const _Py_CODEUNIT *code =
842842
(const _Py_CODEUNIT *)PyBytes_AS_STRING(frame->f_code->co_code);
@@ -849,7 +849,7 @@ _PyFrame_OpAlreadyRan(InterpreterFrame *frame, int opcode, int oparg)
849849
}
850850

851851
int
852-
_PyFrame_FastToLocalsWithError(InterpreterFrame *frame) {
852+
_PyFrame_FastToLocalsWithError(_PyInterpreterFrame *frame) {
853853
/* Merge fast locals into f->f_locals */
854854
PyObject *locals;
855855
PyObject **fast;
@@ -960,7 +960,7 @@ PyFrame_FastToLocals(PyFrameObject *f)
960960
}
961961

962962
void
963-
_PyFrame_LocalsToFast(InterpreterFrame *frame, int clear)
963+
_PyFrame_LocalsToFast(_PyInterpreterFrame *frame, int clear)
964964
{
965965
/* Merge locals into fast locals */
966966
PyObject *locals;

0 commit comments

Comments
 (0)