Stefan Krah added the comment: Richard Oudkerk <rep...@bugs.python.org> wrote: > PyObject_GetBuffer(b, &buf, PyBUF_WRITABLE); > view = PyMemoryView_FromBuffer(&buf); > // readinto view > PyBuffer_Release(&buf); > > Would attempts to access a "leaked" reference to view now result in > ValueError("operation forbidden on released memoryview object")? If so then > I think this would be safe.
You would need to call memory_release(). Perhaps we can just expose it on the C-API level as PyMemoryView_Release(). IMO the use of PyObject_GetBuffer() should be discouraged. The semantics aren't clear (see #15821). I'd suggest using: 1) A buffer provider is involved (the case here): PyMemoryView_From Object() 2) A piece of memory needs to be wrapped temporarily and no references to the memoryview are "leaked" on the Python level: PyMemoryView_FromMemory() 3) A piece of memory needs to be packaged as a memoryview with automatic cleanup in mbuf_dealloc(): PyMemoryView_FromBufferWithCleanup() (proposed in msg169613) So I think the combination of PyMemoryView_FromObject() with a call to PyMemoryView_Release() should indeed work here. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue15903> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com