-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Accept mutable bytes-like objects #67190
Comments
Some builtins accept only read-only bytes-like objects (PyArg_Parse format codes "s#", "z#", "y", and "y#"). Proposed patch makes them accepting also mutable bytes-like objects such as bytearray. I'm not sure that all these changes are useful, but in some cases this can get rid of copying binary data created in bytearray (e.g. read by readinto()). |
In the event of calls back into Python code in multithreaded execution (or GIL release), this would mean you no longer have guarantees as to the contents (or even the validity) of the pointer you get back. I'd think the only safe way to accept mutable buffers would be to use the s*, z*, y* codes, which lock the buffer to prevent resize/destruction. Do we want to open segfault vulnerabilities in arbitrary functions? |
That is was the patch does. Convert from s# to s* etc. See also bpo-22896 about potential bugs with the use of pointers to unlocked |
Ah, sorry. Should have examined patch. I thought you were making a change to the behavior of s#, z#, y and y#, not converting actual uses of them. Again, sorry. |
+1 on the principle. I haven't looked at the patch. |
If this goes ahead, it would be nice adding notes to the documentation saying that bytearray() or whatever was previously not supported. There are APIs in Python 2.6 that had similar treatment with no documentation updates, and I keep being bitten by it. |
Added versionchanged directives and fixed other documentation. |
I had a closer look at the changes, and most of them seem good. However I think I found one leak in fcntl(); see Reitveld. I noticed there is no test for “ossaudiodev”. Would that be too hard, or is it just an oversight? |
Thank you for your review Martin. Yes, the problem with fcntl() is not so easy and I'll left it for the separate issue.
It is hard because test_ossaudiodev is not designed to just apply the test with different type of data, and this test doesn't work on my computer at all (no /dev/dsp). |
New changeset 17c77938c4e2 by Serhiy Storchaka in branch 'default': |
New changeset 11548e1ac920 by Victor Stinner in branch 'default': |
New changeset d478a2a5738a by Victor Stinner in branch 'default': |
Thanks Victor. |
You're welcome, I just worked recently on ossaudiodev for _Py_read/write functions functions. But I'm not able to run ossaudiodev neither :-( I hope that the test runs on some buildbots (FreeBSD?). |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: