File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -792,9 +792,6 @@ pub struct PyUntypedBufferView {
792792impl PyUntypedBufferView {
793793 /// Acquire a buffer view on the stack with [`ffi::PyBUF_SIMPLE`] flags,
794794 /// pass it to `f`, then release the buffer.
795- ///
796- /// Format is patched to `"B"` and itemsize to `1`, as required by the
797- /// buffer protocol for `PyBUF_SIMPLE` requests.
798795 pub fn with < R > (
799796 obj : & Bound < ' _ , PyAny > ,
800797 f : impl FnOnce ( & PyUntypedBufferView ) -> R ,
@@ -835,10 +832,16 @@ impl PyUntypedBufferView {
835832
836833 // SAFETY: Construct view only after successful GetBuffer, so Drop always
837834 // runs on an initialized Py_buffer.
838- let view = PyUntypedBufferView {
835+ let mut view = PyUntypedBufferView {
839836 raw : unsafe { raw. assume_init ( ) } ,
840837 } ;
841838
839+ // For PyBUF_WRITABLE, the consumer must assume itemsize == 1 and format "B".
840+ if flags == ffi:: PyBUF_WRITABLE {
841+ view. raw . itemsize = 1 ;
842+ view. raw . format = ffi:: c_str!( "B" ) . as_ptr ( ) as * mut _ ;
843+ }
844+
842845 Ok ( f ( & view) )
843846 }
844847
You can’t perform that action at this time.
0 commit comments