[Python-checkins] cpython (3.2): Issue #13979: Fix ctypes.util.find_library ldconfig regex

meador.inge python-checkins at python.org
Tue Feb 14 05:25:47 CET 2012


http://hg.python.org/cpython/rev/ac362fb3b86b
changeset:   74930:ac362fb3b86b
branch:      3.2
parent:      74924:d8904aff9442
user:        Meador Inge <meadori at gmail.com>
date:        Mon Feb 13 22:08:39 2012 -0600
summary:
  Issue #13979: Fix ctypes.util.find_library ldconfig regex

files:
  Lib/ctypes/util.py |  19 +------------------
  Misc/NEWS          |   3 +++
  2 files changed, 4 insertions(+), 18 deletions(-)


diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -171,22 +171,6 @@
 
     else:
 
-        def _findLib_ldconfig(name):
-            # XXX assuming GLIBC's ldconfig (with option -p)
-            expr = r'/[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
-            with contextlib.closing(os.popen('/sbin/ldconfig -p 2>/dev/null')) as f:
-                data = f.read()
-            res = re.search(expr, data)
-            if not res:
-                # Hm, this works only for libs needed by the python executable.
-                cmd = 'ldd %s 2>/dev/null' % sys.executable
-                with contextlib.closing(os.popen(cmd)) as f:
-                    data = f.read()
-                res = re.search(expr, data)
-                if not res:
-                    return None
-            return res.group(0)
-
         def _findSoname_ldconfig(name):
             import struct
             if struct.calcsize('l') == 4:
@@ -203,8 +187,7 @@
             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))
+            expr = r'\s+(lib%s\.[^\s]+)\s+\(%s' % (re.escape(name), abi_type)
             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)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -113,6 +113,9 @@
 Library
 -------
 
+- Issue #13979: A bug in ctypes.util.find_library that caused
+  the wrong library name to be returned has been fixed.
+
 - Issue #13993: HTMLParser is now able to handle broken end tags when
   strict=False.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list