python: fix ctypes.util.find_library() with musl; patch from Alpine.

This patch should also work for glibc, so that it's applied unconditionally.
It's unfortunate that this code on glibc relies on `ldconfig -p` to work
correctly.
This commit is contained in:
Juan RP 2015-08-13 07:15:33 +02:00
parent 1674e75ffb
commit a99a70dcc8
2 changed files with 44 additions and 1 deletions

View File

@ -0,0 +1,43 @@
See http://bugs.alpinelinux.org/issues/4512
--- Lib/ctypes/util.py
+++ Lib/ctypes/util.py
@@ -238,8 +238,37 @@ elif os.name == "posix":
return None
return res.group(1)
+ def _is_elf(filepath):
+ try:
+ with open(filepath, 'rb') as fh:
+ return fh.read(4) == b'\x7fELF'
+ except:
+ return False
+
+ def _find_libfile(name):
+ from glob import glob
+ # special case for libm, libcrypt and libpthread and musl
+ if name in ['m', 'crypt', 'pthread']:
+ name = 'c'
+ elif name in ['libm.so', 'libcrypt.so', 'libpthread.so']:
+ name = 'libc.so'
+ # search in standard locations
+ paths = ['/lib', '/usr/lib', '/usr/local/lib']
+ if 'LD_LIBRARY_PATH' in os.environ:
+ paths = os.environ['LD_LIBRARY_PATH'].split(':') + paths
+ for d in paths:
+ f = os.path.join(d, name)
+ if _is_elf(f):
+ return f
+
+ prefix = os.path.join(d, 'lib'+name)
+ for suffix in ['.so', '.so.*', '.*.so.*']:
+ for f in glob('{0}{1}'.format(prefix, suffix)):
+ if _is_elf(f):
+ return f
+
def find_library(name):
- return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
+ return _find_libfile(name) or _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
################################################################
# test code

View File

@ -4,7 +4,7 @@
#
pkgname=python
version=2.7.10
revision=6
revision=7
wrksrc="Python-${version}"
hostmakedepends="pkg-config"
makedepends="