Message170659
Richard Oudkerk <report@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. |
|
Date |
User |
Action |
Args |
2012-09-18 18:20:41 | skrah | set | recipients:
+ skrah, jcea, amaury.forgeotdarc, pitrou, sbt |
2012-09-18 18:20:41 | skrah | link | issue15903 messages |
2012-09-18 18:20:40 | skrah | create | |
|