summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorIgor Galić <igalic@brainsware.at>2017-09-20 21:13:40 (GMT)
committerIgor Galić <igalic@brainsware.at>2017-09-22 07:53:24 (GMT)
commit74fdc42048b95698eeac36b2fdb35b3ff5d6a620 (patch)
treeb276560ed28c5a6bcd15329f9d70d780c5352cff /Lib
parent5e02c7826f9797fb3add79b608ef51f7a62b3e5a (diff)
downloadcpython-74fdc42048b95698eeac36b2fdb35b3ff5d6a620.zip
cpython-74fdc42048b95698eeac36b2fdb35b3ff5d6a620.tar.gz
cpython-74fdc42048b95698eeac36b2fdb35b3ff5d6a620.tar.bz2
optimize paths for finding uuid_generate_time
optimizes uuid ctypes initialization for BSD and Darwin
Diffstat (limited to 'Lib')
-rw-r--r--Lib/uuid.py34
1 files changed, 19 insertions, 15 deletions
diff --git a/Lib/uuid.py b/Lib/uuid.py
index 15a81f5..3dda13e 100644
--- a/Lib/uuid.py
+++ b/Lib/uuid.py
@@ -481,14 +481,29 @@ def _netbios_getnode():
# XXX This makes the module non-thread-safe!
_uuid_generate_time = _UuidCreate = None
try:
- import ctypes, ctypes.util
import sys
+ # The uuid_generate_* functions are broken on MacOS X 10.5, as noted
+ # in issue #8621 the function generates the same sequence of values
+ # in the parent process and all children created using fork (unless
+ # those children use exec as well).
+ #
+ # Assume that the uuid_generate functions are broken from 10.5 onward,
+ # the test can be adjusted when a later version is fixed.
+ if sys.platform == 'darwin':
+ if int(os.uname().release.split('.')[0]) >= 9:
+ _uuid_generate_time = None
+ raise NotImplementedError("Not supported on OSX >= 10.5")
- # The uuid_generate_* routines are provided by libuuid on at least
- # Linux and FreeBSD, and provided by libc on Mac OS X.
+ import ctypes
+ import ctypes.util
+ # The uuid_generate_* routines are provided by libuuid - at least
+ # on Linux. On FreeBSD and OS X they are provided by libc
_libnames = ['uuid']
if not sys.platform.startswith('win'):
- _libnames.append('c')
+ if 'bsd' in sys.platform:
+ _libnames.insert(0, 'c')
+ else:
+ _libnames.append('c')
for libname in _libnames:
try:
lib = ctypes.CDLL(ctypes.util.find_library(libname))
@@ -506,17 +521,6 @@ try:
break
del _libnames
- # The uuid_generate_* functions are broken on MacOS X 10.5, as noted
- # in issue #8621 the function generates the same sequence of values
- # in the parent process and all children created using fork (unless
- # those children use exec as well).
- #
- # Assume that the uuid_generate functions are broken from 10.5 onward,
- # the test can be adjusted when a later version is fixed.
- if sys.platform == 'darwin':
- if int(os.uname().release.split('.')[0]) >= 9:
- _uuid_generate_time = None
-
# On Windows prior to 2000, UuidCreate gives a UUID containing the
# hardware address. On Windows 2000 and later, UuidCreate makes a
# random UUID and UuidCreateSequential gives a UUID containing the