mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
GH-120024: Use pointer for stack pointer (GH-121923)
This commit is contained in:
parent
24cf867bed
commit
169324c27a
5 changed files with 55 additions and 43 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue