]> granicus.if.org Git - python/commitdiff
Issue #11258: Speed up ctypes.util.find_library() under Linux a lot. Patch
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 26 Feb 2011 08:45:20 +0000 (08:45 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 26 Feb 2011 08:45:20 +0000 (08:45 +0000)
by Jonas H.

Lib/ctypes/test/test_loading.py
Lib/ctypes/util.py
Misc/ACKS
Misc/NEWS

index 4029b463bcd7bcf56465529d1b3faf3260040fab..c6815faaf698eaad229dc3cc1905ab37f31eae08 100644 (file)
@@ -102,5 +102,12 @@ class LoaderTest(unittest.TestCase):
             # This is the real test: call the function via 'call_function'
             self.assertEqual(0, call_function(proc, (None,)))
 
+    if os.name != "nt":
+        def test_libc_exists(self):
+            # A basic test that the libc is found by find_library()
+            # XXX Can this fail on some non-Windows systems?
+            self.assertTrue(libc_name)
+            self.assertTrue(os.path.exists(libc_name))
+
 if __name__ == "__main__":
     unittest.main()
index 1881e89688800a14a6d94c413711694ba7bb31cd..3e8379f2f347fd4656f3c84d7cf9dff0fcec098d 100644 (file)
@@ -203,14 +203,18 @@ elif os.name == "posix":
             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))
+            name = 'lib%s' % name
+            pat = re.compile('\s*(/[^\(\)\s]*%s\.[^\(\)\s]*)' % re.escape(name))
             with contextlib.closing(os.popen('LC_ALL=C LANG=C /sbin/ldconfig -p 2>/dev/null')) as f:
-                data = f.read()
-            res = re.search(expr, data)
-            if not res:
-                return None
-            return res.group(1)
+                for line in f:
+                    if not '=>' in line:
+                        continue
+                    path = line.rsplit('=>', 1)[1]
+                    if not name+'.' in path:
+                        continue
+                    res = pat.search(path)
+                    if res:
+                        return res.group(1)
 
         def find_library(name):
             return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
index 8066ebcc16bd8bbcf52539660140f9a078c5a0fa..20e9b0bd68b923dfeca2fe50e6581398e1f63e7d 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -329,6 +329,7 @@ Dag Gruneau
 Michael Guravage
 Lars Gustäbel
 Thomas Güttler
+Jonas H.
 Barry Haddow
 Paul ten Hagen
 Rasmus Hahn
index 30fa398ab9e405d1704942826f4e4dac3b326fbf..3d0abee2dde48c6c59e05c0f70c110aca7521568 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -35,6 +35,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #11258: Speed up ctypes.util.find_library() under Linux a lot.  Patch
+  by Jonas H.
+
 - Issue #11297: Add collections.ChainMap().
 
 - Issue #10755: Add the posix.fdlistdir() function.  Patch by Ross Lagerwall.