-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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
bpo-11063: Fix _uuid module on macOS #3855
Conversation
I tested this PR manually on macOS Sierra: test_uuid pass, and is_safe attribute is unknown as expected.
Note: I hacked _netstat_getnode() in Lib/uuid.py to add "-n" option to make tests faster, to prevent slow DNS resolution. |
Modules/_uuidmodule.c
Outdated
{ | ||
uuid_t out; | ||
uuid_generate_time(out); | ||
return PyBytes_FromStringAndSize((const char *) out, sizeof(out)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer if you'd return the (out, None)
tuple here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to have very thin wrapper for C functions, and handle differences at the Python level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it only makes both the Python code and the C code more complicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the annoyances with modifying uuid.py
is that there are so different code paths to take care of.
Modules/_uuidmodule.c
Outdated
{"generate_time_safe", (PyCFunction) py_uuid_generate_time_safe, METH_NOARGS, NULL}, | ||
#else | ||
{"generate_time", (PyCFunction) py_uuid_generate_time, METH_NOARGS, NULL}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to expose two different function names, IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to expose two different function names, IMO.
It's not the same API:
- _uuid.generate_time_safe() returns (uuid, is_safe).
- _uuid.generate_time() only returns the uuid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm proposing that it's the same API (see above) :-)
I simplified my PR to not add a new function with a different name in _uuid. Instead, I modified uuid.py to decide if we have or not uuid_generate_time_safe() using sys.platform. |
Instead of checking sys.platform, maybe we could have a constant in _uuid? |
Yes, I think it's better to put this in |
On macOS, use uuid_generate_time() instead of uuid_generate_time_safe() of libuuid, since uuid_generate_time_safe() is not available.
Ok, done. I added _uuid.has_uuid_generate_time_safe (int: 1 or 0). |
Thank you! :-) |
I'd rather see a configure check for the existence of |
@warsaw: "I'd rather see a configure check for ..." Please, go ahead and write it :-) I began to look at AC_CHECK_HEADER() but I don't see how to pass /usr/include/uuid/ to ask to test also this directory. Then I wanted to use pkg-config, but @pitrou showed me that it doesn't exist on macOS. In short, modifying the autotools are out of my skills. I proposed a pragmatic solution to fix the _uuid module on macOS. |
I agree with @warsaw. This should be a configure check. |
On macOS, use uuid_generate_time() instead of
uuid_generate_time_safe() of libuuid, since uuid_generate_time_safe()
is not available.
https://bugs.python.org/issue11063