René's URL Explorer Experiment


Title: bpo-44689: ctypes.util.find_library() now finds macOS 11+ system libraries when built on older macOS systems by bergkvist · Pull Request #27251 · python/cpython · GitHub

Open Graph Title: bpo-44689: ctypes.util.find_library() now finds macOS 11+ system libraries when built on older macOS systems by bergkvist · Pull Request #27251 · python/cpython

X Title: bpo-44689: ctypes.util.find_library() now finds macOS 11+ system libraries when built on older macOS systems by bergkvist · Pull Request #27251 · python/cpython

Description: Improve binary portability between MacOS versions https://bugs.python.org/issue44689 When compiling CPython using a MacOS Catalina build server, it won't work as expected when trying to run it on MacOS Big Sur. In particular, ctypes.util.find_library(name) will always return None. This PR adds support for compiling on an older MacOS version. Background Checking if a shared library exists on MacOS Big Sur is no longer possible by looking at the file system. Instead, Apple recommends the use of dlopen to check if a shared library exists (MacOS Big Sur 11.0.1 changenotes). Note that using dlopen to check for library existence is not ideal, since this might cause arbitrary side effects. _dyld_shared_cache_contains_path and build time requirements The current solution (introduced in #22855) to make find_library work on MacOS Big Sur does not use dlopen, but rather _dyld_shared_cache_contains_path from #include . This function/symbol is only available on MacOS Big Sur, meaning it will only be included if you compile CPython on MacOS Big Sur. In other words, if we compile CPython on MacOS Catalina, and move the binary to MacOS Big Sur, from _ctypes import _dyld_shared_cache_contains_path will raise an ImportError - and find_library will not work, always returning None. # ctypes/macholib/dyld.py # ... +try: + from _ctypes import _dyld_shared_cache_contains_path +except ImportError: + def _dyld_shared_cache_contains_path(*args): + raise NotImplementedError # ... def dyld_find(name, executable_path=None, env=None): """ Find a library or framework using dyld semantics """ for path in dyld_image_suffix_search(chain( dyld_override_search(name, env), dyld_executable_path_search(name, executable_path), dyld_default_search(name, env), ), env): if os.path.isfile(path): return path + try: + if _dyld_shared_cache_contains_path(path): + return path + except NotImplementedError: + pass # ... Method/Verification In order to support building for MacOS >= 11.0 (Big Sur or later) with a build server running MacOS < 11.0 (Catalina or earlier), we use dynamic loading to avoid errors when compiling. _dyld_shared_cache_contains_path will be resolved at runtime instead of compile-time, since it is not available at compile-time in this case. The downside to doing this at runtime instead of compile-time is that the compiler won't give us useful error messages. This is why we want to keep using the weak linking approach when compiling on MacOS >= 11.0 (Big Sur or later) - and only use dynamic loading to support the deprecated use case of compiling on an older MacOS version. To test that this works, I've set up 2 virtual machines using OSX-KVM on a Manjaro Linux host: Catalina (OS: macOS Catalina 10.15.7 19H15 x86_64, Kernel 19.6.0) Big Sur (OS: macOS 11.4 20F71 x86_64, Kernel: 20.5.0) Files are copied between the 2 virtual machines using rsync: #!/usr/bin/env bash rm -rf "./local" echo "Pulling from Catalina... (/usr/local/ -> ./local)" rsync -a -e "ssh -p 2222" tobias@localhost:/usr/local . echo "Pushing to BigSur... (./local/ -> /usr/local)" rsync -a -e "ssh -p 3222" ./local/* tobias@localhost:/usr/local/ echo "Done!" Checks Compile on Catalina and install, copy /usr/local/* over to BigSur, and call find_library('c') Results Before this change: ❌ Compile on Catalina and install, copy /usr/local/* over to BigSur, and call find_library('c') Python 3.11.0a0 (heads/main:635bfe8162, Jul 19 2021, 08:09:05) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from ctypes.util import find_library; print(find_library('c')) None After this change: ✔️ Compile on Catalina and install, copy /usr/local/* over to BigSur, and call find_library('c') Python 3.11.0a0 (heads/macos-ctypes-find-library:0858c0c9ff, Jul 19 2021, 17:52:24) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from ctypes.util import find_library; print(find_library('c')) /usr/lib/libc.dylib Related issues/Symptoms of the issue Note that some of these are closed due to the symptom having been treated - rather than the underlying cause. NixOS/nixpkgs#105038 jupyterlab/jupyterlab#9863 arsenetar/send2trash#51 minrk/appnope#12 jupyterlab/jupyterlab#9410 hbldh/bleak#372 https://bugs.python.org/issue43052 https://stackoverflow.com/questions/65065482/error-when-importing-pyautogui-on-macos-10-13-and-python-3-8 https://bugs.python.org/issue44689

Open Graph Description: Improve binary portability between MacOS versions https://bugs.python.org/issue44689 When compiling CPython using a MacOS Catalina build server, it won't work as expected when trying to run it ...

