René's URL Explorer Experiment


Title: gh-154199: Fix find_msvcrt() on builds with a truncated sys.version by SynaptSea · Pull Request #154209 · python/cpython · GitHub

Open Graph Title: gh-154199: Fix find_msvcrt() on builds with a truncated sys.version by SynaptSea · Pull Request #154209 · python/cpython

X Title: gh-154199: Fix find_msvcrt() on builds with a truncated sys.version by SynaptSea · Pull Request #154209 · python/cpython

Description: Fixes #154199 Python/getversion.c formats the compiler identification with "%.80s". The banner that PC/pyconfig.h emits for clang-cl builds is "[Clang " __clang_version__ "] 64 bit (AMD64) with MSC v. CRT]", and official LLVM Windows binaries have an 86-character __clang_version__ (version + repo URL + full commit hash), so the tail carrying the "MSC v." marker is always cut off. ctypes.util._get_build_version() looks for that marker and, not finding it, fell back to return 6 — "assume the compiler is MSVC 6". find_msvcrt() then maps version 6 to msvcrt.dll and find_library('c') returns it. That CRT does not share its errno with the ucrt that _ctypes is linked against, so ctypes.get_errno() silently returns stale values after a failing call. No exception is raised — the caller just gets wrong data. This reports the build version as unknown instead, so find_msvcrt() and find_library('c') return None exactly as they already do on modern MSVC builds (where _get_build_version() returns 14.x and the "CRT is no longer directly loadable" branch from bpo-23606 applies). find_msvcrt() already had a version is None guard, so this simply routes truncated banners into the existing safe path. While fixing that I found a second manifestation of the same truncation: when the cut lands inside the version digits, the marker is present but the number is not, and s, rest = sys.version[i:].split(" ", 1) raises ValueError: not enough values to unpack out of find_library('c') — worse than a wrong return value. partition() handles both cases. Happy to split that into its own PR if you would rather keep this one to the single change. The documented contract is unchanged: Doc/library/ctypes.rst already says find_msvcrt() returns None "if the name of the library cannot be determined", and that find_library("c") fails on Windows. Only the undocumented MSVC-6 fallback is removed. Testing Added FindLibraryWindows to Lib/test/test_ctypes/test_find.py. It patches sys.version with unittest.mock, so it exercises the fix on any Windows build — a clang-cl build is not needed to run it. It covers a truncated clang banner, a truncation inside the marker, and a real MSVC banner (asserting 14.4 / None, so the MSVC path is pinned against regression). On a local clang-cl free-threaded build, python -m test test_ctypes: before: run=674 failures=1 (test_errno.Test.test_open: AssertionError: 0 != 2) — FAILURE after: run=678 skipped=40 — SUCCESS test_open now skips with 'Unable to find C library', identical to an MSVC build. Three tests move from run to skipped (test_errno.test_open, test_loading.test_find, test_callbacks.test_issue_8959_a); all three already skip on MSVC builds, so this converges clang-cl onto the reference platform rather than reducing coverage. Verified no MSVC regression by mocking real banners: MSC v.1944 -> 14.4, MSC v.1600 -> msvcr100.dll, MSC v.1200 -> msvcrt.dll (a genuine MSVC 6 build is unaffected). The root cause is arguably the "%.80s" precision in Python/getversion.c — sys.version also ends mid-hash without its closing bracket on these builds, and it broke sysconfig.get_platform() the same way in gh-145410. I have not touched it here since that would change sys.version content for every consumer, but it may be worth a separate issue.

Open Graph Description: Fixes #154199 Python/getversion.c formats the compiler identification with "%.80s". The banner that PC/pyconfig.h emits for clang-cl builds is "[Clang " __clang_version__ "...

X Description: Fixes #154199 Python/getversion.c formats the compiler identification with "%.80s". The banner that PC/pyconfig.h emits for clang-cl builds is "[Clang " __clang_...

