]> granicus.if.org Git - python/commitdiff
bpo-32493: Fix uuid.uuid1() on FreeBSD. (GH-7099)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 24 May 2018 23:22:59 +0000 (16:22 -0700)
committerGitHub <noreply@github.com>
Thu, 24 May 2018 23:22:59 +0000 (16:22 -0700)
Use uuid_enc_be() if available to encode UUID to bytes as big endian.
(cherry picked from commit 17d8830312d82e7de42ab89739b0771f712645ff)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Misc/NEWS.d/next/Library/2018-05-24-17-41-36.bpo-32493.5tAoAu.rst [new file with mode: 0644]
Modules/_uuidmodule.c
configure
configure.ac
pyconfig.h.in

diff --git a/Misc/NEWS.d/next/Library/2018-05-24-17-41-36.bpo-32493.5tAoAu.rst b/Misc/NEWS.d/next/Library/2018-05-24-17-41-36.bpo-32493.5tAoAu.rst
new file mode 100644 (file)
index 0000000..32f88dd
--- /dev/null
@@ -0,0 +1 @@
+Fixed :func:`uuid.uuid1` on FreeBSD.
index 16aa09b04ff2090453df0b13ceab3c7c4666b7ce..89499143a61b2b9b61374b2ee9ad7d4d8f086e47 100644 (file)
@@ -18,10 +18,16 @@ py_uuid_generate_time_safe(void)
 
     res = uuid_generate_time_safe(uuid);
     return Py_BuildValue("y#i", (const char *) uuid, sizeof(uuid), res);
-#elif HAVE_UUID_CREATE
+#elif defined(HAVE_UUID_CREATE)
     uint32_t status;
     uuid_create(&uuid, &status);
+# if defined(HAVE_UUID_ENC_BE)
+    unsigned char buf[sizeof(uuid)];
+    uuid_enc_be(buf, &uuid);
+    return Py_BuildValue("y#i", buf, sizeof(uuid), (int) status);
+# else
     return Py_BuildValue("y#i", (const char *) &uuid, sizeof(uuid), (int) status);
+# endif
 #else
     uuid_generate_time(uuid);
     return Py_BuildValue("y#O", (const char *) uuid, sizeof(uuid), Py_None);
@@ -57,6 +63,7 @@ PyInit__uuid(void)
     }
     if (PyModule_AddIntConstant(mod, "has_uuid_generate_time_safe",
                                 has_uuid_generate_time_safe) < 0) {
+        Py_DECREF(mod);
         return NULL;
     }
 
index f1f01df4a80e4262d0c849aa467dfb7afec7df66..b1cd944ac562ea363eb8af040d280e1ec59c03c0 100755 (executable)
--- a/configure
+++ b/configure
@@ -9625,6 +9625,40 @@ $as_echo "no" >&6; }
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
+# Little-endian FreeBSD, OpenBSD and NetBSD needs encoding into an octet
+# stream in big-endian byte-order
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for uuid_enc_be" >&5
+$as_echo_n "checking for uuid_enc_be... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <uuid.h>
+int
+main ()
+{
+
+#ifndef uuid_enc_be
+uuid_t uuid;
+unsigned char buf[sizeof(uuid)];
+uuid_enc_be(buf, &uuid);
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+$as_echo "#define HAVE_UUID_ENC_BE 1" >>confdefs.h
+
+   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
 # 'Real Time' functions on Solaris
 # posix4 on Solaris 2.6
 # pthread (first!) on Linux
index 2535969642042f38ad4a4a7ef485f9aef94f7b5a..59489047fc24eb1b0fe2dc2d642bd097226235c5 100644 (file)
@@ -2742,6 +2742,21 @@ void *x = uuid_create
   [AC_MSG_RESULT(no)]
 )
 
+# Little-endian FreeBSD, OpenBSD and NetBSD needs encoding into an octet
+# stream in big-endian byte-order
+AC_MSG_CHECKING(for uuid_enc_be)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <uuid.h>]], [[
+#ifndef uuid_enc_be
+uuid_t uuid;
+unsigned char buf[sizeof(uuid)];
+uuid_enc_be(buf, &uuid);
+#endif
+]])],
+  [AC_DEFINE(HAVE_UUID_ENC_BE, 1, Define if uuid_enc_be() exists.)
+   AC_MSG_RESULT(yes)],
+  [AC_MSG_RESULT(no)]
+)
+
 # 'Real Time' functions on Solaris
 # posix4 on Solaris 2.6
 # pthread (first!) on Linux
index a0efff9777d27d53086971543e81abf4604a1bf6..e561a7c07cca7896f35faaa1f2dc9d07823ca42a 100644 (file)
 /* Define if uuid_create() exists. */
 #undef HAVE_UUID_CREATE
 
+/* Define if uuid_enc_be() exists. */
+#undef HAVE_UUID_ENC_BE
+
 /* Define if uuid_generate_time_safe() exists. */
 #undef HAVE_UUID_GENERATE_TIME_SAFE