Skip to content

Commit fd869ce

Browse files
bpo-32493: Fix uuid.uuid1() on FreeBSD.
1 parent 301e3cc commit fd869ce

File tree

5 files changed

+61
-1
lines changed

5 files changed

+61
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed :func:`uuid.uuid1` on FreeBSD.

Modules/_uuidmodule.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ py_uuid_generate_time_safe(PyObject *Py_UNUSED(context),
1919

2020
res = uuid_generate_time_safe(uuid);
2121
return Py_BuildValue("y#i", (const char *) uuid, sizeof(uuid), res);
22-
#elif HAVE_UUID_CREATE
22+
#elif defined(HAVE_UUID_CREATE)
2323
uint32_t status;
2424
uuid_create(&uuid, &status);
25+
# if defined(HAVE_UUID_ENC_BE)
26+
unsigned char buf[sizeof(uuid)];
27+
uuid_enc_be(buf, &uuid);
28+
return Py_BuildValue("y#i", buf, sizeof(uuid), (int) status);
29+
# else
2530
return Py_BuildValue("y#i", (const char *) &uuid, sizeof(uuid), (int) status);
31+
# endif
2632
#else
2733
uuid_generate_time(uuid);
2834
return Py_BuildValue("y#O", (const char *) uuid, sizeof(uuid), Py_None);
@@ -58,6 +64,7 @@ PyInit__uuid(void)
5864
}
5965
if (PyModule_AddIntConstant(mod, "has_uuid_generate_time_safe",
6066
has_uuid_generate_time_safe) < 0) {
67+
Py_DECREF(mod);
6168
return NULL;
6269
}
6370

configure

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9584,6 +9584,40 @@ $as_echo "no" >&6; }
95849584
fi
95859585
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
95869586

9587+
# Little-endian FreeBSD, OpenBSD and NetBSD needs encoding into an octet
9588+
# stream in big-endian byte-order
9589+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for uuid_enc_be" >&5
9590+
$as_echo_n "checking for uuid_enc_be... " >&6; }
9591+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
9592+
/* end confdefs.h. */
9593+
#include <uuid.h>
9594+
int
9595+
main ()
9596+
{
9597+
9598+
#ifndef uuid_enc_be
9599+
uuid_t uuid;
9600+
unsigned char buf[sizeof(uuid)];
9601+
uuid_enc_be(buf, &uuid);
9602+
#endif
9603+
9604+
;
9605+
return 0;
9606+
}
9607+
_ACEOF
9608+
if ac_fn_c_try_compile "$LINENO"; then :
9609+
9610+
$as_echo "#define HAVE_UUID_ENC_BE 1" >>confdefs.h
9611+
9612+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
9613+
$as_echo "yes" >&6; }
9614+
else
9615+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
9616+
$as_echo "no" >&6; }
9617+
9618+
fi
9619+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
9620+
95879621
# 'Real Time' functions on Solaris
95889622
# posix4 on Solaris 2.6
95899623
# pthread (first!) on Linux

configure.ac

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,6 +2696,21 @@ void *x = uuid_create
26962696
[AC_MSG_RESULT(no)]
26972697
)
26982698

2699+
# Little-endian FreeBSD, OpenBSD and NetBSD needs encoding into an octet
2700+
# stream in big-endian byte-order
2701+
AC_MSG_CHECKING(for uuid_enc_be)
2702+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <uuid.h>]], [[
2703+
#ifndef uuid_enc_be
2704+
uuid_t uuid;
2705+
unsigned char buf[sizeof(uuid)];
2706+
uuid_enc_be(buf, &uuid);
2707+
#endif
2708+
]])],
2709+
[AC_DEFINE(HAVE_UUID_ENC_BE, 1, Define if uuid_enc_be() exists.)
2710+
AC_MSG_RESULT(yes)],
2711+
[AC_MSG_RESULT(no)]
2712+
)
2713+
26992714
# 'Real Time' functions on Solaris
27002715
# posix4 on Solaris 2.6
27012716
# pthread (first!) on Linux

pyconfig.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,9 @@
12151215
/* Define if uuid_create() exists. */
12161216
#undef HAVE_UUID_CREATE
12171217

1218+
/* Define if uuid_enc_be() exists. */
1219+
#undef HAVE_UUID_ENC_BE
1220+
12181221
/* Define if uuid_generate_time_safe() exists. */
12191222
#undef HAVE_UUID_GENERATE_TIME_SAFE
12201223

0 commit comments

Comments
 (0)