X Description: Improve binary portability between MacOS versions https://bugs.python.org/issue44689 When compiling CPython using a MacOS Catalina build server, it won&#39;t work as expected when trying to run...

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

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:8389dc10-e2e6-f640-e6a1-60648f80e280
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id8E76:C3948:46BA04A:6314185:6A4F78D5
html-safe-noncea4d9103309b4df459f74bd9bfdc9e28015721c4815f790edb3a51c81db97e8c8
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RTc2OkMzOTQ4OjQ2QkEwNEE6NjMxNDE4NTo2QTRGNzhENSIsInZpc2l0b3JfaWQiOiIxMjMwMTk4MDk0NDUwODMzNDkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac94a9ec4d6192b3430d8ba91aa718ea118d4ab56112499e5613f5072c57b4e148
hovercard-subject-tagpull_request:693027701
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/27251/files
twitter:imagehttps://avatars.githubusercontent.com/u/410028?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/410028?s=400&v=4
og:image:altImprove binary portability between MacOS versions https://bugs.python.org/issue44689 When compiling CPython using a MacOS Catalina build server, it won't work as expected when trying to run it ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noneb92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9
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
release4b249b445842943ed31549e027f57a8ade9881ed
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/27251/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F27251%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F27251%2Ffiles
Sign up https://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/27251/files
Reloadhttps://github.com/python/cpython/pull/27251/files
Reloadhttps://github.com/python/cpython/pull/27251/files
Please reload this pagehttps://github.com/python/cpython/pull/27251/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/27251/files
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 34.8k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.6k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.3k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality 0 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
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
ned-deilyhttps://github.com/ned-deily
python:mainhttps://github.com/python/cpython/tree/main
bergkvist:macos-ctypes-find-libraryhttps://github.com/bergkvist/cpython/tree/macos-ctypes-find-library
Conversation 21 https://github.com/python/cpython/pull/27251
Commits 7 https://github.com/python/cpython/pull/27251/commits
Checks 0 https://github.com/python/cpython/pull/27251/checks
Files changed https://github.com/python/cpython/pull/27251/files
Please reload this pagehttps://github.com/python/cpython/pull/27251/files
bpo-44689: ctypes.util.find_library() now finds macOS 11+ system libraries when built on older macOS systems https://github.com/python/cpython/pull/27251/files#top
Show all changes 7 commits https://github.com/python/cpython/pull/27251/files
0858c0c Add _ctypes.shared_library_is_loadable. Remove _ctypes._dyld_shared_c… bergkvist Jul 20, 2021 https://github.com/python/cpython/pull/27251/commits/0858c0c9ff6d99aa215a952ca0a4c977e3ce358f
b7aa289 Fix test_ctypes for Windows. bergkvist Jul 20, 2021 https://github.com/python/cpython/pull/27251/commits/b7aa289e4e2b4ceb364bed9129f91276511719d1
00388a2 📜🤖 Added by blurb_it. blurb-it[bot] Jul 20, 2021 https://github.com/python/cpython/pull/27251/commits/00388a25ddf3c0391a6643958c1c746db1cf93b8
9d3c834 bpo-44689: Remove dlopen in find_library. Load _dyld_shared_cache_con… bergkvist Jul 27, 2021 https://github.com/python/cpython/pull/27251/commits/9d3c83474efb5a78c6452b1a812c8d72ec8771fa
01bcf2b Update Misc/NEWS.d/next/macOS/2021-07-20-22-27-01.bpo-44689.mmT_xH.rst bergkvist Jul 27, 2021 https://github.com/python/cpython/pull/27251/commits/01bcf2bef5f4ffffb454da35cb66b186a7a12598
52473a4 bpo-44689: Revert to using weak linking implementation. Only use dyna… bergkvist Aug 6, 2021 https://github.com/python/cpython/pull/27251/commits/52473a484b2f0bfc6776dc7b483c0a253fb1f996
dfcc357 bpo-44689: edit NEWS blurb and comment ned-deily Aug 30, 2021 https://github.com/python/cpython/pull/27251/commits/dfcc35789e97e94a8ae04650ef39fc08f33ecc7d
Clear filters https://github.com/python/cpython/pull/27251/files
Please reload this pagehttps://github.com/python/cpython/pull/27251/files
Please reload this pagehttps://github.com/python/cpython/pull/27251/files
2021-07-20-22-27-01.bpo-44689.mmT_xH.rst https://github.com/python/cpython/pull/27251/files#diff-2b9a9f1149cacaf6ef23681de7fcc6e7dc82b462ca5bc418e985325e2fb0d943
callproc.c https://github.com/python/cpython/pull/27251/files#diff-4e23b3237d0aa08bf4c434d75fab19200a80837bd147051fefccd98b7f2480fa
Misc/NEWS.d/next/macOS/2021-07-20-22-27-01.bpo-44689.mmT_xH.rsthttps://github.com/python/cpython/pull/27251/files#diff-2b9a9f1149cacaf6ef23681de7fcc6e7dc82b462ca5bc418e985325e2fb0d943
View file https://github.com/bergkvist/cpython/blob/dfcc35789e97e94a8ae04650ef39fc08f33ecc7d/Misc/NEWS.d/next/macOS/2021-07-20-22-27-01.bpo-44689.mmT_xH.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/27251/{{ revealButtonHref }}
Modules/_ctypes/callproc.chttps://github.com/python/cpython/pull/27251/files#diff-4e23b3237d0aa08bf4c434d75fab19200a80837bd147051fefccd98b7f2480fa
View file https://github.com/bergkvist/cpython/blob/dfcc35789e97e94a8ae04650ef39fc08f33ecc7d/Modules/_ctypes/callproc.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/27251/{{ revealButtonHref }}
https://github.com/python/cpython/pull/27251/files#diff-4e23b3237d0aa08bf4c434d75fab19200a80837bd147051fefccd98b7f2480fa
https://github.com/python/cpython/pull/27251/files#diff-4e23b3237d0aa08bf4c434d75fab19200a80837bd147051fefccd98b7f2480fa
https://github.com/python/cpython/pull/27251/files#diff-4e23b3237d0aa08bf4c434d75fab19200a80837bd147051fefccd98b7f2480fa
https://github.com/python/cpython/pull/27251/files#diff-4e23b3237d0aa08bf4c434d75fab19200a80837bd147051fefccd98b7f2480fa
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.