Skip to content

gh-162362: Resolve dyld functions from the process on import ctypes.util on macOS - #162363

Merged
ZeroIntensity merged 6 commits into
python:mainfrom
maurycy:ctypes-find-library-cwd
Dec 1, 2026
Merged

ZeroIntensity merged 6 commits into
python:mainfrom
maurycy:ctypes-find-library-cwd

Conversation

@maurycy

@maurycy maurycy commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Use CDLL(None) to look up _dyld_image_count and _dyld_get_image_name. Both symbols are already available in the process. This removes the import-time search for libc, which could load a library from the working directory on macOS.

Fixes #162362

@encukou

encukou commented Nov 23, 2026

Copy link
Copy Markdown
Member

!buildbot macOS

@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @encukou for commit e3cba4d 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F162363%2Fmerge

The command will test the builders whose names match following regular expression: macOS

The builders matched are:

  • x86-64 MacOS Intel NoGIL PR
  • x86-64 macOS PR
  • ARM64 MacOS M1 Refleaks NoGIL PR
  • ARM64 MacOS M1 NoGIL PR
  • x86-64 MacOS Intel ASAN NoGIL PR
  • ARM64 macOS PR

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I don't have access to macOS, so I cannot test this change manually. But if _libc["_dyld_get_image_name"] still works when using ctypes.CDLL(None), I think that it's safer and more reliable to use ctypes.CDLL(None).

I see that ctypes.util.dllist() is tested by Lib/test/test_ctypes/test_dllist.py. So if test_ctypes pass on GHA macOS and macOS buildbots, we are good :-)

@ZeroIntensity ZeroIntensity added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Dec 1, 2026
@ZeroIntensity
ZeroIntensity merged commit 6a663aa into python:main Dec 1, 2026
68 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @maurycy for the PR, and @ZeroIntensity for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@bedevere-app

bedevere-app Bot commented Dec 1, 2026

Copy link
Copy Markdown

GH-162899 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Dec 1, 2026
@bedevere-app

bedevere-app Bot commented Dec 1, 2026

Copy link
Copy Markdown

GH-162900 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Dec 1, 2026
@maurycy
maurycy deleted the ctypes-find-library-cwd branch December 1, 2026 00:57
ZeroIntensity pushed a commit that referenced this pull request Dec 1, 2026
…ctypes.util` on macOS (GH-162363) (GH-162900)

(cherry picked from commit 6a663aa)

Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
ZeroIntensity pushed a commit that referenced this pull request Dec 1, 2026
…ctypes.util` on macOS (GH-162363) (GH-162899)

(cherry picked from commit 6a663aa)

Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
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.

import ctypes.util on macOS loads a library from the working directory

5 participants