-
Notifications
You must be signed in to change notification settings - Fork 777
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
Replace unsound PyByteArray::data with PyByteArray::to_vec #545
Conversation
I'm not against this PR, but to think about what kind of safety we can provide under the current design, we should keep in our mind that we can do mutate operation to all &Py~ types. |
In the end, to be taken seriously by the Rust community, and to deserve the name of a safe wrapper, PyO3 cannot leave UB possible in safe code. This is the benefit that outweighs any drawback of more complicated code. |
For all I can tell pyo3 is in its general design sound. The known exceptions are:
I'd be happy about pull requests for those issues and I'm willing to help with questions arising when implementing those. Given the size of pyo3's codebase and the cpython ffi, there are surely more bugs that can produce UB in the code, but I don't think that there are fundamental problems with pyo3's current design.
Could you explain that a bit more? For my understanding what we're doing is well defined because every modification happens through a call to a c function with a raw pointer, which are both opaque to rustc. |
Sorry for my poor English and explanation, ...
Yeah, I think this is a good interpretation of what kind of safety we can provide. |
Thanks to @ExpHP's comment in #373 pointing out the existing unsoundness of
PyByteArray::data
I've replace the function withto_vec
, which copies the bytearray to a Vec. In the long run we likely want something like ReadOnlyCell for anas_slice
, but this at least fixes the UB for now.