At the moment PyBufferProtocol requires users to initialize the raw ffi::Py_Buffer structure in a pointer.
This forces the user to write unsafe code. It would be nice to rewrite this protocol to offer something better.
Prompted by the below discussion:
In the future I would like to remove Py_buffer::new(), but I think to do so right now would be inconvenient for users because PyBufferProtocol basically forces you to handle the raw ffi pointer (which probably points to uninitialized memory which C created).
I chose MaybeUninit here because that's pretty much identical to what C would do: we create a slab of memory and pass its location to PyObject_GetBuffer to initialize the contents.
Originally posted by @davidhewitt in #1534 (comment)
At the moment
PyBufferProtocolrequires users to initialize the rawffi::Py_Bufferstructure in a pointer.This forces the user to write
unsafecode. It would be nice to rewrite this protocol to offer something better.Prompted by the below discussion:
In the future I would like to remove
Py_buffer::new(), but I think to do so right now would be inconvenient for users becausePyBufferProtocolbasically forces you to handle the raw ffi pointer (which probably points to uninitialized memory which C created).I chose
MaybeUninithere because that's pretty much identical to what C would do: we create a slab of memory and pass its location toPyObject_GetBufferto initialize the contents.Originally posted by @davidhewitt in #1534 (comment)