Skip to content

Safer trait for PyBufferProtocol #1536

@davidhewitt

Description

@davidhewitt

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)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions