Skip to content
Open
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
2 changes: 1 addition & 1 deletion Lib/ctypes/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def find_library(name):
# https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/dyld.3.html
import ctypes

_libc = ctypes.CDLL(find_library("c"))
_libc = ctypes.CDLL(None)
_dyld_get_image_name = _libc["_dyld_get_image_name"]
_dyld_get_image_name.restype = ctypes.c_char_p

Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_ctypes/test_dllist.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from ctypes import CDLL
import ctypes.util
from test.support import import_helper
from unittest.mock import patch


WINDOWS = os.name == "nt"
Expand Down Expand Up @@ -54,6 +55,13 @@ def test_lists_updates(self):
self.assertGreater(dlls2, dlls1, f"newly loaded libraries: {dlls2 - dlls1}")
self.assertTrue(any("_ctypes_test" in dll for dll in dlls2), f"loaded={dlls2}")

@unittest.skipUnless(APPLE, "requires an Apple platform")
def test_import_does_not_search_for_libc(self):
self.addCleanup(setattr, ctypes, "util", ctypes.util)
with patch("ctypes.macholib.dyld.dyld_find", return_value=None) as find:
import_helper.import_fresh_module("ctypes.util")
find.assert_not_called()


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a bug where importing :mod:`!ctypes.util` on macOS could load
``libc.dylib`` from the current working directory. Patch by Maurycy
Pawłowski-Wieroński.
Loading