-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-117139: Fix a few wrong steals in bytecodes.c #121127
Conversation
@@ -673,7 +673,7 @@ dummy_func( | |||
err = 1; | |||
} | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
@@ -789,7 +789,7 @@ dummy_func( | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for PySet_Add
@@ -1450,7 +1450,7 @@ dummy_func( | |||
op(_STORE_ATTR, (v, owner --)) { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.