This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author skrah
Recipients amaury.forgeotdarc, jcea, pitrou, sbt, skrah
Date 2012-09-18.18:20:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <20120918182042.GA23778@sleipnir.bytereef.org>
In-reply-to <1347965270.12.0.195762674033.issue15903@psf.upfronthosting.co.za>
Content
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.
History
Date User Action Args
2012-09-18 18:20:41skrahsetrecipients: + skrah, jcea, amaury.forgeotdarc, pitrou, sbt
2012-09-18 18:20:41skrahlinkissue15903 messages
2012-09-18 18:20:40skrahcreate