Skip to content

Commit c2dbfe2

Browse files
committed
pythongh-117139: Fix an incorrect borrow in bytecodes.c
`_PyDict_SetItem_Take2` steals both the key (i.e., `sub`) and the value.
1 parent 64857d8 commit c2dbfe2

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

Python/bytecodes.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -851,13 +851,14 @@ dummy_func(
851851
PyStackRef_CLOSE(list_st);
852852
}
853853

854-
inst(STORE_SUBSCR_DICT, (unused/1, value, dict_st, sub_st -- )) {
855-
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
854+
inst(STORE_SUBSCR_DICT, (unused/1, value, dict_st, sub -- )) {
856855
PyObject *dict = PyStackRef_AsPyObjectBorrow(dict_st);
857856

858857
DEOPT_IF(!PyDict_CheckExact(dict));
859858
STAT_INC(STORE_SUBSCR, hit);
860-
int err = _PyDict_SetItem_Take2((PyDictObject *)dict, sub, PyStackRef_AsPyObjectSteal(value));
859+
int err = _PyDict_SetItem_Take2((PyDictObject *)dict,
860+
PyStackRef_AsPyObjectSteal(sub),
861+
PyStackRef_AsPyObjectSteal(value));
861862
PyStackRef_CLOSE(dict_st);
862863
ERROR_IF(err, error);
863864
}

Python/executor_cases.c.h

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)