8000 [3.12] gh-114257: Ignore the FileNotFound error in ctypes.util._is_elf() (GH-114394) by miss-islington · Pull Request #114444 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.12] gh-114257: Ignore the FileNotFound error in ctypes.util._is_elf() (GH-114394) #114444

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 1 commit 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
gh-114257: Ignore the FileNotFound error in ctypes.util._is_elf() (GH…
…-114394)

(cherry picked from commit 7fc51c3)

Co-authored-by: AN Long <aisk@users.noreply.github.com>
  • Loading branch information
aisk authored and miss-islington committed Jan 22, 2024
commit d256c8c37714ab633c48d03f3c11f24b7a5b102f
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 @@ -122,6 +122,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