mirror of https://github.com/python/cpython
Merge r68487 from svn+ssh://pythondev@svn.python.org/python/trunk:
- Issue #4861: ctypes.util.find_library(): Robustify. Fix library detection on biarch systems. Try to rely on ldconfig only, without using objdump and gcc.
This commit is contained in:
parent
49956b26a2
commit
2c7e3ee79b
|
@ -89,20 +89,22 @@ elif os.name == "posix":
|
||||||
expr = r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
|
expr = r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
|
||||||
fdout, ccout = tempfile.mkstemp()
|
fdout, ccout = tempfile.mkstemp()
|
||||||
os.close(fdout)
|
os.close(fdout)
|
||||||
cmd = 'if type gcc >/dev/null 2>&1; then CC=gcc; else CC=cc; fi;' \
|
cmd = 'if type gcc >/dev/null 2>&1; then CC=gcc; elif type cc >/dev/null 2>&1; then CC=cc;else exit 10; fi;' \
|
||||||
'$CC -Wl,-t -o ' + ccout + ' 2>&1 -l' + name
|
'$CC -Wl,-t -o ' + ccout + ' 2>&1 -l' + name
|
||||||
try:
|
try:
|
||||||
f = os.popen(cmd)
|
f = os.popen(cmd)
|
||||||
try:
|
try:
|
||||||
trace = f.read()
|
trace = f.read()
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
rv = f.close()
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
os.unlink(ccout)
|
os.unlink(ccout)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno != errno.ENOENT:
|
if e.errno != errno.ENOENT:
|
||||||
raise
|
raise
|
||||||
|
if rv == 10:
|
||||||
|
raise OSError, 'gcc or cc command not found'
|
||||||
res = re.search(expr, trace)
|
res = re.search(expr, trace)
|
||||||
if not res:
|
if not res:
|
||||||
return None
|
return None
|
||||||
|
@ -129,7 +131,13 @@ elif os.name == "posix":
|
||||||
# assuming GNU binutils / ELF
|
# assuming GNU binutils / ELF
|
||||||
if not f:
|
if not f:
|
||||||
return None
|
return None
|
||||||
cmd = "objdump -p -j .dynamic 2>/dev/null " + f
|
cmd = 'if ! type objdump >/dev/null 2>&1; then exit 10; fi;' \
|
||||||
|
"objdump -p -j .dynamic 2>/dev/null " + f
|
||||||
|
f = os.popen(cmd)
|
||||||
|
dump = f.read()
|
||||||
|
rv = f.close()
|
||||||
|
if rv == 10:
|
||||||
|
raise OSError, 'objdump command not found'
|
||||||
f = os.popen(cmd)
|
f = os.popen(cmd)
|
||||||
try:
|
try:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
|
@ -193,8 +201,32 @@ elif os.name == "posix":
|
||||||
return None
|
return None
|
||||||
return res.group(0)
|
return res.group(0)
|
||||||
|
|
||||||
|
def _findSoname_ldconfig(name):
|
||||||
|
import struct
|
||||||
|
if struct.calcsize('l') == 4:
|
||||||
|
machine = os.uname()[4] + '-32'
|
||||||
|
else:
|
||||||
|
machine = os.uname()[4] + '-64'
|
||||||
|
mach_map = {
|
||||||
|
'x86_64-64': 'libc6,x86-64',
|
||||||
|
'ppc64-64': 'libc6,64bit',
|
||||||
|
'sparc64-64': 'libc6,64bit',
|
||||||
|
's390x-64': 'libc6,64bit',
|
||||||
|
'ia64-64': 'libc6,IA-64',
|
||||||
|
}
|
||||||
|
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))
|
||||||
|
res = re.search(expr,
|
||||||
|
os.popen('/sbin/ldconfig -p 2>/dev/null').read())
|
||||||
|
if not res:
|
||||||
|
return None
|
||||||
|
return res.group(1)
|
||||||
|
|
||||||
def find_library(name):
|
def find_library(name):
|
||||||
return _get_soname(_findLib_ldconfig(name) or _findLib_gcc(name))
|
return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
|
||||||
|
|
||||||
################################################################
|
################################################################
|
||||||
# test code
|
# test code
|
||||||
|
|
|
@ -236,6 +236,9 @@ Library
|
||||||
support unusual filenames (such as those containing semi-colons) in
|
support unusual filenames (such as those containing semi-colons) in
|
||||||
Content-Disposition headers.
|
Content-Disposition headers.
|
||||||
|
|
||||||
|
- Issue #4861: ctypes.util.find_library(): Robustify. Fix library detection on
|
||||||
|
biarch systems. Try to rely on ldconfig only, without using objdump and gcc.
|
||||||
|
|
||||||
Tools/Demos
|
Tools/Demos
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue