Skip to content

Commit 7496f95

Browse files
authored
bpo-45431: Rename CFrame to _PyCFrame in the C API (GH-31584)
Rename also struct _cframe to struct _PyCFrame. Add a comment suggesting using public functions rather than using directly the private _PyCFrame structure.
1 parent 4558af5 commit 7496f95

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

Include/cpython/pystate.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ typedef struct {
3333
PyCodeAddressRange bounds; // Only valid if code != NULL.
3434
} PyTraceInfo;
3535

36-
typedef struct _cframe {
36+
// Internal structure: you should not use it directly, but use public functions
37+
// like PyThreadState_EnterTracing() and PyThreadState_LeaveTracing().
38+
typedef struct _PyCFrame {
3739
/* This struct will be threaded through the C stack
3840
* allowing fast access to per-thread state that needs
3941
* to be accessed quickly by the interpreter, but can
@@ -47,8 +49,8 @@ typedef struct _cframe {
4749
int use_tracing;
4850
/* Pointer to the currently executing frame (it can be NULL) */
4951
struct _PyInterpreterFrame *current_frame;
50-
struct _cframe *previous;
51-
} CFrame;
52+
struct _PyCFrame *previous;
53+
} _PyCFrame;
5254

5355
typedef struct _err_stackitem {
5456
/* This struct represents a single execution context where we might
@@ -102,9 +104,9 @@ struct _ts {
102104
the trace/profile. */
103105
int tracing;
104106

105-
/* Pointer to current CFrame in the C stack frame of the currently,
107+
/* Pointer to current _PyCFrame in the C stack frame of the currently,
106108
* or most recently, executing _PyEval_EvalFrameDefault. */
107-
CFrame *cframe;
109+
_PyCFrame *cframe;
108110

109111
Py_tracefunc c_profilefunc;
110112
Py_tracefunc c_tracefunc;
@@ -196,7 +198,7 @@ struct _ts {
196198
_PyErr_StackItem exc_state;
197199

198200
/* The bottom-most frame on the stack. */
199-
CFrame root_cframe;
201+
_PyCFrame root_cframe;
200202
};
201203

202204

Include/internal/pycore_frame.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ typedef struct _PyInterpreterFrame {
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 */
62-
bool is_entry; // Whether this is the "root" frame for the current CFrame.
62+
bool is_entry; // Whether this is the "root" frame for the current _PyCFrame.
6363
bool is_generator;
6464
PyObject *localsplus[1];
6565
} _PyInterpreterFrame;

Python/ceval.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,15 +1616,15 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
16161616
int oparg; /* Current opcode argument, if any */
16171617
_Py_atomic_int * const eval_breaker = &tstate->interp->ceval.eval_breaker;
16181618

1619-
CFrame cframe;
1619+
_PyCFrame cframe;
16201620
CallShape call_shape;
16211621
call_shape.kwnames = NULL; // Borrowed reference. Reset by CALL instructions.
16221622

1623-
/* WARNING: Because the CFrame lives on the C stack,
1623+
/* WARNING: Because the _PyCFrame lives on the C stack,
16241624
* but can be accessed from a heap allocated object (tstate)
16251625
* strict stack discipline must be maintained.
16261626
*/
1627-
CFrame *prev_cframe = tstate->cframe;
1627+
_PyCFrame *prev_cframe = tstate->cframe;
16281628
cframe.use_tracing = prev_cframe->use_tracing;
16291629
cframe.previous = prev_cframe;
16301630
tstate->cframe = &cframe;

0 commit comments

Comments
 (0)