FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-141563: make `PyDateTime_IMPORT` thread-safe by kumaraditya303 · Pull Request #144210 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .h  (1) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
19 changes: 17 additions & 2 deletions Include/datetime.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Comment thread
kumaraditya303 marked this conversation as resolved.
Comment thread
kumaraditya303 marked this conversation as resolved.
_PyDateTime_IMPORT(void) {
PyDateTime_CAPI *val = _Py_atomic_load_ptr(&PyDateTimeAPI);
Comment thread
kumaraditya303 marked this conversation as resolved.
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
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix thread safety of :c:macro:`! PyDateTime_IMPORT`.
Loading

Back | FazBrowse Home | New Git URL