[cpyext] internal field of buffer struct lost or ignored
Created originally on Bitbucket by nlgranger
When creating an object exposing the buffer protocol, the python specification offers an internal field in the buffer struct to store custom values. This field is incorrectly set to NULL when releasebuffer is called instead of keeping the value it was initially assigned. Presumable, PyPy didn’t even read that value.
In the attached example, the internal field is read back by RefCountedBuffer_releasebuffer when a buffer gets released in mymodule.c l118. The example is a wrapper around objects already exposing the buffer API, it adds a refcount to track how many views of the buffer exist and triggers a callback when that count reaches 0.
Attachments: cpyext_with_buffer.zip