aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-10-02 07:57:59 -0700
committerGitHub <noreply@github.com>2017-10-02 07:57:59 -0700
commit4337a0d9955f0855ba38ef30feec3858d304abf0 (patch)
treea45f7d035c6e28bb95e4a54fb1d433c83353963b /Modules/_uuidmodule.c
parentbpo-31516: current_thread() should not return a dummy thread at shutdown (#3673) (diff)
downloadcpython-4337a0d9955f0855ba38ef30feec3858d304abf0.tar.gz
cpython-4337a0d9955f0855ba38ef30feec3858d304abf0.tar.bz2
cpython-4337a0d9955f0855ba38ef30feec3858d304abf0.zip
bpo-11063: Fix _uuid module on macOS (#3855)
On macOS, use uuid_generate_time() instead of uuid_generate_time_safe() of libuuid, since uuid_generate_time_safe() is not available.
Diffstat (limited to 'Modules/_uuidmodule.c')
-rw-r--r--Modules/_uuidmodule.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/Modules/_uuidmodule.c b/Modules/_uuidmodule.c
index e263b40d8ff..88c40ce3537 100644
--- a/Modules/_uuidmodule.c
+++ b/Modules/_uuidmodule.c
@@ -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;
}