Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7fc51c3

Browse files
authored
gh-114257: Ignore the FileNotFound error in ctypes.util._is_elf() (GH-114394)
1 parented30a3c commit7fc51c3

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

‎Lib/ctypes/util.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,11 @@ def find_library(name):
9696
def_is_elf(filename):
9797
"Return True if the given file is an ELF file"
9898
elf_header=b'\x7fELF'
99-
withopen(filename,'br')asthefile:
100-
returnthefile.read(4)==elf_header
99+
try:
100+
withopen(filename,'br')asthefile:
101+
returnthefile.read(4)==elf_header
102+
exceptFileNotFoundError:
103+
returnFalse
101104

102105
def_findLib_gcc(name):
103106
# Run GCC's linker with the -t (aka --trace) option and examine the

‎Lib/test/test_ctypes/test_find.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ def test_find_library_with_ld(self):
125125
unittest.mock.patch("ctypes.util._findLib_gcc",lambda*args:None):
126126
self.assertNotEqual(find_library('c'),None)
127127

128+
deftest_gh114257(self):
129+
self.assertIsNone(find_library("libc"))
130+
128131

129132
if__name__=="__main__":
130133
unittest.main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Dismiss the:exc:`FileNotFound` error in:func:`ctypes.util.find_library` and
2+
just return ``None`` on Linux.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp