Commit 56a220ae authored by Antoine Pitrou's avatar Antoine Pitrou

Issue #13393: BufferedReader.read1() now asks the full requested size to

the raw stream instead of limiting itself to the buffer size.
parent 2821644d
...@@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1? ...@@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1?
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #13393: BufferedReader.read1() now asks the full requested size to
the raw stream instead of limiting itself to the buffer size.
- Issue #13392: Writing a pyc file should now be atomic under Windows as well. - Issue #13392: Writing a pyc file should now be atomic under Windows as well.
- Issue #13333: The UTF-7 decoder now accepts lone surrogates (the encoder - Issue #13333: The UTF-7 decoder now accepts lone surrogates (the encoder
......
...@@ -889,51 +889,34 @@ buffered_read1(buffered *self, PyObject *args) ...@@ -889,51 +889,34 @@ buffered_read1(buffered *self, PyObject *args)
if (n == 0) if (n == 0)
return PyBytes_FromStringAndSize(NULL, 0); return PyBytes_FromStringAndSize(NULL, 0);
if (!ENTER_BUFFERED(self))
return NULL;
/* Return up to n bytes. If at least one byte is buffered, we /* Return up to n bytes. If at least one byte is buffered, we
only return buffered bytes. Otherwise, we do one raw read. */ only return buffered bytes. Otherwise, we do one raw read. */
/* XXX: this mimicks the io.py implementation but is probably wrong.
If we need to read from the raw stream, then we could actually read
all `n` bytes asked by the caller (and possibly more, so as to fill
our buffer for the next reads). */
have = Py_SAFE_DOWNCAST(READAHEAD(self), Py_off_t, Py_ssize_t); have = Py_SAFE_DOWNCAST(READAHEAD(self), Py_off_t, Py_ssize_t);
if (have > 0) { if (have > 0) {
if (n > have) n = Py_MIN(have, n);
n = have; res = _bufferedreader_read_fast(self, n);
res = PyBytes_FromStringAndSize(self->buffer + self->pos, n); assert(res != Py_None);
if (res == NULL) return res;
goto end;
self->pos += n;
goto end;
} }
res = PyBytes_FromStringAndSize(NULL, n);
if (self->writable) { if (res == NULL)
res = buffered_flush_and_rewind_unlocked(self); return NULL;
if (res == NULL) if (!ENTER_BUFFERED(self)) {
goto end;
Py_DECREF(res); Py_DECREF(res);
return NULL;
} }
/* Fill the buffer from the raw stream, and copy it to the result. */
_bufferedreader_reset_buf(self); _bufferedreader_reset_buf(self);
r = _bufferedreader_fill_buffer(self); r = _bufferedreader_raw_read(self, PyBytes_AS_STRING(res), n);
if (r == -1) LEAVE_BUFFERED(self)
goto end; if (r == -1) {
Py_DECREF(res);
return NULL;
}
if (r == -2) if (r == -2)
r = 0; r = 0;
if (n > r) if (n > r)
n = r; _PyBytes_Resize(&res, r);
res = PyBytes_FromStringAndSize(self->buffer, n);
if (res == NULL)
goto end;
self->pos = n;
end:
LEAVE_BUFFERED(self)
return res; return res;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment