Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
gh-156112: Load the ObjC runtime by name when find_library() cannot r…
…esolve it (GH-156113)

Provides a fallback name for the ObjC runtime library on iOS, and improved error
handling when that library cannot be loaded.
(cherry picked from commit 918fb3a)

Co-authored-by: Clément Péron <peron.clem@gmail.com>
  • Loading branch information
clementperon authored and miss-islington committed Aug 22, 2026
commit 783e33880dbb072be4f4327e4a4f7d64dbec3f87
13 changes: 8 additions & 5 deletions Lib/_ios_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Loading