]> granicus.if.org Git - python/commitdiff
bpo-11063: Fix _uuid module on macOS (#3855)
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 2 Oct 2017 14:57:59 +0000 (07:57 -0700)
committerGitHub <noreply@github.com>
Mon, 2 Oct 2017 14:57:59 +0000 (07:57 -0700)
On macOS, use uuid_generate_time() instead of
uuid_generate_time_safe() of libuuid, since uuid_generate_time_safe()
is not available.

Lib/uuid.py
Modules/_uuidmodule.c

index b2fbd38c353efc5a6c24e26f0faa62318b67cd70..3123ff88a16b0be306162e4b475170e9b7ef0bd2 100644 (file)
@@ -509,7 +509,7 @@ def _load_system_functions():
         pass
     elif _uuid is not None:
         _generate_time_safe = _uuid.generate_time_safe
-        _has_uuid_generate_time_safe = True
+        _has_uuid_generate_time_safe = _uuid.has_uuid_generate_time_safe
         return
 
     try:
index e263b40d8ff3e2ad0e81d05c74b4450b5d214a47..88c40ce353786e40c464de373675297fdd9f5af1 100644 (file)
@@ -4,14 +4,27 @@
 #include <uuid/uuid.h>
 
 
+/* bpo-11063: libuuid on macOS doesn't provide uuid_generate_time_safe(),
+   only uuid_generate_time(). */
+#ifndef __APPLE__
+#  define HAVE_TIME_SAFE
+#endif
+
+
 static PyObject *
 py_uuid_generate_time_safe(void)
 {
+#ifdef HAVE_TIME_SAFE
     uuid_t out;
     int res;
 
     res = uuid_generate_time_safe(out);
     return Py_BuildValue("y#i", (const char *) out, sizeof(out), res);
+#else
+    uuid_t out;
+    uuid_generate_time(out);
+    return Py_BuildValue("y#O", (const char *) out, sizeof(out), Py_None);
+#endif
 }
 
 
@@ -30,6 +43,21 @@ static struct PyModuleDef uuidmodule = {
 PyMODINIT_FUNC
 PyInit__uuid(void)
 {
+    PyObject *mod;
     assert(sizeof(uuid_t) == 16);
-    return PyModule_Create(&uuidmodule);
+#ifdef HAVE_TIME_SAFE
+    int has_uuid_generate_time_safe = 1;
+#else
+    int has_uuid_generate_time_safe = 0;
+#endif
+    mod = PyModule_Create(&uuidmodule);
+    if (mod == NULL) {
+        return NULL;
+    }
+    if (PyModule_AddIntConstant(mod, "has_uuid_generate_time_safe",
+                                has_uuid_generate_time_safe) < 0) {
+        return NULL;
+    }
+
+    return mod;
 }