mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
[3.12] gh-114257: Ignore the FileNotFound error in ctypes.util._is_elf() (GH-114394) (GH-114444)
(cherry picked from commit 7fc51c3f6b)
Co-authored-by: AN Long <aisk@users.noreply.github.com>
This commit is contained in:
parent
4bbb9f6f29
commit
ed567c1e1f
3 changed files with 10 additions and 2 deletions
|
|
@ -96,8 +96,11 @@ elif os.name == "posix":
|
|||
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
|
||||
|
|
|
|||
|
|
@ -122,6 +122,9 @@ class FindLibraryLinux(unittest.TestCase):
|
|||
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()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
Dismiss the :exc:`FileNotFound` error in :func:`ctypes.util.find_library` and
|
||||
just return ``None`` on Linux.
|
||||
Loading…
Add table
Add a link
Reference in a new issue