Skip to content

bpo-32493: Fix uuid.uuid1() on FreeBSD. #7099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed :func:`uuid.uuid1` on FreeBSD.
9 changes: 8 additions & 1 deletion Modules/_uuidmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ py_uuid_generate_time_safe(PyObject *Py_UNUSED(context),

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)];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The size should be 16 bytes.
https://www.freebsd.org/cgi/man.cgi?query=uuid_create
"must be large enough to hold the 16-octet binary UUID"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since @ned-deily wants this fix, I took the liberty of fixing this issue myself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait. My change only modified the size of the buffer, but not configure, not the call to Py_BuildValue two lines below. I reverted my change.

Anyway, the module constructor has an assertion for sizeof(uuid_t) == 16.

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);
Expand Down Expand Up @@ -58,6 +64,7 @@ PyInit__uuid(void)
}
if (PyModule_AddIntConstant(mod, "has_uuid_generate_time_safe",
has_uuid_generate_time_safe) < 0) {
Py_DECREF(mod);
return NULL;
}

Expand Down
34 changes: 34 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -9584,6 +9584,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
Expand Down
15 changes: 15 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2696,6 +2696,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
Expand Down
3 changes: 3 additions & 0 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,9 @@
/* 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

Expand Down