summaryrefslogtreecommitdiff
path: root/Lib/platform.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-07-09 04:38:27 -0700
committerSerhiy Storchaka <storchaka@gmail.com>2018-07-09 14:38:27 +0300
commitd73497ba52171bc8f786a70ecf50d3104b596221 (patch)
tree67dc261174329e56efc4be80121fc4d9646dd8a6 /Lib/platform.py
parent336c715a82797462fd3beb2a5f309594ce7b7bd0 (diff)
downloadcpython-git-d73497ba52171bc8f786a70ecf50d3104b596221.tar.gz
bpo-26544: Fixed implementation of platform.libc_ver(). (GH-7684). (GH-8193) (GH-8195)
(cherry picked from commit 2a9b8babf0d09946ebebfdb2931cc0d3db5a1d3d) (cherry picked from commit 7c43b801503c802ed6ea4b811f5bc73791249d94)
Diffstat (limited to 'Lib/platform.py')
-rwxr-xr-xLib/platform.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/Lib/platform.py b/Lib/platform.py
index cc2db9870d..c8e0476bfb 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -144,9 +144,7 @@ _libc_search = re.compile(b'(__libc_init)'
b'|'
br'(libc(_\w+)?\.so(?:\.(\d[0-9.]*))?)', re.ASCII)
-def libc_ver(executable=sys.executable, lib='', version='',
-
- chunksize=16384):
+def libc_ver(executable=sys.executable, lib='', version='', chunksize=16384):
""" Tries to determine the libc version that the file executable
(which defaults to the Python interpreter) is linked against.
@@ -161,6 +159,7 @@ def libc_ver(executable=sys.executable, lib='', version='',
The file is read and scanned in chunks of chunksize bytes.
"""
+ from distutils.version import LooseVersion as V
if hasattr(os.path, 'realpath'):
# Python 2.2 introduced os.path.realpath(); it is used
# here to work around problems with Cygwin not being
@@ -169,17 +168,19 @@ def libc_ver(executable=sys.executable, lib='', version='',
with open(executable, 'rb') as f:
binary = f.read(chunksize)
pos = 0
- while 1:
+ while pos < len(binary):
if b'libc' in binary or b'GLIBC' in binary:
m = _libc_search.search(binary, pos)
else:
m = None
- if not m:
- binary = f.read(chunksize)
- if not binary:
+ if not m or m.end() == len(binary):
+ chunk = f.read(chunksize)
+ if chunk:
+ binary = binary[max(pos, len(binary) - 1000):] + chunk
+ pos = 0
+ continue
+ if not m:
break
- pos = 0
- continue
libcinit, glibc, glibcversion, so, threads, soversion = [
s.decode('latin1') if s is not None else s
for s in m.groups()]
@@ -189,12 +190,12 @@ def libc_ver(executable=sys.executable, lib='', version='',
if lib != 'glibc':
lib = 'glibc'
version = glibcversion
- elif glibcversion > version:
+ elif V(glibcversion) > V(version):
version = glibcversion
elif so:
if lib != 'glibc':
lib = 'libc'
- if soversion and soversion > version:
+ if soversion and (not version or V(soversion) > V(version)):
version = soversion
if threads and version[-len(threads):] != threads:
version = version + threads
@@ -389,6 +390,7 @@ def popen(cmd, mode='r', bufsize=-1):
warnings.warn('use os.popen instead', DeprecationWarning, stacklevel=2)
return os.popen(cmd, mode, bufsize)
+
def _norm_version(version, build=''):
""" Normalize the version and build strings and return a single