-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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-127271: Remove the PyCell_Get usage for framelocalsproxy #130383
base: main
Are you sure you want to change the base?
Conversation
PyObject *value = framelocalsproxy_getval(frame->f_frame, co, i); | ||
assert(value != NULL); |
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.
This doesn't look safe to me. I don't think we can rely on consistency between the earlier framelocalsproxy_getkeyindex
call and the framelocalsproxy_getval
here.
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.
Do you mean a very specific case where the content of the cell on that index is set to NULL
by PyCell_Set
from another thread? I think that's probably an outlier. If it's a normal fast variable, can it happen? Multi-threading can't affect the local fast variables on stack right?
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.
Yeah, I'm just thinking about the cell case.
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.
The normal Python operation won't set NULL
to a cell right? So we should maybe raise some exception here if the value is NULL
? That's the only case I can think of.
Co-authored-by: Sam Gross <[email protected]>
In #127272 a
PyCell_Get
usage inframeobject.c
was missed from being replaced for free-threaded safety. I guess the reason was probably the function was labelled to return a borrowed reference and a deeper understanding of the piece of code is needed to make that change. (or maybe I'm just thinking too much and it just slipped away :))I made the change to use
PyCell_GetRef
and changed the function to return a new reference (because otherwise it won't be safe in free-threaded build). However, there are a few places in the code where it does not care about the actual value stored, it only cares whether such value exists - so I added a util function to avoid havingPy_XDECREF
s all around the code.