summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2024-07-18 11:47:21 (GMT)
committerGitHub <noreply@github.com>2024-07-18 11:47:21 (GMT)
commit169324c27a39a4d6a4dd7b313b0de6ab2d1f7e6b (patch)
tree89b908cb6b3957a88b567dcc4c44b9873865433f /Python
parent24cf867bed6035f33cd3b38d89d303b7522f12a6 (diff)
downloadcpython-169324c27a39a4d6a4dd7b313b0de6ab2d1f7e6b.zip
cpython-169324c27a39a4d6a4dd7b313b0de6ab2d1f7e6b.tar.gz
cpython-169324c27a39a4d6a4dd7b313b0de6ab2d1f7e6b.tar.bz2
GH-120024: Use pointer for stack pointer (GH-121923)
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c2
-rw-r--r--Python/frame.c22
2 files changed, 14 insertions, 10 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 026e018..97d4b82 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -764,7 +764,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
#endif
entry_frame.f_executable = Py_None;
entry_frame.instr_ptr = (_Py_CODEUNIT *)_Py_INTERPRETER_TRAMPOLINE_INSTRUCTIONS + 1;
- entry_frame.stacktop = 0;
+ entry_frame.stackpointer = entry_frame.localsplus;
entry_frame.owner = FRAME_OWNED_BY_CSTACK;
entry_frame.return_offset = 0;
/* Push frame */
diff --git a/Python/frame.c b/Python/frame.c
index 9c7e596..25fa282 100644
--- a/Python/frame.c
+++ b/Python/frame.c
@@ -17,10 +17,11 @@ _PyFrame_Traverse(_PyInterpreterFrame *frame, visitproc visit, void *arg)
Py_VISIT(_PyFrame_GetCode(frame));
/* locals */
_PyStackRef *locals = _PyFrame_GetLocalsArray(frame);
- int i = 0;
+ _PyStackRef *sp = frame->stackpointer;
/* locals and stack */
- for (; i <frame->stacktop; i++) {
- Py_VISIT(PyStackRef_AsPyObjectBorrow(locals[i]));
+ while (sp > locals) {
+ sp--;
+ Py_VISIT(PyStackRef_AsPyObjectBorrow(*sp));
}
return 0;
}
@@ -59,10 +60,11 @@ take_ownership(PyFrameObject *f, _PyInterpreterFrame *frame)
assert(frame->owner != FRAME_OWNED_BY_CSTACK);
assert(frame->owner != FRAME_OWNED_BY_FRAME_OBJECT);
assert(frame->owner != FRAME_CLEARED);
- Py_ssize_t size = ((char*)&frame->localsplus[frame->stacktop]) - (char *)frame;
+ Py_ssize_t size = ((char*)frame->stackpointer) - (char *)frame;
Py_INCREF(_PyFrame_GetCode(frame));
memcpy((_PyInterpreterFrame *)f->_f_frame_data, frame, size);
frame = (_PyInterpreterFrame *)f->_f_frame_data;
+ frame->stackpointer = (_PyStackRef *)(((char *)frame) + size);
f->f_frame = frame;
frame->owner = FRAME_OWNED_BY_FRAME_OBJECT;
if (_PyFrame_IsIncomplete(frame)) {
@@ -97,11 +99,13 @@ take_ownership(PyFrameObject *f, _PyInterpreterFrame *frame)
void
_PyFrame_ClearLocals(_PyInterpreterFrame *frame)
{
- assert(frame->stacktop >= 0);
- int stacktop = frame->stacktop;
- frame->stacktop = 0;
- for (int i = 0; i < stacktop; i++) {
- PyStackRef_XCLOSE(frame->localsplus[i]);
+ assert(frame->stackpointer != NULL);
+ _PyStackRef *sp = frame->stackpointer;
+ _PyStackRef *locals = frame->localsplus;
+ frame->stackpointer = locals;
+ while (sp > locals) {
+ sp--;
+ PyStackRef_XCLOSE(*sp);
}
Py_CLEAR(frame->f_locals);
}