https://github.com/python/cpython/commit/918fb3aec907baf8d9b6181570ff308529be16a3
commit: 918fb3aec907baf8d9b6181570ff308529be16a3
branch: main
author: Clément Péron <[email protected]>
committer: freakboy3742 <[email protected]>
date: 2026-08-22T11:51:49+08:00
summary:
gh-156112: Load the ObjC runtime by name when find_library() cannot resolve it
(#156113)
Provides a fallback name for the ObjC runtime library on iOS, and improved
error
handling when that library cannot be loaded.
files:
A Misc/NEWS.d/next/Library/2026-08-20-13-50-49.gh-issue-156112.yEcma8.rst
M Lib/_ios_support.py
diff --git a/Lib/_ios_support.py b/Lib/_ios_support.py
index 20467a7c2bcaeb..cc51aa504916e3 100644
--- a/Lib/_ios_support.py
+++ b/Lib/_ios_support.py
@@ -10,12 +10,15 @@
else:
# ctypes is available. Load the ObjC library, and wrap the objc_getClass,
# sel_registerName methods
- lib = util.find_library("objc")
- if lib is None:
- # Failed to load the objc library
- raise ImportError("ObjC runtime library couldn't be loaded")
+ # find_library() resolves a system library through the dyld shared cache,
+ # which needs _dyld_shared_cache_contains_path(); that is unavailable
before
+ # iOS 14, so fall back to the bare name, which dyld resolves by itself.
+ lib = util.find_library("objc") or "libobjc.dylib"
- objc = cdll.LoadLibrary(lib)
+ try:
+ objc = cdll.LoadLibrary(lib)
+ except OSError:
+ raise ImportError("ObjC runtime library couldn't be loaded")
objc.objc_getClass.restype = c_void_p
objc.objc_getClass.argtypes = [c_char_p]
objc.sel_registerName.restype = c_void_p
diff --git
a/Misc/NEWS.d/next/Library/2026-08-20-13-50-49.gh-issue-156112.yEcma8.rst
b/Misc/NEWS.d/next/Library/2026-08-20-13-50-49.gh-issue-156112.yEcma8.rst
new file mode 100644
index 00000000000000..ba92df3c5cb6c1
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-08-20-13-50-49.gh-issue-156112.yEcma8.rst
@@ -0,0 +1,4 @@
+:mod:`!_ios_support` no longer fails to import when
+:func:`ctypes.util.find_library` cannot resolve the ObjC runtime through the
+dyld shared cache, as is the case on iOS 13. The runtime is now loaded by name,
+which dyld resolves against the cache directly.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]