Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(158259)

Delta Between Two Patch Sets: Lib/ctypes/util.py

Issue 21042: ctypes.util.find_library() should return full pathname instead of filename in linux
Left Patch Set: Created 3 years, 10 months ago
Right Patch Set: Created 3 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/ctypes/test/test_find.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 import sys, os 1 import sys, os
2 import contextlib 2 import contextlib
3 import subprocess 3 import subprocess
4 4
5 # find_library(name) returns the pathname of a library, or None. 5 # find_library(name) returns the pathname of a library, or None.
6 if os.name == "nt": 6 if os.name == "nt":
7 7
8 def _get_build_version(): 8 def _get_build_version():
9 """Return the version of MSVC that was used to build Python. 9 """Return the version of MSVC that was used to build Python.
10 10
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 return _get_soname(_findLib_crle(name, is64) or _findLib_gcc(name)) 204 return _get_soname(_findLib_crle(name, is64) or _findLib_gcc(name))
205 205
206 else: 206 else:
207 207
208 def _findSoname_ldconfig(name): 208 def _findSoname_ldconfig(name):
209 import struct 209 import struct
210 if struct.calcsize('l') == 4: 210 if struct.calcsize('l') == 4:
211 machine = os.uname().machine + '-32' 211 machine = os.uname().machine + '-32'
212 else: 212 else:
213 machine = os.uname().machine + '-64' 213 machine = os.uname().machine + '-64'
214 mach_map = {
215 'x86_64-64': 'libc6,x86-64',
216 'ppc64-64': 'libc6,64bit',
217 'sparc64-64': 'libc6,64bit',
218 's390x-64': 'libc6,64bit',
219 'ia64-64': 'libc6,IA-64',
220 }
221 abi_type = mach_map.get(machine, 'libc6')
214 222
215 # XXX assuming GLIBC's ldconfig (with option -p) 223 # XXX assuming GLIBC's ldconfig (with option -p)
216 regex = os.fsencode( 224 regex = os.fsencode(
217 '([^\s]+lib%s\.[^\s]+)' % (re.escape(name))) 225 r'lib%s\.[^\s]+\s\(%s(?:,\s.*)?\)\s=>\s(.*)' % (re.escape(name), abi_type))
218 try: 226 try:
219 with subprocess.Popen(['/sbin/ldconfig', '-p'], 227 with subprocess.Popen(['/sbin/ldconfig', '-p'],
220 stdin=subprocess.DEVNULL, 228 stdin=subprocess.DEVNULL,
221 stderr=subprocess.DEVNULL, 229 stderr=subprocess.DEVNULL,
222 stdout=subprocess.PIPE, 230 stdout=subprocess.PIPE,
223 env={'LC_ALL': 'C', 'LANG': 'C'}) as p: 231 env={'LC_ALL': 'C', 'LANG': 'C'}) as p:
224 res = re.search(regex, p.stdout.read()) 232 res = re.search(regex, p.stdout.read())
225 if res: 233 if res:
226 return os.fsdecode(res.group(1)) 234 return os.fsdecode(res.group(1))
227 except OSError: 235 except OSError:
(...skipping 28 matching lines...) Expand all
256 print(cdll.LoadLibrary("libcrypto.dylib")) 264 print(cdll.LoadLibrary("libcrypto.dylib"))
257 print(cdll.LoadLibrary("libSystem.dylib")) 265 print(cdll.LoadLibrary("libSystem.dylib"))
258 print(cdll.LoadLibrary("System.framework/System")) 266 print(cdll.LoadLibrary("System.framework/System"))
259 else: 267 else:
260 print(cdll.LoadLibrary("libm.so")) 268 print(cdll.LoadLibrary("libm.so"))
261 print(cdll.LoadLibrary("libcrypt.so")) 269 print(cdll.LoadLibrary("libcrypt.so"))
262 print(find_library("crypt")) 270 print(find_library("crypt"))
263 271
264 if __name__ == "__main__": 272 if __name__ == "__main__":
265 test() 273 test()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+