Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-34366: fix FreeBSD with both system lib and libuuid present #8711

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

Closed
wants to merge 1 commit into from
Closed
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
21 changes: 12 additions & 9 deletions Modules/_uuidmodule.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#define PY_SSIZE_T_CLEAN

#include "Python.h"
#ifdef HAVE_UUID_H
#include <uuid.h>
#else
#ifdef HAVE_UUID_UUID_H
#include <uuid/uuid.h>
#endif
#ifdef HAVE_UUID_H
#include <uuid.h>
#endif


Expand All @@ -14,12 +15,7 @@ py_uuid_generate_time_safe(PyObject *Py_UNUSED(context),
PyObject *Py_UNUSED(ignored))
{
uuid_t uuid;
#ifdef HAVE_UUID_GENERATE_TIME_SAFE
int res;

res = uuid_generate_time_safe(uuid);
return Py_BuildValue("y#i", (const char *) uuid, sizeof(uuid), res);
#elif defined(HAVE_UUID_CREATE)
#ifdef HAVE_UUID_CREATE /* uuid.h variant */
uint32_t status;
uuid_create(&uuid, &status);
# if defined(HAVE_UUID_ENC_BE)
Expand All @@ -29,6 +25,11 @@ py_uuid_generate_time_safe(PyObject *Py_UNUSED(context),
# else
return Py_BuildValue("y#i", (const char *) &uuid, sizeof(uuid), (int) status);
# endif
#elif defined(HAVE_UUID_GENERATE_TIME_SAFE) /* uuid/uuid.h variants */
int res;

res = uuid_generate_time_safe(uuid);
return Py_BuildValue("y#i", (const char *) uuid, sizeof(uuid), res);
#else
uuid_generate_time(uuid);
return Py_BuildValue("y#O", (const char *) uuid, sizeof(uuid), Py_None);
Expand All @@ -53,7 +54,9 @@ PyInit__uuid(void)
{
PyObject *mod;
assert(sizeof(uuid_t) == 16);
#ifdef HAVE_UUID_GENERATE_TIME_SAFE
/* we prefer the system uuid.h library, so HAVE_UUID_GENERATE_TIME_SAFE
* does not matter when HAVE_UUID_CREATE is present */
#if defined(HAVE_UUID_GENERATE_TIME_SAFE) && !defined(HAVE_UUID_CREATE)
int has_uuid_generate_time_safe = 1;
#else
int has_uuid_generate_time_safe = 0;
Expand Down
20 changes: 15 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1614,12 +1614,22 @@ class db_found(Exception): pass
missing.append('_tkinter')

# Build the _uuid module if possible
uuid_incs = find_file("uuid.h", inc_dirs, ["/usr/include/uuid"])
# Note: we explicitly need to distinguish uuid.h and uuid/uuid.h
# as those are two libraries that can be installed simultaneously
uuid_incs = find_file("uuid.h", inc_dirs, [])
if uuid_incs is not None:
# this is the built-in system library
uuid_libs = []
else:
uuid_incs = find_file("uuid/uuid.h", inc_dirs, [])
if uuid_incs is not None:
# this is the external library, so we need -luuid
if self.compiler.find_library_file(lib_dirs, 'uuid'):
uuid_libs = ['uuid']
else:
uuid_incs = None

if uuid_incs is not None:
if self.compiler.find_library_file(lib_dirs, 'uuid'):
uuid_libs = ['uuid']
else:
uuid_libs = []
self.extensions.append(Extension('_uuid', ['_uuidmodule.c'],
libraries=uuid_libs,
include_dirs=uuid_incs))
Expand Down