gh-117139: Fix a few wrong steals in bytecodes.c#121127
gh-117139: Fix a few wrong steals in bytecodes.c#121127Fidget-Spinner merged 1 commit intopython:mainfrom
Conversation
| } | ||
| else { | ||
| err = PyObject_SetItem(PyStackRef_AsPyObjectBorrow(container), slice, PyStackRef_AsPyObjectSteal(v)); | ||
| err = PyObject_SetItem(PyStackRef_AsPyObjectBorrow(container), slice, PyStackRef_AsPyObjectBorrow(v)); |
There was a problem hiding this comment.
PyObject_SetItem and the entire family actually takes borrowed references to the container and item. So this steal is wrong, it should be borrow.
This was caught when the PyStackRef_CLOSE(v) below tried to close an already invalid stackref (it was made invalid by the steal).
| inst(SET_ADD, (set, unused[oparg-1], v -- set, unused[oparg-1])) { | ||
| int err = PySet_Add(PyStackRef_AsPyObjectBorrow(set), | ||
| PyStackRef_AsPyObjectSteal(v)); | ||
| PyStackRef_AsPyObjectBorrow(v)); |
There was a problem hiding this comment.
Same for PySet_Add
| PyObject *name = GETITEM(FRAME_CO_NAMES, oparg); | ||
| int err = PyObject_SetAttr(PyStackRef_AsPyObjectBorrow(owner), | ||
| name, PyStackRef_AsPyObjectSteal(v)); | ||
| name, PyStackRef_AsPyObjectBorrow(v)); |
There was a problem hiding this comment.
PyObject_SetAttr actually takes borrowed refs too, so this shouldn't be stolen. This was caught when the DECREF_INPUTS tried to close an already stolen stackref.
|
|
It looks unrelated and more like a buildbot problem. |
Fix a few wrong steals in bytecodes.c
Fix a few wrong steals in bytecodes.c
Fix a few wrong steals in bytecodes.c
I actually caught these using a tool I built following the stackref semantics here https://github.com/faster-cpython/ideas/blob/kenjin/stackref-semantics/3.14/stackref_semantics.md.
I'll send the PR for the tool in a separate PR.
These bugs were quite hard to notice, I will explain each one in comments below.