Title: gh-153711: Guard dup3/pipe2 with __builtin_available on Apple platforms by Vamsi-klu · Pull Request #154718 · python/cpython · GitHub
Open Graph Title: gh-153711: Guard dup3/pipe2 with __builtin_available on Apple platforms by Vamsi-klu · Pull Request #154718 · python/cpython
X Title: gh-153711: Guard dup3/pipe2 with __builtin_available on Apple platforms by Vamsi-klu · Pull Request #154718 · python/cpython
Description: Summary Fix gh-153711 (deferred-blocker): when CPython is built with an Xcode 27 SDK, dup3 / pipe2 are detected at configure time but only exist at runtime on macOS / iOS 27+. On older OSes they bind as weak_import NULL and the first os.pipe() / non-inheritable os.dup2() jumps to address 0. What the issue is Xcode 27 SDKs annotate dup3/pipe2 with __API_AVAILABLE(macos(27.0), iOS(27.0), …). AC_CHECK_FUNCS synthesizes its own char dup3(); prototype, ignores availability, links against libSystem.tbd, and defines HAVE_DUP3 / HAVE_PIPE2. Modules/posixmodule.c then calls them unconditionally inside os_dup2_impl / os_pipe_impl / os_pipe2_impl. With MACOSX_DEPLOYMENT_TARGET < 27, the symbols are weak; on macOS 26 they are NULL → EXC_BAD_ACCESS. os.pipe() is on the hot path of subprocess, multiprocessing, and asyncio — effectively a total-loss crash for python.org-style builds. iOS was already excluded from the configure check (gh-150443 / #150444). macOS was not. The issue body already points at the gh-97897 (mkfifoat/mknodat) weak-linking pattern. Why I solved it that way Runtime __builtin_available guards, not configure hacks — configure cannot see availability attributes, and we still want the symbols on macOS 27+. Reuse the existing three-arm HAVE_*_RUNTIME machinery in posixmodule.c (modern / Xcode≤8 / non-Apple) documented in Mac/README.rst. Omitting any arm breaks the build. Sole-expression if (HAVE_X_RUNTIME) — Apple's compiler rejects if (!HAVE_X_RUNTIME). Latch dup3_works = 0 when unavailable so the existing dup2+FD_CLOEXEC fallback runs this call and every later call without re-probing. Seed res = -1; errno = ENOSYS before the pipe2 probe so the existing ENOSYS → pipe() fallback still runs when the symbol is missing (uninitialized res/errno would be a footgun). Pop os.pipe2 from the module dict when unavailable (same idiom as pwritev/preadv) because os_pipe2_impl has no fallback and would crash on direct call. Existing tests already hasattr(os, "pipe2"). Omit visionOS from __builtin_available — no other macro in the block names it; pre-Xcode-15 clang rejects the spelling. Honest verification limit: this environment is Linux. Code mirrors gh-97897; an OS-mac core dev with Xcode 27 should confirm on macOS 26. How I did it Area Change Modules/posixmodule.c HAVE_DUP3_RUNTIME / HAVE_PIPE2_RUNTIME in all 3 arms; guard dup3/pipe2 call sites; pop pipe2 at exec Lib/test/test_os/test_posix.py TestPosixWeaklinking.test_pipe2 / test_dup3 Doc/library/os.rst os.pipe2 availability notes macOS/iOS ≥ 27 Misc/NEWS.d/next/macOS/ blurb for gh-153711 Impact Unblocks building with Xcode 27 SDKs while deploying to macOS < 27. On Linux/non-Apple, macros are 1 — zero codegen change (constant-folded). On macOS ≥ 27, behavior unchanged (fast path still used). Deferred-blocker across 3.13–3.16 — backports appropriate after OS-mac review. Testing plan Linux debug build + ./python -m test test_os.test_posix — PASS (weaklinking class skipped on non-macOS, as designed). Smoke: os.pipe() / os.dup2(..., inheritable=False) on Linux — OK. Needed from reviewer / buildbot: macOS 26 host, Xcode 27 SDK, deployment target < 27: Before: crash on os.pipe() / os.pipe2 / non-inheritable dup2. After: os.pipe() works via fallback; hasattr(os, "pipe2") is False; TestPosixWeaklinking assertions hold. macOS 27+ : pipe2 present, weaklinking tests assert attrs exist. CI: macOS jobs (will not fully exercise the Xcode 27 × older OS matrix). Everything else Does not undo iOS configure exclusion from #150444. Pattern credit: Ned Deily's gh-97897 / commit for mkfifoat/mknodat. Backports: 3.15, 3.14, 3.13 after merge. Reviewers: OS-mac / Apple platform SMEs. Requested reviewers (subject-matter experts) Could the following SMEs take a look when convenient (I cannot formally request reviews from this fork account): ned-deily — OS-mac / weak-linking (gh-97897 pattern) ronaldoussoren — macOS freakboy3742 — Apple/iOS (adjacent gh-150443) Thank you!
Open Graph Description: Summary Fix gh-153711 (deferred-blocker): when CPython is built with an Xcode 27 SDK, dup3 / pipe2 are detected at configure time but only exist at runtime on macOS / iOS 27+. On older OSes they bi...
X Description: Summary Fix gh-153711 (deferred-blocker): when CPython is built with an Xcode 27 SDK, dup3 / pipe2 are detected at configure time but only exist at runtime on macOS / iOS 27+. On older OSes they bi...
Opengraph URL: https://github.com/python/cpython/pull/154718
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,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-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:f5d7f546-c9f1-2194-bedf-7079085945c9 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 843E:19299:1095F9:172089:6AFDADA5 |
| html-safe-nonce | c299c0ff1e70b18bf30c3df34d2c8fdb7f619f77888e8192b57ea54c87e8e668 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NDNFOjE5Mjk5OjEwOTVGOToxNzIwODk6NkFGREFEQTUiLCJ2aXNpdG9yX2lkIjoiODM1NDUzNTM3NzY5NTc4MDI2MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2cd9c9ee8673b7a3aa83b265ba770e83444f414fc2cbcf818187ae28fa8e82d5 |
| hovercard-subject-tag | pull_request:4135411285 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/154718/files |
| twitter:image | https://avatars.githubusercontent.com/u/32898216?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/32898216?s=400&v=4 |
| og:image:alt | Summary Fix gh-153711 (deferred-blocker): when CPython is built with an Xcode 27 SDK, dup3 / pipe2 are detected at configure time but only exist at runtime on macOS / iOS 27+. On older OSes they bi... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | bc86424ef34a73b386237872800e922d149d65ba907f63d6f150a2dcb8433bea |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 0ddf53eb35c87f1f8df13dbf75c3bdadbfc6e969 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width