From 31701e1d90be15e892a4c35b87dda0a6a08725ed Mon Sep 17 00:00:00 2001 From: AN Long Date: Mon, 22 Jan 2024 00:25:43 +0800 Subject: [PATCH 1/4] gh-114257: Ignore the `FileNotFound` error in `ctypes.util._is_elf` --- Lib/ctypes/util.py | 7 +++++-- Lib/test/test_ctypes/test_find.py | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py index 0c2510e1619c8e..c550883e7c7d4b 100644 --- a/Lib/ctypes/util.py +++ b/Lib/ctypes/util.py @@ -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 diff --git a/Lib/test/test_ctypes/test_find.py b/Lib/test/test_ctypes/test_find.py index 66ff23e72b5e10..7732ff37308848 100644 --- a/Lib/test/test_ctypes/test_find.py +++ b/Lib/test/test_ctypes/test_find.py @@ -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() From 5c119c15a8a86e7e52ee536f3aef48aff9c0aa9b Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 21 Jan 2024 16:33:00 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst diff --git a/Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst b/Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst new file mode 100644 index 00000000000000..40cee711a373bf --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst @@ -0,0 +1 @@ +Ignore the :exc:`FileNotFound` error in :func:`ctypes.util._is_elf` and just return ``False``. From f9460834c7ffca39e7c26dfd1e0718d7db8efa8f Mon Sep 17 00:00:00 2001 From: AN Long Date: Tue, 23 Jan 2024 00:21:13 +0800 Subject: [PATCH 3/4] update news entry --- .../Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst b/Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst index 40cee711a373bf..49a4c40f73215c 100644 --- a/Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst +++ b/Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst @@ -1 +1,2 @@ -Ignore the :exc:`FileNotFound` error in :func:`ctypes.util._is_elf` and just return ``False``. +Dissmiss the :exc:`FileNotFound` error in :func:`ctypes.util.find_library` and +just return ``None`` on Linux. From deae7c64675b32e4e33bfe4851fcef6c0666d40f Mon Sep 17 00:00:00 2001 From: AN Long Date: Tue, 23 Jan 2024 00:35:36 +0800 Subject: [PATCH 4/4] Update Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst --- .../next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst b/Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst index 49a4c40f73215c..6f02ff9e62617d 100644 --- a/Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst +++ b/Misc/NEWS.d/next/Library/2024-01-21-16-32-55.gh-issue-114257.bCFld5.rst @@ -1,2 +1,2 @@ -Dissmiss the :exc:`FileNotFound` error in :func:`ctypes.util.find_library` and +Dismiss the :exc:`FileNotFound` error in :func:`ctypes.util.find_library` and just return ``None`` on Linux.