aboutsummaryrefslogtreecommitdiffstats
path: root/main/python/musl-find_library.patch
diff options
context:
space:
mode:
Diffstat (limited to 'main/python/musl-find_library.patch')
-rw-r--r--main/python/musl-find_library.patch43
1 files changed, 43 insertions, 0 deletions
diff --git a/main/python/musl-find_library.patch b/main/python/musl-find_library.patch
new file mode 100644
index 0000000000..aad604c451
--- /dev/null
+++ b/main/python/musl-find_library.patch
@@ -0,0 +1,43 @@
+diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
+index 1e882e3..b265cc0 100644
+--- a/Lib/ctypes/util.py
++++ b/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