Skip to content

Commit c4d2d57

Browse files
authored
bpo-46841: Fix BINARY_OP's handling of inline caches (GH-31671)
1 parent cedd247 commit c4d2d57

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix incorrect handling of inline cache entries when specializing
2+
:opcode:`BINARY_OP`.

Python/ceval.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,8 +2028,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
20282028
DEOPT_IF(!PyUnicode_CheckExact(left), BINARY_OP);
20292029
DEOPT_IF(Py_TYPE(right) != Py_TYPE(left), BINARY_OP);
20302030
DEOPT_IF(Py_REFCNT(left) != 2, BINARY_OP);
2031-
int next_oparg = _Py_OPARG(*next_instr);
2032-
assert(_Py_OPCODE(*next_instr) == STORE_FAST);
2031+
_Py_CODEUNIT true_next = next_instr[INLINE_CACHE_ENTRIES_BINARY_OP];
2032+
int next_oparg = _Py_OPARG(true_next);
2033+
assert(_Py_OPCODE(true_next) == STORE_FAST);
20332034
/* In the common case, there are 2 references to the value
20342035
* stored in 'variable' when the v = v + ... is performed: one
20352036
* on the value stack (in 'v') and one still stored in the

Python/specialize.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,8 @@ _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
19511951
break;
19521952
}
19531953
if (PyUnicode_CheckExact(lhs)) {
1954-
if (_Py_OPCODE(instr[1]) == STORE_FAST && Py_REFCNT(lhs) == 2) {
1954+
_Py_CODEUNIT next = instr[INLINE_CACHE_ENTRIES_BINARY_OP + 1];
1955+
if (_Py_OPCODE(next) == STORE_FAST && Py_REFCNT(lhs) == 2) {
19551956
*instr = _Py_MAKECODEUNIT(BINARY_OP_INPLACE_ADD_UNICODE,
19561957
oparg);
19571958
goto success;

0 commit comments

Comments
 (0)