Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ffeee35

Browse files
committed
Issue #13979: Fix ctypes.util.find_library ldconfig regex
1 parent a127ecb commit ffeee35

2 files changed

Lines changed: 4 additions & 18 deletions

File tree

Lib/ctypes/util.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -171,22 +171,6 @@ def find_library(name):
171171

172172
else:
173173

174-
def _findLib_ldconfig(name):
175-
# XXX assuming GLIBC's ldconfig (with option -p)
176-
expr = r'/[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
177-
with contextlib.closing(os.popen('/sbin/ldconfig -p 2>/dev/null')) as f:
178-
data = f.read()
179-
res = re.search(expr, data)
180-
if not res:
181-
# Hm, this works only for libs needed by the python executable.
182-
cmd = 'ldd %s 2>/dev/null' % sys.executable
183-
with contextlib.closing(os.popen(cmd)) as f:
184-
data = f.read()
185-
res = re.search(expr, data)
186-
if not res:
187-
return None
188-
return res.group(0)
189-
190174
def _findSoname_ldconfig(name):
191175
import struct
192176
if struct.calcsize('l') == 4:
@@ -203,8 +187,7 @@ def _findSoname_ldconfig(name):
203187
abi_type = mach_map.get(machine, 'libc6')
204188

205189
# XXX assuming GLIBC's ldconfig (with option -p)
206-
expr = r'(\S+)\s+\((%s(?:, OS ABI:[^\)]*)?)\)[^/]*(/[^\(\)\s]*lib%s\.[^\(\)\s]*)' \
207-
% (abi_type, re.escape(name))
190+
expr = r'\s+(lib%s\.[^\s]+)\s+\(%s' % (re.escape(name), abi_type)
208191
with contextlib.closing(os.popen('LC_ALL=C LANG=C /sbin/ldconfig -p 2>/dev/null')) as f:
209192
data = f.read()
210193
res = re.search(expr, data)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ Core and Builtins
113113
Library
114114
-------
115115

116+
- Issue #13979: A bug in ctypes.util.find_library that caused
117+
the wrong library name to be returned has been fixed.
118+
116119
- Issue #13993: HTMLParser is now able to handle broken end tags when
117120
strict=False.
118121

0 commit comments

Comments
 (0)