I have an existing PyMemoryViewObject
that I want to "release" to invalidate the memoryview
object.
I am able to call the release
function through the PyObject_CallMethod
API:
if (PyMemoryView_Check(obj)) {
PyObject_CallMethod(obj, "release", NULL);
}
This works fine, but I would like to use a more direct approach.
I've tried this:
if (PyMemoryView_Check(obj)) {
PyBuffer_Release(PyMemoryView_GET_BUFFER(obj));
}
However, this doesn't work, and I'm still able to read/write from the buffer in Python. In fact, the documentation for PyBuffer_Release
says:
/* Releases a Py_buffer obtained from getbuffer ParseTuple's "s*". */