Skip to content

Commit

Permalink
gh-117139: Fix an incorrect borrow in bytecodes.c (#122318)
Browse files Browse the repository at this point in the history
`_PyDict_SetItem_Take2` steals both the key (i.e., `sub`) and the value.
  • Loading branch information
colesbury committed Aug 7, 2024
1 parent 013a092 commit 674a50e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
7 changes: 4 additions & 3 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -862,13 +862,14 @@ dummy_func(
PyStackRef_CLOSE(list_st);
}

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

DEOPT_IF(!PyDict_CheckExact(dict));
STAT_INC(STORE_SUBSCR, hit);
int err = _PyDict_SetItem_Take2((PyDictObject *)dict, sub, PyStackRef_AsPyObjectSteal(value));
int err = _PyDict_SetItem_Take2((PyDictObject *)dict,
PyStackRef_AsPyObjectSteal(sub),
PyStackRef_AsPyObjectSteal(value));
PyStackRef_CLOSE(dict_st);
ERROR_IF(err, error);
}
Expand Down
9 changes: 5 additions & 4 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 674a50e

Please sign in to comment.