at 18.09-beta 6.2 kB view raw
1From 105621b99cc30615c79b5aa3d12d6732e14b0d59 Mon Sep 17 00:00:00 2001 2From: Frederik Rietdijk <fridh@fridh.nl> 3Date: Mon, 28 Aug 2017 09:24:06 +0200 4Subject: [PATCH] Don't use ldconfig and speed up uuid load 5 6--- 7 Lib/ctypes/util.py | 70 ++---------------------------------------------------- 8 Lib/uuid.py | 48 ------------------------------------- 9 2 files changed, 2 insertions(+), 116 deletions(-) 10 11diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py 12index 339ae8aa8a..2944985c30 100644 13--- a/Lib/ctypes/util.py 14+++ b/Lib/ctypes/util.py 15@@ -85,46 +85,7 @@ elif os.name == "posix": 16 import re, tempfile 17 18 def _findLib_gcc(name): 19- # Run GCC's linker with the -t (aka --trace) option and examine the 20- # library name it prints out. The GCC command will fail because we 21- # haven't supplied a proper program with main(), but that does not 22- # matter. 23- expr = os.fsencode(r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)) 24- 25- c_compiler = shutil.which('gcc') 26- if not c_compiler: 27- c_compiler = shutil.which('cc') 28- if not c_compiler: 29- # No C compiler available, give up 30- return None 31- 32- temp = tempfile.NamedTemporaryFile() 33- try: 34- args = [c_compiler, '-Wl,-t', '-o', temp.name, '-l' + name] 35- 36- env = dict(os.environ) 37- env['LC_ALL'] = 'C' 38- env['LANG'] = 'C' 39- try: 40- proc = subprocess.Popen(args, 41- stdout=subprocess.PIPE, 42- stderr=subprocess.STDOUT, 43- env=env) 44- except OSError: # E.g. bad executable 45- return None 46- with proc: 47- trace = proc.stdout.read() 48- finally: 49- try: 50- temp.close() 51- except FileNotFoundError: 52- # Raised if the file was already removed, which is the normal 53- # behaviour of GCC if linking fails 54- pass 55- res = re.search(expr, trace) 56- if not res: 57- return None 58- return os.fsdecode(res.group(0)) 59+ return None 60 61 62 if sys.platform == "sunos5": 63@@ -246,34 +207,7 @@ elif os.name == "posix": 64 else: 65 66 def _findSoname_ldconfig(name): 67- import struct 68- if struct.calcsize('l') == 4: 69- machine = os.uname().machine + '-32' 70- else: 71- machine = os.uname().machine + '-64' 72- mach_map = { 73- 'x86_64-64': 'libc6,x86-64', 74- 'ppc64-64': 'libc6,64bit', 75- 'sparc64-64': 'libc6,64bit', 76- 's390x-64': 'libc6,64bit', 77- 'ia64-64': 'libc6,IA-64', 78- } 79- abi_type = mach_map.get(machine, 'libc6') 80- 81- # XXX assuming GLIBC's ldconfig (with option -p) 82- regex = r'\s+(lib%s\.[^\s]+)\s+\(%s' 83- regex = os.fsencode(regex % (re.escape(name), abi_type)) 84- try: 85- with subprocess.Popen(['/sbin/ldconfig', '-p'], 86- stdin=subprocess.DEVNULL, 87- stderr=subprocess.DEVNULL, 88- stdout=subprocess.PIPE, 89- env={'LC_ALL': 'C', 'LANG': 'C'}) as p: 90- res = re.search(regex, p.stdout.read()) 91- if res: 92- return os.fsdecode(res.group(1)) 93- except OSError: 94- pass 95+ return None 96 97 def _findLib_ld(name): 98 # See issue #9998 for why this is needed 99diff --git a/Lib/uuid.py b/Lib/uuid.py 100index 200c800b34..31160ace95 100644 101--- a/Lib/uuid.py 102+++ b/Lib/uuid.py 103@@ -455,57 +455,9 @@ def _netbios_getnode(): 104 continue 105 return int.from_bytes(bytes, 'big') 106 107-# Thanks to Thomas Heller for ctypes and for his help with its use here. 108 109-# If ctypes is available, use it to find system routines for UUID generation. 110-# XXX This makes the module non-thread-safe! 111 _uuid_generate_time = _UuidCreate = None 112-try: 113- import ctypes, ctypes.util 114- import sys 115 116- # The uuid_generate_* routines are provided by libuuid on at least 117- # Linux and FreeBSD, and provided by libc on Mac OS X. 118- _libnames = ['uuid'] 119- if not sys.platform.startswith('win'): 120- _libnames.append('c') 121- for libname in _libnames: 122- try: 123- lib = ctypes.CDLL(ctypes.util.find_library(libname)) 124- except Exception: 125- continue 126- if hasattr(lib, 'uuid_generate_time'): 127- _uuid_generate_time = lib.uuid_generate_time 128- break 129- del _libnames 130- 131- # The uuid_generate_* functions are broken on MacOS X 10.5, as noted 132- # in issue #8621 the function generates the same sequence of values 133- # in the parent process and all children created using fork (unless 134- # those children use exec as well). 135- # 136- # Assume that the uuid_generate functions are broken from 10.5 onward, 137- # the test can be adjusted when a later version is fixed. 138- if sys.platform == 'darwin': 139- if int(os.uname().release.split('.')[0]) >= 9: 140- _uuid_generate_time = None 141- 142- # On Windows prior to 2000, UuidCreate gives a UUID containing the 143- # hardware address. On Windows 2000 and later, UuidCreate makes a 144- # random UUID and UuidCreateSequential gives a UUID containing the 145- # hardware address. These routines are provided by the RPC runtime. 146- # NOTE: at least on Tim's WinXP Pro SP2 desktop box, while the last 147- # 6 bytes returned by UuidCreateSequential are fixed, they don't appear 148- # to bear any relationship to the MAC address of any network device 149- # on the box. 150- try: 151- lib = ctypes.windll.rpcrt4 152- except: 153- lib = None 154- _UuidCreate = getattr(lib, 'UuidCreateSequential', 155- getattr(lib, 'UuidCreate', None)) 156-except: 157- pass 158 159 def _unixdll_getnode(): 160 """Get the hardware address on Unix using ctypes.""" 161-- 1622.14.1 163