summaryrefslogtreecommitdiffstats
path: root/Modules/_io
diff options
context:
space:
mode:
authorNitish Chandra <nitishchandrachinta@gmail.com>2018-01-28 16:00:09 (GMT)
committerAntoine Pitrou <pitrou@free.fr>2018-01-28 16:00:09 (GMT)
commit059f58ce938d9c3f0286412a4efb1b9131339421 (patch)
tree4d8ece4c9ab330e0a2e68fd27c49dbee525ec7fb /Modules/_io
parent79db11ce99332d62917be9d03b31494b1ff2f96a (diff)
downloadcpython-059f58ce938d9c3f0286412a4efb1b9131339421.zip
cpython-059f58ce938d9c3f0286412a4efb1b9131339421.tar.gz
cpython-059f58ce938d9c3f0286412a4efb1b9131339421.tar.bz2
bpo-32228: Reset raw_pos after unwinding the raw stream (#4858)
Ensure that ``truncate()`` preserves the file position (as reported by ``tell()``) after writes longer than the buffer size.
Diffstat (limited to 'Modules/_io')
-rw-r--r--Modules/_io/bufferedio.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
index 2b7aaaf..358a654 100644
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -1292,7 +1292,6 @@ _io__Buffered_seek_impl(buffered *self, PyObject *targetobj, int whence)
if (res == NULL)
goto end;
Py_CLEAR(res);
- _bufferedwriter_reset_buf(self);
}
/* TODO: align on block boundary and read buffer if needed? */
@@ -1852,8 +1851,6 @@ _bufferedwriter_raw_write(buffered *self, char *start, Py_ssize_t len)
return n;
}
-/* `restore_pos` is 1 if we need to restore the raw stream position at
- the end, 0 otherwise. */
static PyObject *
_bufferedwriter_flush_unlocked(buffered *self)
{
@@ -1894,9 +1891,18 @@ _bufferedwriter_flush_unlocked(buffered *self)
goto error;
}
- _bufferedwriter_reset_buf(self);
end:
+ /* This ensures that after return from this function,
+ VALID_WRITE_BUFFER(self) returns false.
+
+ This is a required condition because when a tell() is called
+ after flushing and if VALID_READ_BUFFER(self) is false, we need
+ VALID_WRITE_BUFFER(self) to be false to have
+ RAW_OFFSET(self) == 0.
+
+ Issue: https://bugs.python.org/issue32228 */
+ _bufferedwriter_reset_buf(self);
Py_RETURN_NONE;
error: