Uh oh!
There was an error while loading. Please reload this page.
gh-60107: Remove a copy from RawIOBase.read - #141532
Conversation
If the underlying I/O class keeps a reference to the memory raise BufferError.
Uh oh!
There was an error while loading. Please reload this page.
| } | ||
| return res; | ||
| } | ||
| res = PyObject_CallMethod(b, "take_bytes", NULL); |
There was a problem hiding this comment.
@vstinner : Not sure how common this "resize/discard then take_bytes" is going to be; might make sense to change to take_bytes(n=None, /, *, discard=False)
There was a problem hiding this comment.
for now planning to keep that in back pocket until need many ways (ba.resize(n) or del ba[:n] gives the same capability)
vstinner
left a comment
There was a problem hiding this comment.
Can you also update RawIOBase.read() in the _pyio module?
cmaloney
commented
Nov 15, 2025
Have that in #141539 which does all the cases |
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Victor Stinner <vstinner@python.org>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
If the underlying I/O class keeps a reference to the memory, raise BufferError. Co-authored-by: Victor Stinner <vstinner@python.org>
If the underlying I/O class keeps a reference to the memory, raise BufferError. Co-authored-by: Victor Stinner <vstinner@python.org>
If the underlying I/O class keeps a reference to the memory raise
BufferError.Uses gh-139871 to implement.
--
If want to maintain closer compatibility when a
BufferErroroccurs can fall back to a copy (copying is as safe as the original code). I have a slight preference to erroring as I think keeping a reference to the memory is uncommon (and probably unintended).bytearraytobytesin rawiobase_read() implementation #60107