Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6c6e040

Browse files
authored
bpo-47009: Let PRECALL_NO_KW_LIST_APPEND do its own POP_TOP (GH-32239)
1 parent 96e0983 commit 6c6e040

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Python/ceval.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -5040,15 +5040,15 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
50405040
PyObject *list = SECOND();
50415041
DEOPT_IF(!PyList_Check(list), PRECALL);
50425042
STAT_INC(PRECALL, hit);
5043-
SKIP_CALL();
5043+
// PRECALL + CALL + POP_TOP
5044+
JUMPBY(INLINE_CACHE_ENTRIES_PRECALL + 1 + INLINE_CACHE_ENTRIES_CALL + 1);
5045+
assert(next_instr[-1] == POP_TOP);
50445046
PyObject *arg = POP();
50455047
if (_PyList_AppendTakeRef((PyListObject *)list, arg) < 0) {
50465048
goto error;
50475049
}
5050+
STACK_SHRINK(2);
50485051
Py_DECREF(list);
5049-
STACK_SHRINK(1);
5050-
Py_INCREF(Py_None);
5051-
SET_TOP(Py_None);
50525052
Py_DECREF(callable);
50535053
NOTRACE_DISPATCH();
50545054
}

Python/specialize.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,10 @@ specialize_method_descriptor(PyMethodDescrObject *descr, _Py_CODEUNIT *instr,
14351435
}
14361436
PyInterpreterState *interp = _PyInterpreterState_GET();
14371437
PyObject *list_append = interp->callable_cache.list_append;
1438-
if ((PyObject *)descr == list_append && oparg == 1) {
1438+
_Py_CODEUNIT next = instr[INLINE_CACHE_ENTRIES_PRECALL + 1
1439+
+ INLINE_CACHE_ENTRIES_CALL + 1];
1440+
bool pop = (_Py_OPCODE(next) == POP_TOP);
1441+
if ((PyObject *)descr == list_append && oparg == 1 && pop) {
14391442
_Py_SET_OPCODE(*instr, PRECALL_NO_KW_LIST_APPEND);
14401443
return 0;
14411444
}

0 commit comments

Comments
 (0)