at 18.09-beta 5.7 kB view raw
1From 81bd99ad9058feb1d0361bc8862e8567c21a6142 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 | 52 ++-------------------------------------------------- 8 Lib/uuid.py | 50 ++------------------------------------------------ 9 2 files changed, 4 insertions(+), 98 deletions(-) 10 11diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py 12index 595113bffd..780cd5d21b 100644 13--- a/Lib/ctypes/util.py 14+++ b/Lib/ctypes/util.py 15@@ -88,28 +88,7 @@ elif os.name == "posix": 16 import re, tempfile 17 18 def _findLib_gcc(name): 19- expr = r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name) 20- fdout, ccout = tempfile.mkstemp() 21- os.close(fdout) 22- cmd = 'if type gcc >/dev/null 2>&1; then CC=gcc; elif type cc >/dev/null 2>&1; then CC=cc;else exit 10; fi;' \ 23- 'LANG=C LC_ALL=C $CC -Wl,-t -o ' + ccout + ' 2>&1 -l' + name 24- try: 25- f = os.popen(cmd) 26- try: 27- trace = f.read() 28- finally: 29- rv = f.close() 30- finally: 31- try: 32- os.unlink(ccout) 33- except FileNotFoundError: 34- pass 35- if rv == 10: 36- raise OSError('gcc or cc command not found') 37- res = re.search(expr, trace) 38- if not res: 39- return None 40- return res.group(0) 41+ return None 42 43 44 if sys.platform == "sunos5": 45@@ -200,34 +179,7 @@ elif os.name == "posix": 46 else: 47 48 def _findSoname_ldconfig(name): 49- import struct 50- if struct.calcsize('l') == 4: 51- machine = os.uname().machine + '-32' 52- else: 53- machine = os.uname().machine + '-64' 54- mach_map = { 55- 'x86_64-64': 'libc6,x86-64', 56- 'ppc64-64': 'libc6,64bit', 57- 'sparc64-64': 'libc6,64bit', 58- 's390x-64': 'libc6,64bit', 59- 'ia64-64': 'libc6,IA-64', 60- } 61- abi_type = mach_map.get(machine, 'libc6') 62- 63- # XXX assuming GLIBC's ldconfig (with option -p) 64- regex = os.fsencode( 65- '\s+(lib%s\.[^\s]+)\s+\(%s' % (re.escape(name), abi_type)) 66- try: 67- with subprocess.Popen(['/sbin/ldconfig', '-p'], 68- stdin=subprocess.DEVNULL, 69- stderr=subprocess.DEVNULL, 70- stdout=subprocess.PIPE, 71- env={'LC_ALL': 'C', 'LANG': 'C'}) as p: 72- res = re.search(regex, p.stdout.read()) 73- if res: 74- return os.fsdecode(res.group(1)) 75- except OSError: 76- pass 77+ return None 78 79 def find_library(name): 80 return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name)) 81diff --git a/Lib/uuid.py b/Lib/uuid.py 82index 1061bffc43..846f5819f5 100644 83--- a/Lib/uuid.py 84+++ b/Lib/uuid.py 85@@ -451,57 +451,11 @@ def _netbios_getnode(): 86 return ((bytes[0]<<40) + (bytes[1]<<32) + (bytes[2]<<24) + 87 (bytes[3]<<16) + (bytes[4]<<8) + bytes[5]) 88 89-# Thanks to Thomas Heller for ctypes and for his help with its use here. 90 91-# If ctypes is available, use it to find system routines for UUID generation. 92-# XXX This makes the module non-thread-safe! 93 _uuid_generate_random = _uuid_generate_time = _UuidCreate = None 94-try: 95- import ctypes, ctypes.util 96 97- # The uuid_generate_* routines are provided by libuuid on at least 98- # Linux and FreeBSD, and provided by libc on Mac OS X. 99- for libname in ['uuid', 'c']: 100- try: 101- lib = ctypes.CDLL(ctypes.util.find_library(libname)) 102- except: 103- continue 104- if hasattr(lib, 'uuid_generate_random'): 105- _uuid_generate_random = lib.uuid_generate_random 106- if hasattr(lib, 'uuid_generate_time'): 107- _uuid_generate_time = lib.uuid_generate_time 108- if _uuid_generate_random is not None: 109- break # found everything we were looking for 110- 111- # The uuid_generate_* functions are broken on MacOS X 10.5, as noted 112- # in issue #8621 the function generates the same sequence of values 113- # in the parent process and all children created using fork (unless 114- # those children use exec as well). 115- # 116- # Assume that the uuid_generate functions are broken from 10.5 onward, 117- # the test can be adjusted when a later version is fixed. 118- import sys 119- if sys.platform == 'darwin': 120- import os 121- if int(os.uname().release.split('.')[0]) >= 9: 122- _uuid_generate_random = _uuid_generate_time = None 123- 124- # On Windows prior to 2000, UuidCreate gives a UUID containing the 125- # hardware address. On Windows 2000 and later, UuidCreate makes a 126- # random UUID and UuidCreateSequential gives a UUID containing the 127- # hardware address. These routines are provided by the RPC runtime. 128- # NOTE: at least on Tim's WinXP Pro SP2 desktop box, while the last 129- # 6 bytes returned by UuidCreateSequential are fixed, they don't appear 130- # to bear any relationship to the MAC address of any network device 131- # on the box. 132- try: 133- lib = ctypes.windll.rpcrt4 134- except: 135- lib = None 136- _UuidCreate = getattr(lib, 'UuidCreateSequential', 137- getattr(lib, 'UuidCreate', None)) 138-except: 139- pass 140+_uuid_generate_time = _UuidCreate = None 141+ 142 143 def _unixdll_getnode(): 144 """Get the hardware address on Unix using ctypes.""" 145-- 1462.14.1 147