From 74fdc42048b95698eeac36b2fdb35b3ff5d6a620 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Igor=20Gali=C4=87?= <igalic@brainsware.at>
Date: Wed, 20 Sep 2017 23:13:40 +0200
Subject: optimize paths for finding uuid_generate_time

optimizes uuid ctypes initialization for BSD and Darwin
---
 Lib/uuid.py | 34 +++++++++++++++++++---------------
 1 file 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
-- 
cgit v0.12

