Skip to content
Closed
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
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
7 changes: 4 additions & 3 deletions Lib/distutils/ccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,9 +875,10 @@ def executable_filename(self, basename, strip_dir=0, output_dir=''):
def library_filename(self, libname, lib_type='static', # or 'shared'
strip_dir=0, output_dir=''):
assert output_dir is not None
if lib_type not in ("static", "shared", "dylib", "xcode_stub"):
raise ValueError(
"'lib_type' must be \"static\", \"shared\", \"dylib\", or \"xcode_stub\"")
if lib_type not in ("static", "shared", "dylib", "xcode_stub",
"implib"):
raise ValueError("'lib_type' must be \"static\", \"shared\", "
"\"dylib\", \"xcode_stub\", or \"implib\"")
fmt = getattr(self, lib_type + "_lib_format")
ext = getattr(self, lib_type + "_lib_extension")

Expand Down
10 changes: 7 additions & 3 deletions Lib/distutils/unixccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ class UnixCCompiler(CCompiler):
shared_lib_extension = ".so"
dylib_lib_extension = ".dylib"
xcode_stub_lib_extension = ".tbd"
implib_lib_extension = ".dll.a"
static_lib_format = shared_lib_format = dylib_lib_format = "lib%s%s"
xcode_stub_lib_format = dylib_lib_format
implib_lib_format = xcode_stub_lib_format = dylib_lib_format
if sys.platform == "cygwin":
exe_extension = ".exe"

Expand Down Expand Up @@ -266,6 +267,7 @@ def find_library_file(self, dirs, lib, debug=0):
shared_f = self.library_filename(lib, lib_type='shared')
dylib_f = self.library_filename(lib, lib_type='dylib')
xcode_stub_f = self.library_filename(lib, lib_type='xcode_stub')
implib_f = self.library_filename(lib, lib_type='implib')
static_f = self.library_filename(lib, lib_type='static')

if sys.platform == 'darwin':
Expand Down Expand Up @@ -294,13 +296,12 @@ def find_library_file(self, dirs, lib, debug=0):
else:
sysroot = m.group(1)



for dir in dirs:
shared = os.path.join(dir, shared_f)
dylib = os.path.join(dir, dylib_f)
static = os.path.join(dir, static_f)
xcode_stub = os.path.join(dir, xcode_stub_f)
implib = os.path.join(dir, implib_f)

if sys.platform == 'darwin' and (
dir.startswith('/System/') or (
Expand All @@ -310,6 +311,7 @@ def find_library_file(self, dirs, lib, debug=0):
dylib = os.path.join(sysroot, dir[1:], dylib_f)
static = os.path.join(sysroot, dir[1:], static_f)
xcode_stub = os.path.join(sysroot, dir[1:], xcode_stub_f)
implib = os.path.join(sysroot, dir[1:], implib_f)

# We're second-guessing the linker here, with not much hard
# data to go on: GCC seems to prefer the shared library, so I'm
Expand All @@ -319,6 +321,8 @@ def find_library_file(self, dirs, lib, debug=0):
return dylib
elif os.path.exists(xcode_stub):
return xcode_stub
elif os.path.exists(implib):
return implib
elif os.path.exists(shared):
return shared
elif os.path.exists(static):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add .dll.a to UnixCCompiler to allow the UnixCCompiler.find_library_file to
correctly find DLL import libs on Cygwin. Patch by Masayuki Yamamoto.