8000 gh-114257: Ignore the `FileNotFound` error in `ctypes.util._is_elf` by aisk · Pull Request #114394 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-114257: Ignore the FileNotFound error in ctypes.util._is_elf #114394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 22, 2024
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
7 changes: 5 additions & 2 deletions Lib/ctypes/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ def find_library(name):
def _is_elf(filename):
"Return True if the given file is an ELF file"
elf_header = b'\x7fELF'
with open(filename, 'br') as thefile:
return thefile.read(4) == elf_header
try:
with open(filename, 'br') as thefile:
return thefile.read(4) == elf_header
except FileNotFoundError:
return False

def _findLib_gcc(name):
# Run GCC's linker with the -t (aka --trace) option and examine the
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_ctypes/test_find.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ def test_find_library_with_ld(self):
unittest.mock.patch("ctypes.util._findLib_gcc", lambda *args: None):
self.assertNotEqual(find_library('c'), None)

def test_gh114257(self):
self.assertIsNone(find_library("libc"))


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Dismiss the :exc:`FileNotFound` error in :func:`ctypes.util.find_library` and
just return ``None`` on Linux.
0