-
-
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
Changes from all commits
c3f4649
36a06c8
8488875
9a58924
12a008d
a1bbafd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -196,8 +196,23 @@ typedef struct { | |
| /* Define global variable for the C API and a macro for setting it. */ | ||
| static PyDateTime_CAPI *PyDateTimeAPI = NULL; | ||
|
|
||
| #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 commentThe reason will be displayed to describe this comment to others. Learn more. Sup non invert,'s ok! |
||
| _PyDateTime_IMPORT(void) { | ||
| PyDateTime_CAPI *val = _Py_atomic_load_ptr(&PyDateTimeAPI); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm now seeing this error in external code that includes Probably just missing a cast.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you get the error with C or C++?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| if (val == NULL) { | ||
| PyDateTime_CAPI *capi = (PyDateTime_CAPI *)PyCapsule_Import( | ||
| PyDateTime_CAPSULE_NAME, 0); | ||
| if (capi != NULL) { | ||
| /* if the compare exchange fails then in that case | ||
| another thread would have initialized it */ | ||
| _Py_atomic_compare_exchange_ptr(&PyDateTimeAPI, &val, (void *)capi); | ||
| return capi; | ||
| } | ||
| } | ||
| return val; | ||
| } | ||
|
|
||
| #define PyDateTime_IMPORT _PyDateTime_IMPORT() | ||
|
|
||
| /* Macro for access to the UTC singleton */ | ||
| #define PyDateTime_TimeZone_UTC PyDateTimeAPI->TimeZone_UTC | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix thread safety of :c:macro:`! PyDateTime_IMPORT`. |
Uh oh!
There was an error while loading. Please reload this page.