[3.8] bpo-38597: Never statically link extension initialization code on Windows (GH-18724) by miss-islington · Pull Request #18758 · python/cpython · GitHub
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
60 changes: 7 additions & 53 deletions Lib/distutils/_msvccompiler.py
51 changes: 0 additions & 51 deletions Lib/distutils/tests/test_msvccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,57 +32,6 @@ def _find_vcvarsall(plat_spec):
finally:
_msvccompiler._find_vcvarsall = old_find_vcvarsall

def test_compiler_options(self):
import distutils._msvccompiler as _msvccompiler
# suppress path to vcruntime from _find_vcvarsall to
# check that /MT is added to compile options
old_find_vcvarsall = _msvccompiler._find_vcvarsall
def _find_vcvarsall(plat_spec):
return old_find_vcvarsall(plat_spec)[0], None
_msvccompiler._find_vcvarsall = _find_vcvarsall
try:
compiler = _msvccompiler.MSVCCompiler()
compiler.initialize()

self.assertIn('/MT', compiler.compile_options)
self.assertNotIn('/MD', compiler.compile_options)
finally:
_msvccompiler._find_vcvarsall = old_find_vcvarsall

def test_vcruntime_copy(self):
import distutils._msvccompiler as _msvccompiler
# force path to a known file - it doesn't matter
# what we copy as long as its name is not in
# _msvccompiler._BUNDLED_DLLS
old_find_vcvarsall = _msvccompiler._find_vcvarsall
def _find_vcvarsall(plat_spec):
return old_find_vcvarsall(plat_spec)[0], __file__
_msvccompiler._find_vcvarsall = _find_vcvarsall
try:
tempdir = self.mkdtemp()
compiler = _msvccompiler.MSVCCompiler()
compiler.initialize()
compiler._copy_vcruntime(tempdir)

self.assertTrue(os.path.isfile(os.path.join(
tempdir, os.path.basename(__file__))))
finally:
_msvccompiler._find_vcvarsall = old_find_vcvarsall

def test_vcruntime_skip_copy(self):
import distutils._msvccompiler as _msvccompiler

tempdir = self.mkdtemp()
compiler = _msvccompiler.MSVCCompiler()
compiler.initialize()
dll = compiler._vcruntime_redist
self.assertTrue(os.path.isfile(dll), dll or "<None>")

compiler._copy_vcruntime(tempdir)

self.assertFalse(os.path.isfile(os.path.join(
tempdir, os.path.basename(dll))), dll or "<None>")

def test_get_vc_env_unicode(self):
import distutils._msvccompiler as _msvccompiler

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:mod:`distutils` will no longer statically link :file:`vcruntime140.dll`
when a redistributable version is unavailable. All future releases of
CPython will include a copy of this DLL to ensure distributed extensions can
continue to load.
2 changes: 2 additions & 0 deletions PCbuild/pythoncore.vcxproj