[issue15903] Make rawiobase_read() read directly to bytes object

Richard Oudkerk report at bugs.python.org
Tue Sep 18 01:05:17 CEST 2012


Richard Oudkerk added the comment:

> I think that's a useless precaution. The bytes object cannot "leak" 
> since you are using PyMemoryView_FromMemory(), which doesn't know about 
> the original object.

The bytes object cannot "leak" so, as you say, checking that refcount is pointless.  But the view might "leak", and since it does not own a reference to the base object we have a problem: we can't deallocate the bytes object for fear of breaking the view.

It looks like objects returned by PyMemoryView_FromMemory() must never be allowed to "leak", so I am not sure there are many circumstances in which PyMemoryView_FromMemory() is safe to use.

Perhaps using PyBuffer_FillInfo() and PyMemory_FromBuffer() would keep alive the bytes object while the view is alive, without letting the bytes object "leak".

> Out of curiousity, have you done any benchmarks?

No.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15903>
_______________________________________


More information about the Python-bugs-list mailing list