mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
Issue #11258: Speed up ctypes.util.find_library() under Linux a lot. Patch
by Jonas H.
This commit is contained in:
parent
ec5a2d5e89
commit
ffa1a77c67
4 changed files with 22 additions and 7 deletions
|
|
@ -203,14 +203,18 @@ def _findSoname_ldconfig(name):
|
|||
abi_type = mach_map.get(machine, 'libc6')
|
||||
|
||||
# XXX assuming GLIBC's ldconfig (with option -p)
|
||||
expr = r'(\S+)\s+\((%s(?:, OS ABI:[^\)]*)?)\)[^/]*(/[^\(\)\s]*lib%s\.[^\(\)\s]*)' \
|
||||
% (abi_type, re.escape(name))
|
||||
name = 'lib%s' % name
|
||||
pat = re.compile('\s*(/[^\(\)\s]*%s\.[^\(\)\s]*)' % re.escape(name))
|
||||
with contextlib.closing(os.popen('LC_ALL=C LANG=C /sbin/ldconfig -p 2>/dev/null')) as f:
|
||||
data = f.read()
|
||||
res = re.search(expr, data)
|
||||
if not res:
|
||||
return None
|
||||
return res.group(1)
|
||||
for line in f:
|
||||
if not '=>' in line:
|
||||
continue
|
||||
path = line.rsplit('=>', 1)[1]
|
||||
if not name+'.' in path:
|
||||
continue
|
||||
res = pat.search(path)
|
||||
if res:
|
||||
return res.group(1)
|
||||
|
||||
def find_library(name):
|
||||
return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue