8000 [2.7] bpo-21622 ctypes.util find_library walk LD_LIBRARY_PATH (GH-10453) by jcastillo2nd · Pull Request #10455 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[2.7] bpo-21622 ctypes.util find_library walk LD_LIBRARY_PATH (GH-10453) #10455

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

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
Next Next commit
Issue #21622 Walk LD_LIBRARY_PATH for library
FIXES bpo-21622 for 2.7
  • Loading branch information
jcastillo2nd authored Nov 10, 2018
commit 0e3163f48ce5cce50fd8e7a0f70c90881aa75fc2
28 changes: 27 additions & 1 deletion Lib/ctypes/util.py
Ori 8000 ginal file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,34 @@ def _findSoname_ldconfig(name):
return None
return res.group(1)

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):
return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
return _findSoname_ldconfig(name) or \
_get_soname(_findLib_gcc(name)) or \
_findWalk_ldpath(name)

################################################################
# test code
Expand Down
0