-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-60107: Remove a copy from RawIOBase.read #141532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
f904fce
6c9d14e
847c7ed
bfb0c71
3709cf9
63ceed7
a1daaae
13abb41
7dc7e92
82643f8
a9a1f14
8ca1cef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Remove a copy from :meth:`io.RawIOBase.read`. If the underlying I/O class | ||
| keeps a reference to the mutable memory raise a :exc:`BufferError`. | ||
|
vstinner marked this conversation as resolved.
Outdated
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -953,7 +953,19 @@ _io__RawIOBase_read_impl(PyObject *self, Py_ssize_t n) | |
| return NULL; | ||
| } | ||
|
|
||
| res = PyBytes_FromStringAndSize(PyByteArray_AsString(b), bytes_filled); | ||
| res = PyObject_CallMethod(b, "resize", "i", bytes_filled); | ||
| if (res != Py_None) { | ||
| Py_DECREF(b); | ||
| if (res != NULL) { | ||
| PyErr_Format(PyExc_ValueError, | ||
| "resize returned unexpected value %R", | ||
| res); | ||
| Py_DECREF(res); | ||
| res = NULL; | ||
| } | ||
| return res; | ||
| } | ||
| res = PyObject_CallMethod(b, "take_bytes", NULL); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vstinner : Not sure how common this "resize/discard then take_bytes" is going to be; might make sense to change to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for now planning to keep that in back pocket until need many ways (
cmaloney marked this conversation as resolved.
Outdated
|
||
| Py_DECREF(b); | ||
| return res; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.