Skip to content

Commit ada9da9

Browse files
gh-154199: Soft-deprecate ctypes.util.find_msvcrt (GH-154553)
1 parent 2f4cca5 commit ada9da9

3 files changed

Lines changed: 15 additions & 46 deletions

File tree

Doc/library/ctypes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,6 +1866,10 @@ like ``find_library("c")`` will fail and return ``None``.
18661866

18671867
.. availability:: Windows
18681868

1869+
.. soft-deprecated:: 3.16
1870+
This function now always returns ``None``, as there are no more
1871+
VC runtime DLLs that are a single file and supported by Microsoft.
1872+
18691873

18701874
.. _ctypes-listing-loaded-shared-libraries:
18711875

Lib/ctypes/util.py

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,56 +13,19 @@
1313

1414
# find_library(name) returns the pathname of a library, or None.
1515
if os.name == "nt":
16-
17-
def _get_build_version():
18-
"""Return the version of MSVC that was used to build Python.
19-
20-
For Python 2.3 and up, the version number is included in
21-
sys.version. For earlier versions, assume the compiler is MSVC 6.
22-
"""
23-
# This function was copied from Lib/distutils/msvccompiler.py
24-
prefix = "MSC v."
25-
i = sys.version.find(prefix)
26-
if i == -1:
27-
return 6
28-
i = i + len(prefix)
29-
s, rest = sys.version[i:].split(" ", 1)
30-
majorVersion = int(s[:-2]) - 6
31-
if majorVersion >= 13:
32-
majorVersion += 1
33-
minorVersion = int(s[2:3]) / 10.0
34-
# I don't think paths are affected by minor version in version 6
35-
if majorVersion == 6:
36-
minorVersion = 0
37-
if majorVersion >= 6:
38-
return majorVersion + minorVersion
39-
# else we don't know what version of the compiler this is
40-
return None
41-
4216
def find_msvcrt():
43-
"""Return the name of the VC runtime dll"""
44-
version = _get_build_version()
45-
if version is None:
46-
# better be safe than sorry
47-
return None
48-
if version <= 6:
49-
clibname = 'msvcrt'
50-
elif version <= 13:
51-
clibname = 'msvcr%d' % (version * 10)
52-
else:
53-
# CRT is no longer directly loadable. See issue23606 for the
54-
# discussion about alternative approaches.
55-
return None
56-
57-
# If python was built with in debug mode
58-
import importlib.machinery
59-
if '_d.pyd' in importlib.machinery.EXTENSION_SUFFIXES:
60-
clibname += 'd'
61-
return clibname+'.dll'
17+
"""Return the name of the VC runtime dll.
18+
This is soft deprecated as of Python 3.16."""
19+
# See gh-154199. In short, this function wasn't able to return
20+
# newer msvcrt versions (because there was no single msvcrt DLL),
21+
# and the versions that are a single DLL are no longer supported
22+
# by Microsoft.
23+
return None
6224

6325
def find_library(name):
6426
if name in ('c', 'm'):
65-
return find_msvcrt()
27+
# See gh-67794; there is no single VC runtime DLL anymore.
28+
return None
6629
# See MSDN for the REAL search order.
6730
for directory in os.environ['PATH'].split(os.pathsep):
6831
fname = os.path.join(directory, name)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Make :func:`ctypes.util.find_msvcrt` always return ``None`` for
2+
compatibility reasons.

0 commit comments

Comments
 (0)