diff -r 87dfadd61e0d Doc/library/ctypes.rst --- a/Doc/library/ctypes.rst Thu Feb 04 01:24:56 2016 -0500 +++ b/Doc/library/ctypes.rst Sat Feb 06 13:01:01 2016 +0100 @@ -1252,15 +1252,15 @@ On Linux, :func:`find_library` tries to run external programs (``/sbin/ldconfig``, ``gcc``, and ``objdump``) to find the library file. It -returns the filename of the library file. Here are some examples:: +returns the absolute path of the library file. Here are some examples:: >>> from ctypes.util import find_library >>> find_library("m") - 'libm.so.6' + '/lib/i386-linux-gnu/libm.so.6' >>> find_library("c") - 'libc.so.6' + '/lib/i386-linux-gnu/libc.so.6' >>> find_library("bz2") - 'libbz2.so.1.0' + '/lib/x86_64-linux-gnu/libbz2.so.1.0' >>> On OS X, :func:`find_library` tries several predefined naming schemes and paths @@ -1829,6 +1829,9 @@ The exact functionality is system dependent. + .. versionchanged:: 3.5 + On Linux it returns an absolute path. + .. function:: find_msvcrt() :module: ctypes.util diff -r 87dfadd61e0d Lib/ctypes/util.py --- a/Lib/ctypes/util.py Thu Feb 04 01:24:56 2016 -0500 +++ b/Lib/ctypes/util.py Sat Feb 06 13:01:01 2016 +0100 @@ -222,7 +222,7 @@ # XXX assuming GLIBC's ldconfig (with option -p) regex = os.fsencode( - '\s+(lib%s\.[^\s]+)\s+\(%s' % (re.escape(name), abi_type)) + '([^\s]+lib%s\.[^\s]+)\\n\\t[^\s]+\s\(%s' % (re.escape(name), abi_type)) try: with subprocess.Popen(['/sbin/ldconfig', '-p'], stdin=subprocess.DEVNULL, @@ -243,6 +243,7 @@ def test(): from ctypes import cdll + from os.path import isabs if os.name == "nt": print(cdll.msvcrt) print(cdll.load("msvcrt")) @@ -250,9 +251,9 @@ if os.name == "posix": # find and load_version - print(find_library("m")) - print(find_library("c")) - print(find_library("bz2")) + print(find_library("m"), os.path.isabs(find_library("m"))) + print(find_library("c"), os.path.isabs(find_library("c"))) + print(find_library("bz2"), os.path.isabs(find_library("bz2"))) # getattr ## print cdll.m