140140 b'|'
141141 br'(libc(_\w+)?\.so(?:\.(\d[0-9.]*))?)' , re .ASCII )
142142
143- def libc_ver (executable = sys .executable , lib = '' , version = '' ,
144-
145- chunksize = 16384 ):
143+ def libc_ver (executable = sys .executable , lib = '' , version = '' , chunksize = 16384 ):
146144
147145 """ Tries to determine the libc version that the file executable
148146 (which defaults to the Python interpreter) is linked against.
@@ -157,6 +155,7 @@ def libc_ver(executable=sys.executable, lib='', version='',
157155 The file is read and scanned in chunks of chunksize bytes.
158156
159157 """
158+ from distutils .version import LooseVersion as V
160159 if hasattr (os .path , 'realpath' ):
161160 # Python 2.2 introduced os.path.realpath(); it is used
162161 # here to work around problems with Cygwin not being
@@ -165,17 +164,19 @@ def libc_ver(executable=sys.executable, lib='', version='',
165164 with open (executable , 'rb' ) as f :
166165 binary = f .read (chunksize )
167166 pos = 0
168- while 1 :
167+ while pos < len ( binary ) :
169168 if b'libc' in binary or b'GLIBC' in binary :
170169 m = _libc_search .search (binary , pos )
171170 else :
172171 m = None
173- if not m :
174- binary = f .read (chunksize )
175- if not binary :
172+ if not m or m .end () == len (binary ):
173+ chunk = f .read (chunksize )
174+ if chunk :
175+ binary = binary [max (pos , len (binary ) - 1000 ):] + chunk
176+ pos = 0
177+ continue
178+ if not m :
176179 break
177- pos = 0
178- continue
179180 libcinit , glibc , glibcversion , so , threads , soversion = [
180181 s .decode ('latin1' ) if s is not None else s
181182 for s in m .groups ()]
@@ -185,12 +186,12 @@ def libc_ver(executable=sys.executable, lib='', version='',
185186 if lib != 'glibc' :
186187 lib = 'glibc'
187188 version = glibcversion
188- elif glibcversion > version :
189+ elif V ( glibcversion ) > V ( version ) :
189190 version = glibcversion
190191 elif so :
191192 if lib != 'glibc' :
192193 lib = 'libc'
193- if soversion and soversion > version :
194+ if soversion and ( not version or V ( soversion ) > V ( version )) :
194195 version = soversion
195196 if threads and version [- len (threads ):] != threads :
196197 version = version + threads
@@ -253,6 +254,7 @@ def popen(cmd, mode='r', bufsize=-1):
253254 warnings .warn ('use os.popen instead' , DeprecationWarning , stacklevel = 2 )
254255 return os .popen (cmd , mode , bufsize )
255256
257+
256258def _norm_version (version , build = '' ):
257259
258260 """ Normalize the version and build strings and return a single
0 commit comments