Skip to content

Remove broken dlopen in pyobjc_internal_init; fix bogus fallback path#150

Open
ElliotGarbus wants to merge 2 commits into
kivy:masterfrom
ElliotGarbus:fix/runtime-h-dlopen-noise
Open

Remove broken dlopen in pyobjc_internal_init; fix bogus fallback path#150
ElliotGarbus wants to merge 2 commits into
kivy:masterfrom
ElliotGarbus:fix/runtime-h-dlopen-noise

Conversation

@ElliotGarbus

Copy link
Copy Markdown

Summary

Fixes #146.

pyobjc_internal_init() in _runtime.h tries to dlopen Foundation by absolute filesystem path. On iOS 16+ (and matching simulators) that path does not exist — Apple moved system frameworks fully into the dyld shared cache. The call always fails, printing two noisy error lines on every app launch. The /Groups/System/… fallback path has never corresponded to any real macOS or iOS directory and was not corrected when #22 and #36 were closed in 2016.

The fix is safe because:

  • The foundation dlopen handle is written once and never read — verified by searching the tree for all uses of the variable.
  • allocAndInitAutoreleasePool() reaches NSAutoreleasePool via objc_getClass, which goes through the ObjC runtime's class registry and has no dependency on the dlopen handle.
  • Foundation is already mapped into the process via direct linking before pyobjc_internal_init() runs, so the ObjC runtime works without an explicit handle.

Changes

  • pyobjus/_runtime.h — empty the body of pyobjc_internal_init() and drop the now-unused <stdio.h> and <dlfcn.h> includes.

Result

The two Got dlopen error on Foundation / Got fallback dlopen error on Foundation lines that appeared on every launch are gone. No other behaviour changes.

On iOS 16+ system frameworks live only in the dyld shared cache —
there is no on-disk file to dlopen.  The absolute-path dlopen always
fails and prints two scary-looking error lines on every launch.  The
/Groups/System/… fallback path has never existed on any Apple OS and
was not fixed when kivy#22 and kivy#36 were closed in 2016.

The dlopen handle was never read after being written; Foundation is
already mapped into the process via direct linking before
pyobjc_internal_init() runs, so the ObjC runtime (objc_getClass, …)
works without it.  Empty the function body and drop the now-unused
<stdio.h> and <dlfcn.h> includes.

Closes kivy#146
connection_didFailWithError_ calls CFRunLoopStop after each failure, so a
single CFRunLoopRunInMode call exits after the first delegate fires and
the second connection's event is never delivered.  Run the loop in short
bursts, restarting after each CFRunLoopStop, until both delegates have
been called.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_runtime.h: Foundation dlopen() always fails on modern iOS; /Groups/System/... fallback path is bogus (reprises #22, #36)

1 participant