GH-120024: Use pointer for stack pointer (GH-121923)

This commit is contained in:
Mark Shannon 2024-07-18 12:47:21 +01:00 committed by GitHub
parent 24cf867bed
commit 169324c27a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 55 additions and 43 deletions

View file

@ -1620,8 +1620,10 @@ frame_dealloc(PyFrameObject *f)
Py_CLEAR(frame->f_funcobj);
Py_CLEAR(frame->f_locals);
_PyStackRef *locals = _PyFrame_GetLocalsArray(frame);
for (int i = 0; i < frame->stacktop; i++) {
PyStackRef_CLEAR(locals[i]);
_PyStackRef *sp = frame->stackpointer;
while (sp > locals) {
sp--;
PyStackRef_CLEAR(*sp);
}
}
Py_CLEAR(f->f_back);
@ -1656,11 +1658,13 @@ frame_tp_clear(PyFrameObject *f)
/* locals and stack */
_PyStackRef *locals = _PyFrame_GetLocalsArray(f->f_frame);
assert(f->f_frame->stacktop >= 0);
for (int i = 0; i < f->f_frame->stacktop; i++) {
PyStackRef_CLEAR(locals[i]);
_PyStackRef *sp = f->f_frame->stackpointer;
assert(sp >= locals);
while (sp > locals) {
sp--;
PyStackRef_CLEAR(*sp);
}
f->f_frame->stacktop = 0;
f->f_frame->stackpointer = locals;
Py_CLEAR(f->f_frame->f_locals);
return 0;
}
@ -1878,8 +1882,9 @@ frame_get_var(_PyInterpreterFrame *frame, PyCodeObject *co, int i,
return 0;
}
PyObject *value = PyStackRef_AsPyObjectBorrow(frame->localsplus[i]);
if (frame->stacktop) {
PyObject *value = NULL;
if (frame->stackpointer == NULL || frame->stackpointer > frame->localsplus + i) {
value = PyStackRef_AsPyObjectBorrow(frame->localsplus[i]);
if (kind & CO_FAST_FREE) {
// The cell was set by COPY_FREE_VARS.
assert(value != NULL && PyCell_Check(value));
@ -1897,9 +1902,6 @@ frame_get_var(_PyInterpreterFrame *frame, PyCodeObject *co, int i,
}
}
}
else {
assert(value == NULL);
}
*pvalue = value;
return 1;
}