Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/test/test_io/test_memoryio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,12 @@ def __index__(self):
with self.assertRaises(ValueError):
stream.truncate(Size())

# Sizes above 2**31 - 1 must work where C long is 32-bit.
if sys.maxsize > 2**31:
stream = self.ioclass("abc")
self.assertEqual(stream.truncate(2**31), 2**31)
self.assertEqual(stream.getvalue(), "abc")

# XXX: For the Python version of io.StringIO, this is highly
# dependent on the encoding used for the underlying buffer.
def test_widechar(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :class:`io.StringIO` implementation of :meth:`io.IOBase.truncate`
rejecting sizes larger than ``2**31 - 1`` on Windows.
2 changes: 1 addition & 1 deletion Modules/_io/stringio.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ _io_StringIO_truncate_impl(stringio *self, PyObject *pos)
size = self->pos;
}
else {
size = PyLong_AsLong(pos);
size = PyNumber_AsSsize_t(pos, PyExc_OverflowError);
if (size == -1 && PyErr_Occurred()) {
return NULL;
}
Expand Down
Loading