Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
bpo-28459: Fix _pyio on Cygwin where the msvcrt module is not built.
Instead use ctypes to access the setmode function provided by Cygwin.
  • Loading branch information
embray committed Jun 12, 2019
commit 07f3c0dbb748e3add71b6e3569abe34fed388aa3
7 changes: 6 additions & 1 deletion Lib/_pyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
import sys
# Import _thread instead of threading to reduce startup cost
from _thread import allocate_lock as Lock
if sys.platform in {'win32', 'cygwin'}:
if sys.platform == 'win32':
from msvcrt import setmode as _setmode
elif sys.platform == 'cygwin':
import ctypes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid ctypes in the io module. There probably should cygwin equivalent for msvcrt instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benjaminp This is the _pyio module used primarily only in testing. There is no "cygwin equivalent for msvcrt"--why should there be? The closest I can think of is my own PyCygwin package, and it's not part of the standard lib, though I'd be willing to make it so; I'm hardly interested in fighting for a new stdlib package just to fix one bug though.

As was discussed on the issue it would be possible to expose Cygwin's setmode() as os.setmode() but it could be confusing since it does not function the same the FreeBSD setmode().

_cygwin1 = ctypes.CDLL('cygwin1.dll')
def _setmode(fd, mode):
return _cygwin1._setmode(ctypes.c_int(fd), ctypes.c_int(mode))
else:
_setmode = None

Expand Down