Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions Doc/library/ctypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,10 @@ like ``find_library("c")`` will fail and return ``None``.

.. availability:: Windows

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


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

Expand Down
29 changes: 9 additions & 20 deletions Lib/ctypes/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,18 @@ def _get_build_version():
return None

def find_msvcrt():
"""Return the name of the VC runtime dll"""
version = _get_build_version()
if version is None:
# better be safe than sorry
return None
if version <= 6:
clibname = 'msvcrt'
elif version <= 13:
clibname = 'msvcr%d' % (version * 10)
else:
# CRT is no longer directly loadable. See issue23606 for the
# discussion about alternative approaches.
return None

# If python was built with in debug mode
import importlib.machinery
if '_d.pyd' in importlib.machinery.EXTENSION_SUFFIXES:
clibname += 'd'
return clibname+'.dll'
"""Return the name of the VC runtime dll.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This renders _get_build_version unused. Can it be removed?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ZeroIntensity, as you'll be doing this more often: consider doing deprecation periods for underscored API as well, if there's no harm in keeping things around for a few more years.
Most of the module predates clear docs on what the underscore means, so existing code might use such functions.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, right, thanks for the reminder. I think this one is okay because I couldn't find any uses of it after a quick code search.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, this is more of a general reminder of what to keep in mind.
As for code searches, be careful -- this stuff also predates GitHub's hegemony.

This is soft deprecated as of Python 3.16."""
# See gh-154199. In short, this function wasn't able to return
# newer msvcrt versions (because there was no single msvcrt DLL),
# and the versions that are a single DLL are no longer supported
# by Microsoft.
return None

def find_library(name):
if name in ('c', 'm'):
return find_msvcrt()
# See gh-67794; there is no single VC runtime DLL anymore.
return None
# See MSDN for the REAL search order.
for directory in os.environ['PATH'].split(os.pathsep):
fname = os.path.join(directory, name)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Make :func:`ctypes.util.find_msvcrt` always return ``None`` for
compatibility reasons.
Loading