-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
gh-132070: Use _PyObject_IsUniquelyReferenced in unicodeobject #133039
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
base: main
Are you sure you want to change the base?
Conversation
corona10
commented
Apr 27, 2025
•
edited by bedevere-app
bot
Loading
edited by bedevere-app
bot
- Issue: data race when resizing unicode objects #132070
@kumaraditya303 @colesbury |
Co-authored-by: Serhiy Storchaka <[email protected]>
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.
LGTM.
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.
I looked into the case that requires resize_copy
: We have an io.StringIO
, which is used first by one thread and then by a second thread. (It's not used by two threads simultaneously). The io.StringIO
has the only reference to a PyUnicodeWriter
, which in turn has the only reference to unicode object that is treated as a buffer.
The _PyObject_IsUniquelyReferenced()
check is too conservative in this case because the unicode object is owned by a different thread. The unicode object is actually safe to modify, we just can't tell that from _PyObject_IsUniquelyReferenced()
.