Skip to content

Commit 2ffae6f

Browse files
Check for unique reference for _BINARY_OP_INPLACE_ADD_UNICODE
1 parent 9609574 commit 2ffae6f

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Python/bytecodes.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -788,17 +788,17 @@ dummy_func(
788788
_PyStackRef *target_local = &GETLOCAL(next_oparg);
789789
assert(PyUnicode_CheckExact(left_o));
790790
DEOPT_IF(PyStackRef_AsPyObjectBorrow(*target_local) != left_o);
791+
/* gh-143401: The local should be uniquely referenced to modify this in-place.
792+
* This check is required as 3.14 no longer creates new references when pushing
793+
* values to the stack in some cases.
794+
*/
795+
DEOPT_IF(!_PyObject_IsUniquelyReferenced(PyStackRef_AsPyObjectBorrow(*target_local)));
791796
STAT_INC(BINARY_OP, hit);
792797
/* Handle `left = left + right` or `left += right` for str.
793798
*
794799
* When possible, extend `left` in place rather than
795800
* allocating a new PyUnicodeObject. This attempts to avoid
796801
* quadratic behavior when one neglects to use str.join().
797-
*
798-
* If `left` has only two references remaining (one from
799-
* the stack, one in the locals), DECREFing `left` leaves
800-
* only the locals reference, so PyUnicode_Append knows
801-
* that the string is safe to mutate.
802802
*/
803803
assert(Py_REFCNT(left_o) >= 2 || !PyStackRef_IsHeapSafe(left));
804804
PyObject *temp = PyStackRef_AsPyObjectSteal(*target_local);

Python/executor_cases.c.h

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)