diff options
author | Martin Panter <vadmium+py@gmail.com> | 2016-03-10 01:06:23 (GMT) |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2016-03-10 01:06:23 (GMT) |
commit | b9f3114d42601b07c9830af8b18330bff475bcfc (patch) | |
tree | 3ffa3720744c56da04b404561aaf30d34597a579 /Lib/ctypes | |
parent | aadaa3614e9aab723b3563801dfc700c0dae46e3 (diff) | |
download | cpython-b9f3114d42601b07c9830af8b18330bff475bcfc.zip cpython-b9f3114d42601b07c9830af8b18330bff475bcfc.tar.gz cpython-b9f3114d42601b07c9830af8b18330bff475bcfc.tar.bz2 |
Issue #21042: Return full path in ctypes.util.find_library() on Linux
Patch by Tamás Bence Gedai.
Diffstat (limited to 'Lib/ctypes')
-rw-r--r-- | Lib/ctypes/test/test_find.py | 40 | ||||
-rw-r--r-- | Lib/ctypes/util.py | 4 |
2 files changed, 26 insertions, 18 deletions
diff --git a/Lib/ctypes/test/test_find.py b/Lib/ctypes/test/test_find.py index e6bc19d..1845bb0 100644 --- a/Lib/ctypes/test/test_find.py +++ b/Lib/ctypes/test/test_find.py @@ -9,39 +9,39 @@ from ctypes.util import find_library class Test_OpenGL_libs(unittest.TestCase): @classmethod def setUpClass(cls): - lib_gl = lib_glu = lib_gle = None + cls.lib_gl = cls.lib_glu = cls.lib_gle = None if sys.platform == "win32": - lib_gl = find_library("OpenGL32") - lib_glu = find_library("Glu32") + cls.lib_gl = find_library("OpenGL32") + cls.lib_glu = find_library("Glu32") elif sys.platform == "darwin": - lib_gl = lib_glu = find_library("OpenGL") + cls.lib_gl = cls.lib_glu = find_library("OpenGL") else: - lib_gl = find_library("GL") - lib_glu = find_library("GLU") - lib_gle = find_library("gle") + cls.lib_gl = find_library("GL") + cls.lib_glu = find_library("GLU") + cls.lib_gle = find_library("gle") ## print, for debugging if test.support.verbose: print("OpenGL libraries:") - for item in (("GL", lib_gl), - ("GLU", lib_glu), - ("gle", lib_gle)): + for item in (("GL", cls.lib_gl), + ("GLU", cls.lib_glu), + ("gle", cls.lib_gle)): print("\t", item) cls.gl = cls.glu = cls.gle = None - if lib_gl: + if cls.lib_gl: try: - cls.gl = CDLL(lib_gl, mode=RTLD_GLOBAL) + cls.gl = CDLL(cls.lib_gl, mode=RTLD_GLOBAL) except OSError: pass - if lib_glu: + if cls.lib_glu: try: - cls.glu = CDLL(lib_glu, RTLD_GLOBAL) + cls.glu = CDLL(cls.lib_glu, RTLD_GLOBAL) except OSError: pass - if lib_gle: + if cls.lib_gle: try: - cls.gle = CDLL(lib_gle) + cls.gle = CDLL(cls.lib_gle) except OSError: pass @@ -64,6 +64,14 @@ class Test_OpenGL_libs(unittest.TestCase): self.skipTest('lib_gle not available') self.gle.gleGetJoinStyle + def test_abspath(self): + if self.lib_gl: + self.assertTrue(os.path.isabs(self.lib_gl)) + if self.lib_glu: + self.assertTrue(os.path.isabs(self.lib_glu)) + if self.lib_gle: + self.assertTrue(os.path.isabs(self.lib_gle)) + # On platforms where the default shared library suffix is '.so', # at least some libraries can be loaded as attributes of the cdll # object, since ctypes now tries loading the lib again diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py index 9e74ccd..d8e3bfa 100644 --- a/Lib/ctypes/util.py +++ b/Lib/ctypes/util.py @@ -221,8 +221,8 @@ elif os.name == "posix": abi_type = mach_map.get(machine, 'libc6') # XXX assuming GLIBC's ldconfig (with option -p) - regex = os.fsencode( - '\s+(lib%s\.[^\s]+)\s+\(%s' % (re.escape(name), abi_type)) + regex = r'lib%s\.[^\s]+\s\(%s(?:,\s.*)?\)\s=>\s(.*)' + regex = os.fsencode(regex % (re.escape(name), abi_type)) try: with subprocess.Popen(['/sbin/ldconfig', '-p'], stdin=subprocess.DEVNULL, |