-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
gh-141563: make PyDateTime_IMPORT thread-safe
#144210
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
Conversation
ea5a3ea to
a6f6595
Compare
3b08a06 to
96a62cb
Compare
96a62cb to
36a06c8
Compare
vstinner
left a comment
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.
LGTM.
|
|
||
| #define PyDateTime_IMPORT \ | ||
| PyDateTimeAPI = (PyDateTime_CAPI *)PyCapsule_Import(PyDateTime_CAPSULE_NAME, 0) | ||
| static inline PyDateTime_CAPI * |
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.
Sup non invert,'s ok!
| PyDateTimeAPI = (PyDateTime_CAPI *)PyCapsule_Import(PyDateTime_CAPSULE_NAME, 0) | ||
| static inline PyDateTime_CAPI * | ||
| _PyDateTime_IMPORT(void) { | ||
| PyDateTime_CAPI *val = _Py_atomic_load_ptr(&PyDateTimeAPI); |
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 now seeing this error in external code that includes datetime.h:
…/cpython_install/include/python3.15/datetime.h:201:22: error: cannot initialize a variable of type 'PyDateTime_CAPI *' with an rvalue of type 'void *'
201 | PyDateTime_CAPI *val = _Py_atomic_load_ptr(&PyDateTimeAPI);
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Probably just missing a cast.
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.
Do you get the error with C or C++?
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.
Ah, there is a compiler error in C++. I wrote #144667 to add the missing cast, but also to add checks for compiler warnings (to test_cext and test_cppext).
datetimeC API is not thread-safe #141563