bpo-31966: Fixed WindowsConsoleIO.write() for writing empty data. (GH-5754)

(cherry picked from commit 42c35d9c0c)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2018-02-24 09:39:18 -08:00 committed by GitHub
parent 46632f4d3c
commit e49bf0f353
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 0 deletions

View File

@ -121,6 +121,10 @@ class WindowsConsoleIOTests(unittest.TestCase):
else:
self.assertNotIsInstance(f, ConIO)
def test_write_empty_data(self):
with ConIO('CONOUT$', 'w') as f:
self.assertEqual(f.write(b''), 0)
def assertStdinRoundTrip(self, text):
stdin = open('CONIN$', 'r')
old_stdin = sys.stdin

View File

@ -0,0 +1 @@
Fixed WindowsConsoleIO.write() for writing empty data.

View File

@ -964,6 +964,9 @@ _io__WindowsConsoleIO_write_impl(winconsoleio *self, Py_buffer *b)
if (!self->writable)
return err_mode("writing");
if (!b->len) {
return PyLong_FromLong(0);
}
if (b->len > BUFMAX)
len = BUFMAX;
else