msg305726 - (view) |
Author: Guillaume Aldebert (Guillaume Aldebert) |
Date: 2017-11-07 09:40 |
noticed on windows10, 3.6.3-64 and 3.7.0a2-64: using this test.py file: #!/usr/bin/env python3 print('hello\n', end='', flush=True) and running it in unbuffered mode: C:\Dev>py -u test.py hello Traceback (most recent call last): File "test.py", line 2, in print('hello\n', end='', flush=True) OSError: [WinError 87] The parameter is incorrect Note that (still using py -u): print('hello', end='', flush=True) # works fine print('', end='', flush=True) # raises OSError as well |
|
|
msg305733 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2017-11-07 10:12 |
The problem is with _WindowsConsoleIO. C:\py\cpython>python.bat -u -c "import sys; sys.stdout.buffer.write(b'')" Running Release|Win32 interpreter... Traceback (most recent call last): File "", line 1, in OSError: [WinError 87] The parameter is incorrect |
|
|
msg305734 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2017-11-07 10:13 |
Once the bug will be fixed, it would be nice to test this simple case :-) |
|
|
msg305744 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2017-11-07 12:35 |
serhiy.storchaka: "keywords: + easy (C)" For easy issue, you should explain how do you want the issue to be fixed. |
|
|
msg305750 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2017-11-07 13:04 |
I don't know which part of _WindowsConsoleIO.write() fails to handle empty bytes string, but the simplest and the most efficient way to fix this bug it to add an explicit check for zero length at the begin of this method and return Python integer 0 in this case. The test should check that sys.stdout.buffer.write(b''), sys.stdout.buffer.write(b'') and sys.stdout.buffer.raw.write(b'') return 0 (the latter to checks should be performed only if the corresponding buffer and raw attributes exist). There are special tests for WindowsConsoleIO, it would be nice to add an explicit test here too. |
|
|
msg305756 - (view) |
Author: Eryk Sun (eryksun) *  |
Date: 2017-11-07 13:29 |
The error is in _io__WindowsConsoleIO_write_impl. If it's passed a length 0 buffer, it still tries to decode it via MultiByteToWideChar, which fails as documented. As Serhiy says, it can simply return Python int(0) in the zero-length case. |
|
|
msg305762 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2017-11-07 14:43 |
The _io__WindowsConsoleIO_write_impl() function should be fixed to not call MultiByteToWideChar() but use 0 if the input string is zero. Ok, it makes sense. In that case, I agree to call it a simple issue ;-) |
|
|
msg312730 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2018-02-24 16:55 |
New changeset 42c35d9c0c8175332f50fbe034a001fe52f057b9 by Serhiy Storchaka in branch 'master': bpo-31966: Fixed WindowsConsoleIO.write() for writing empty data. (GH-5754) https://github.com/python/cpython/commit/42c35d9c0c8175332f50fbe034a001fe52f057b9 |
|
|
msg312735 - (view) |
Author: miss-islington (miss-islington) |
Date: 2018-02-24 17:39 |
New changeset e49bf0f353a968cddc4d8e6ea668b9d2d116e2ac by Miss Islington (bot) in branch '3.7': bpo-31966: Fixed WindowsConsoleIO.write() for writing empty data. (GH-5754) https://github.com/python/cpython/commit/e49bf0f353a968cddc4d8e6ea668b9d2d116e2ac |
|
|
msg312736 - (view) |
Author: miss-islington (miss-islington) |
Date: 2018-02-24 17:43 |
New changeset 980790eee0c804061a49b8ad7373e4669b48f2ec by Miss Islington (bot) in branch '3.6': bpo-31966: Fixed WindowsConsoleIO.write() for writing empty data. (GH-5754) https://github.com/python/cpython/commit/980790eee0c804061a49b8ad7373e4669b48f2ec |
|
|