Opengraph URL: https://github.com/python/cpython/pull/154209

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:3f0f12e9-6d81-124c-c1a0-f3c4229ba0f3
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idDCE6:1AE20C:3E843EA:4F22A37:6B020806
html-safe-nonceef94c0c4da1ee94896b0dabd2f174add1e55a172baee338ee534ea3226780944
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQ0U2OjFBRTIwQzozRTg0M0VBOjRGMjJBMzc6NkIwMjA4MDYiLCJ2aXNpdG9yX2lkIjoiNTkwMzUxNTAwMDYzNDQ3NjU1MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac1385dd2538ab3c4d47b3af5841eaedf2dea08c93feaff51e9e793afc551a286e
hovercard-subject-tagpull_request:4087713504
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/154209/files
twitter:imagehttps://avatars.githubusercontent.com/u/36235551?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/36235551?s=400&v=4
og:image:altFixes #154199 Python/getversion.c formats the compiler identification with "%.80s". The banner that PC/pyconfig.h emits for clang-cl builds is "[Clang " __clang_version__ "...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/154209/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F154209%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F154209%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/154209/files
Reloadhttps://github.com/python/cpython/pull/154209/files
Reloadhttps://github.com/python/cpython/pull/154209/files
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
SynaptSeahttps://github.com/SynaptSea
python:mainhttps://github.com/python/cpython/tree/main
SynaptSea:fix-find-msvcrt-clanghttps://github.com/SynaptSea/cpython/tree/fix-find-msvcrt-clang
Conversation 2 https://github.com/python/cpython/pull/154209
Commits 1 https://github.com/python/cpython/pull/154209/commits
Checks 47 https://github.com/python/cpython/pull/154209/checks
Files changed https://github.com/python/cpython/pull/154209/files
Please reload this pagehttps://github.com/python/cpython/pull/154209/files
gh-154199: Fix find_msvcrt() on builds with a truncated sys.version https://github.com/python/cpython/pull/154209/files#top
Show all changes 1 commit https://github.com/python/cpython/pull/154209/files
eb69633 gh-154199: Fix find_msvcrt() on builds with a truncated sys.version SynaptSea Jul 19, 2026 https://github.com/python/cpython/pull/154209/commits/eb69633f69803166ab4cbc89f070cc482bc7b533
Clear filters https://github.com/python/cpython/pull/154209/files
Please reload this pagehttps://github.com/python/cpython/pull/154209/files
Please reload this pagehttps://github.com/python/cpython/pull/154209/files
util.py https://github.com/python/cpython/pull/154209/files#diff-bf1ae275d0ef9307536cedfa6e90f6846b3dc52e58582bde2dc7a2431262aadc
test_find.py https://github.com/python/cpython/pull/154209/files#diff-8fda35a68d62007940c297536743ea3e99262d48833ab7918698c61c0013236a
2026-07-19-21-40-00.gh-issue-154199.Kq3mVt.rst https://github.com/python/cpython/pull/154209/files#diff-635ce8adb03af84964af4e95f62dd032454a029f97045476de342c6a504e35e5
Lib/ctypes/util.pyhttps://github.com/python/cpython/pull/154209/files#diff-bf1ae275d0ef9307536cedfa6e90f6846b3dc52e58582bde2dc7a2431262aadc
View file https://github.com/SynaptSea/cpython/blob/eb69633f69803166ab4cbc89f070cc482bc7b533/Lib/ctypes/util.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/154209/{{ revealButtonHref }}
https://github.com/python/cpython/pull/154209/files#diff-bf1ae275d0ef9307536cedfa6e90f6846b3dc52e58582bde2dc7a2431262aadc
https://github.com/python/cpython/pull/154209/files#diff-bf1ae275d0ef9307536cedfa6e90f6846b3dc52e58582bde2dc7a2431262aadc
Lib/test/test_ctypes/test_find.pyhttps://github.com/python/cpython/pull/154209/files#diff-8fda35a68d62007940c297536743ea3e99262d48833ab7918698c61c0013236a
View file https://github.com/SynaptSea/cpython/blob/eb69633f69803166ab4cbc89f070cc482bc7b533/Lib/test/test_ctypes/test_find.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/154209/{{ revealButtonHref }}
https://github.com/python/cpython/pull/154209/files#diff-8fda35a68d62007940c297536743ea3e99262d48833ab7918698c61c0013236a
https://github.com/python/cpython/pull/154209/files#diff-8fda35a68d62007940c297536743ea3e99262d48833ab7918698c61c0013236a
Misc/NEWS.d/next/Library/2026-07-19-21-40-00.gh-issue-154199.Kq3mVt.rsthttps://github.com/python/cpython/pull/154209/files#diff-635ce8adb03af84964af4e95f62dd032454a029f97045476de342c6a504e35e5
View file https://github.com/SynaptSea/cpython/blob/eb69633f69803166ab4cbc89f070cc482bc7b533/Misc/NEWS.d/next/Library/2026-07-19-21-40-00.gh-issue-154199.Kq3mVt.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/154209/{{ revealButtonHref }}
Please reload this pagehttps://github.com/python/cpython/pull/154209/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.