8000 WIP bpo-44800: Rename `_PyInterpreterFrame` to `_Py_framedata` by ncoghlan · Pull Request #27525 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

WIP bpo-44800: Rename _PyInterpreterFrame to _Py_framedata #27525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a133e0d
bpo-44800: Clearly distinguish execution & introspection frames
ncoghlan Aug 1, 2021
d8858aa
'frame' and 'frame data' replaces introspection and execution frames
ncoghlan Aug 14, 2021
cd340b0
Merge remote-tracking branch 'origin/main' into bpo-44800-rename-inte…
ncoghlan Aug 14, 2021
ccf953b
Tweak some comments
ncoghlan Aug 14, 2021
4a097bd
Another comment fix
ncoghlan Aug 14, 2021
bd00490
Fix LLTRACE macro compile error
ncoghlan Aug 14, 2021
04aa7e8
Revert unintended function name changes
ncoghlan Aug 14, 2021
e9018e7
Fix comment alignment
ncoghlan Aug 14, 2021
0ce41c8
Follow proposed new naming conventions in gdb hooks
ncoghlan Aug 14, 2021
c269e1f
Merge remote-tracking branch 'origin/main' into bpo-44800-rename-inte…
ncoghlan Aug 21, 2021
4eeff9a
Reduce conflicts for main branch merge
ncoghlan Mar 6, 2022
6fa0f53
Fix bad search & replace
ncoghlan Mar 6, 2022
776ca80
main branch has no underscore
ncoghlan Mar 6, 2022
8000
682af23
Reduce function header conflicts
ncoghlan Mar 6, 2022
c76e63b
Yet more merge conflict reduction
ncoghlan Mar 6, 2022
b1d1438
Merged and compiles, naming is inconsistent
ncoghlan Mar 6, 2022
cae935d
Reinstate _Py_framedata struct rename
ncoghlan Mar 6, 2022
2866bfa
Fix type declaration for gen/coro frame data
ncoghlan Mar 6, 2022
239a62f
Document frame related naming conventions
ncoghlan Mar 6, 2022
2680f35
Migrate gen/coro iframe field to fdata naming convention
ncoghlan Mar 6, 2022
ebda1d3
Use fdata for frame data locals and parameters
ncoghlan Mar 12, 2022
269a4a0
frame -> fdata in ceval.c & allow compilation
ncoghlan Mar 12, 2022
34cf023
Disambiguate f_fdata and f_frame_data
ncoghlan Mar 12, 2022
55d9276
Merge remote-tracking branch 'origin/main' into bpo-44800-rename-inte…
ncoghlan Mar 12, 2022
3eba918
Document the currently implemented conventions
ncoghlan Mar 12, 2022
e8a4adf
Note the 'current_frame' exception
ncoghlan Mar 12, 2022
3d654a0
Fix test_gdb
ncoghlan Mar 12, 2022
b09b114
Fix header file include guard var
ncoghlan Mar 12, 2022
9b51976
Distinguish frame state error messages
ncoghlan Mar 12, 2022
0a3611c
super() does not access C frame structs
ncoghlan Mar 12, 2022
08410cc
new_frame -> new_fdata in frame push
ncoghlan Mar 12, 2022
c694768
Add missing error check in PyImport_Import
ncoghlan Mar 12, 2022
ba87ef3
No Python frame seems legit for PyImport_Import()
ncoghlan Mar 12, 2022
7168f7d
Get test_gdb passing locally
ncoghlan Mar 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use fdata for frame data locals and parameters
  • Loading branch information
ncoghlan committed Mar 12, 2022
commit ebda1d308426d09109360a7895e035d6bcd1352f
2 changes: 1 addition & 1 deletion Include/cpython/ceval.h
8000
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ PyAPI_FUNC(PyObject *) _PyEval_GetBuiltinId(_Py_Identifier *);
flag was set, else return 0. */
PyAPI_FUNC(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf);

PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(PyThreadState *tstate, struct _Py_framedata *f, int exc);
PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(PyThreadState *tstate, struct _Py_framedata *fdata, int exc);

PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds);
PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void);
Expand Down
6 changes: 3 additions & 3 deletions Include/internal/pycore_ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ extern PyObject *_PyEval_BuiltinsFromGlobals(


static inline PyObject*
_PyEval_EvalFrame(PyThreadState *tstate, struct _Py_framedata *frame, int throwflag)
_PyEval_EvalFrame(PyThreadState *tstate, struct _Py_framedata *fdata, int throwflag)
{
if (tstate->interp->eval_frame == NULL) {
return _PyEval_EvalFrameDefault(tstate, frame, throwflag);
return _PyEval_EvalFrameDefault(tstate, fdata, throwflag);
}
return tstate->interp->eval_frame(tstate, frame, throwflag);
return tstate->interp->eval_frame(tstate, fdata, throwflag);
}

extern PyObject *
Expand Down
54 changes: 27 additions & 27 deletions Include/internal/pycore_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ static inline PyObject *_PyFrame_StackPop(_Py_framedata *f) {
return f->localsplus[f->stacktop];
}

static inline void _PyFrame_StackPush(_Py_framedata *f, PyObject *value) {
f->localsplus[f->stacktop] = value;
f->stacktop++;
static inline void _PyFrame_StackPush(_Py_framedata *fdata, PyObject *value) {
fdata->localsplus[fdata->stacktop] = value;
fdata->stacktop++;
}

#define FRAME_SPECIALS_SIZE ((sizeof(_Py_framedata)-1)/sizeof(PyObject *))
Expand All @@ -135,47 +135,47 @@ void _PyFrame_Copy(_Py_framedata *src, _Py_framedata *dest);
/* Consumes reference to func */
static inline void
_PyFrame_InitializeSpecials(
_Py_framedata *frame, PyFunctionObject *func,
_Py_framedata *fdata, PyFunctionObject *func,
PyObject *locals, int nlocalsplus)
{
frame->func = func;
frame->code = (PyCodeObject *)Py_NewRef(func->func_code);
frame->builtins = func->func_builtins;
frame->globals = func->func_globals;
frame->locals = Py_XNewRef(locals);
frame->stacktop = nlocalsplus;
frame->frame_obj = NULL;
frame->lasti = -1;
frame->state = FRAME_CREATED;
frame->is_entry = false;
frame->is_generator = false;
fdata->func = func;
fdata->code = (PyCodeObject *)Py_NewRef(func->func_code);
fdata->builtins = func->func_builtins;
fdata->globals = func->func_globals;
fdata->locals = Py_XNewRef(locals);
fdata->stacktop = nlocalsplus;
fdata->frame_obj = NULL;
fdata->lasti = -1;
fdata->state = FRAME_CREATED;
fdata->is_entry = false;
fdata->is_generator = false;
}

/* Gets the pointer to the locals array
* that precedes this frame.
*/
static inline PyObject**
_PyFrame_GetLocalsArray(_Py_framedata *frame)
_PyFrame_GetLocalsArray(_Py_framedata *fdata)
{
return frame->localsplus;
return fdata->localsplus;
}

static inline PyObject**
_PyFrame_GetStackPointer(_Py_framedata *frame)
_PyFrame_GetStackPointer(_Py_framedata *fdata)
{
return frame->localsplus+frame->stacktop;
return fdata->localsplus+fdata->stacktop;
}

static inline void
_PyFrame_SetStackPointer(_Py_framedata *frame, PyObject **stack_pointer)
_PyFrame_SetStackPointer(_Py_framedata *fdata, PyObject **stack_pointer)
{
frame->stacktop = (int)(stack_pointer - frame->localsplus);
fdata->stacktop = (int)(stack_pointer - fdata->localsplus);
}

/* For use by _PyFrame_GetFrameObject
Do not call directly. */
PyFrameObject *
_PyFrame_MakeAndSetFrameObject(_Py_framedata *frame);
_PyFrame_MakeAndSetFrameObject(_Py_framedata *fdata);

/* Gets the PyFrameObject for this frame, lazily
* creating it if necessary.
Expand All @@ -200,16 +200,16 @@ _PyFrame_GetFrameObject(_Py_framedata *fdata)
* frames like the ones in generators and coroutines.
*/
void
_PyFrame_Clear(_Py_framedata * frame);
_PyFrame_Clear(_Py_framedata * fdata);

int
_PyFrame_Traverse(_Py_framedata *frame, visitproc visit, void *arg);
_PyFrame_Traverse(_Py_framedata *fdata, visitproc visit, void *arg);

int
_PyFrame_FastToLocalsWithError(_Py_framedata *frame);
_PyFrame_FastToLocalsWithError(_Py_framedata *fdata);

void
_PyFrame_LocalsToFast(_Py_framedata *frame, int clear);
_PyFrame_LocalsToFast(_Py_framedata *fdata, int clear);

extern _Py_framedata *
_PyThreadState_BumpFramePointerSlow(PyThreadState *tstate, size_t size);
Expand All @@ -229,7 +229,7 @@ _PyThreadState_BumpFramePointer(PyThreadState *tstate, size_t size)
return _PyThreadState_BumpFramePointerSlow(tstate, size);
}

void _PyThreadState_PopFrame(PyThreadState *tstate, _Py_framedata *frame);
void _PyThreadState_PopFrame(PyThreadState *tstate, _Py_framedata *fdata);

/* Consume reference to func */
_Py_framedata *
Expand Down
54 changes: 27 additions & 27 deletions Objects/frameobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,14 +630,14 @@ frame_dealloc(PyFrameObject *f)
if (f->f_owns_frame) {
f->f_owns_frame = 0;
assert(f->f_fdata == (_Py_framedata *)f->_f_frame_data);
_Py_framedata *frame = (_Py_framedata *)f->_f_frame_data;
_Py_framedata *fdata = (_Py_framedata *)f->_f_frame_data;
/* Don't clear code object until the end */
co = frame->code;
frame->code = NULL;
Py_CLEAR(frame->func);
Py_CLEAR(frame->locals);
PyObject **locals = _PyFrame_GetLocalsArray(frame);
for (int i = 0; i < frame->stacktop; i++) {
co = fdata->code;
fdata->code = NULL;
Py_CLEAR(fdata->func);
Py_CLEAR(fdata->locals);
PyObject **locals = _PyFrame_GetLocalsArray(fdata);
for (int i = 0; i < fdata->stacktop; i++) {
Py_CLEAR(locals[i]);
}
}
Expand Down Expand Up @@ -771,14 +771,14 @@ PyTypeObject PyFrame_Type = {
};

static void
init_frame(_Py_framedata *frame, PyFunctionObject *func, PyObject *locals)
init_frame(_Py_framedata *fdata, PyFunctionObject *func, PyObject *locals)
{
/* _PyFrame_InitializeSpecials consumes reference to func */
Py_INCREF(func);
PyCodeObject *code = (PyCodeObject *)func->func_code;
_PyFrame_InitializeSpecials(frame, func, locals, code->co_nlocalsplus);
_PyFrame_InitializeSpecials(fdata, func, locals, code->co_nlocalsplus);
for (Py_ssize_t i = 0; i < code->co_nlocalsplus; i++) {
frame->localsplus[i] = NULL;
fdata->localsplus[i] = NULL;
}
}

Expand Down Expand Up @@ -849,30 +849,30 @@ _PyFrame_OpAlreadyRan(_Py_framedata *fdata, int opcode, int oparg)
}

int
_PyFrame_FastToLocalsWithError(_Py_framedata *frame) {
_PyFrame_FastToLocalsWithError(_Py_framedata *fdata) {
/* Merge fast locals into f->locals */
PyObject *locals;
PyObject **fast;
PyCodeObject *co;
locals = frame->locals;
locals = fdata->locals;
if (locals == NULL) {
locals = frame->locals = PyDict_New();
locals = fdata->locals = PyDict_New();
if (locals == NULL)
return -1;
}
co = frame->code;
fast = _PyFrame_GetLocalsArray(frame);
if (frame->lasti < 0 && _Py_OPCODE(co->co_firstinstr[0]) == COPY_FREE_VARS) {
co = fdata->code;
fast = _PyFrame_GetLocalsArray(fdata);
if (fdata->lasti < 0 && _Py_OPCODE(co->co_firstinstr[0]) == COPY_FREE_VARS) {
/* Free vars have not been initialized -- Do that */
PyCodeObject *co = frame->code;
PyObject *closure = frame->func->func_closure;
PyCodeObject *co = fdata->code;
PyObject *closure = fdata->func->func_closure;
int offset = co->co_nlocals + co->co_nplaincellvars;
for (int i = 0; i < co->co_nfreevars; ++i) {
PyObject *o = PyTuple_GET_ITEM(closure, i);
Py_INCREF(o);
frame->localsplus[offset + i] = o;
fdata->localsplus[offset + i] = o;
}
frame->lasti = 0;
fdata->lasti = 0;
}
for (int i = 0; i < co->co_nlocalsplus; i++) {
_PyLocals_Kind kind = _PyLocals_GetKind(co->co_localspluskinds, i);
Expand All @@ -891,7 +891,7 @@ _PyFrame_FastToLocalsWithError(_Py_framedata *frame) {
E2A8
PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i);
PyObject *value = fast[i];
if (frame->state != FRAME_CLEARED) {
if (fdata->state != FRAME_CLEARED) {
if (kind & CO_FAST_FREE) {
// The cell was set by COPY_FREE_VARS.
assert(value != NULL && PyCell_Check(value));
Expand All @@ -904,7 +904,7 @@ _PyFrame_FastToLocalsWithError(_Py_framedata *frame) {
// run yet.
if (value != NULL) {
if (PyCell_Check(value) &&
_PyFrame_OpAlreadyRan(frame, MAKE_CELL, i)) {
_PyFrame_OpAlreadyRan(fdata, MAKE_CELL, i)) {
// (likely) MAKE_CELL must have executed already.
value = PyCell_GET(value);
}
Expand Down Expand Up @@ -960,18 +960,18 @@ PyFrame_FastToLocals(PyFrameObject *f)
}

void
_PyFrame_LocalsToFast(_Py_framedata *frame, int clear)
_PyFrame_LocalsToFast(_Py_framedata *fdata, int clear)
{
/* Merge locals into fast locals */
PyObject *locals;
PyObject **fast;
PyObject *error_type, *error_value, *error_traceback;
PyCodeObject *co;
locals = frame->locals;
locals = fdata->locals;
if (locals == NULL)
return;
fast = _PyFrame_GetLocalsArray(frame);
co = frame->code;
fast = _PyFrame_GetLocalsArray(fdata);
co = fdata->code;

PyErr_Fetch(&error_type, &error_value, &error_traceback);
for (int i = 0; i < co->co_nlocalsplus; i++) {
Expand Down Expand Up @@ -1001,7 +1001,7 @@ _PyFrame_LocalsToFast(_Py_framedata *frame, int clear)
else if (kind & CO_FAST_CELL && oldvalue != NULL) {
/* Same test as in PyFrame_FastToLocals() above. */
if (PyCell_Check(oldvalue) &&
_PyFrame_OpAlreadyRan(frame, MAKE_CELL, i)) {
_PyFrame_OpAlreadyRan(fdata, MAKE_CELL, i)) {
// (likely) MAKE_CELL must have executed already.
cell = oldvalue;
}
Expand Down
Loading
0