Thanks for bringing this up! I got this idea from a post in the previous thread: PEP 688: Making the buffer protocol accessible in Python - #29 by storchaka. It took me a while to convince myself that it’s true, but maybe it’s not! The line of thinking that persuaded me was that anything that allows a writable buffer must keep track of whether someone is already writing to it in order to be thread-safe, and therefore it must have a bf_releasebuffer
slot. Among the stdlib’s buffer classes, it also seems to be true that all the mutable ones have bf_releasebuffer
slots. Numpy gets around this with manual refcounting: the buffer returned by bf_getbuffer
holds a reference that the consumer must eventually DECREF, which signals to the numpy array that its consumer is gone.
If we can’t use bf_releasebuffer
to signal mutability, I think we’ll have to go back to a single Buffer
type, with no affordance for mutability in the type system. There just isn’t an elegant way to support it.