From e3f67780aab24401a50af64e688d38c24ee41ad0 Mon Sep 17 00:00:00 2001 From: Javier Castillo II Date: Sat, 10 Nov 2018 13:39:04 -0600 Subject: [PATCH 1/2] Issue #21622 Walk LD_LIBRARY_PATH for library FIXES bpo-21622 for 3.7 --- Lib/ctypes/util.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py index 97973bce001d9a..cafd4ae591e0f1 100644 --- a/Lib/ctypes/util.py +++ b/Lib/ctypes/util.py @@ -306,10 +306,34 @@ def _findLib_ld(name): pass # result will be None return result + def _findWalk_ldpath(name): + def _is_elf(filepath): + try: + with open(filepath, 'rb') as fh: + return fh.read(4) == b'\x7fELF' + except: + return False + from glob import glob + if os.path.isabs(name): + return name + # search LD_LIBRARY_PATH list + paths = os.environ.get('LD_LIBRARY_PATH', '').split(':') + if paths: + for d in paths: + f = os.path.join(d, name) + if _is_elf(f): + return os.path.basename(f) + prefix = os.path.join(d, 'lib'+name) + for suffix in ['.so', '.so.*']: + for f in glob('{0}{1}'.format(prefix, suffix)): + if _is_elf(f): + return os.path.basename(f) + def find_library(name): # See issue #9998 return _findSoname_ldconfig(name) or \ - _get_soname(_findLib_gcc(name) or _findLib_ld(name)) + _get_soname(_findLib_gcc(name) or _findLib_ld(name)) or \ + _findWalk_ldpath(name) ################################################################ # test code From 6bd8677385648c1ca60c8fd15fa49a496123d454 Mon Sep 17 00:00:00 2001 From: Javier Castillo II Date: Sat, 10 Nov 2018 15:11:40 -0600 Subject: [PATCH 2/2] Resolve typo impacting test_ctypes --- Lib/ctypes/util.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py index cafd4ae591e0f1..03bedce0255a24 100644 --- a/Lib/ctypes/util.py +++ b/Lib/ctypes/util.py @@ -307,14 +307,16 @@ def _findLib_ld(name): return result def _findWalk_ldpath(name): + def _is_elf(filepath): try: with open(filepath, 'rb') as fh: return fh.read(4) == b'\x7fELF' except: return False + from glob import glob - if os.path.isabs(name): + if os.path.isabs(name): return name # search LD_LIBRARY_PATH list paths = os.environ.get('LD_LIBRARY_PATH', '').split(':')