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

gh-136421: Fix crash when _datetime is been initialized in multiple sub-interpreters by aisk · Pull Request #136422 · python/cpython · GitHub

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

Filter by extension

Filter by extension .c  (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
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,2 @@
Fix a crash when :mod:`datetime` is being imported in multiple
sub-interpreters at the same time.
7 changes: 6 additions & 1 deletion Modules/_datetimemodule.c
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 @@ -7336,6 +7336,8 @@ init_static_types(PyInterpreterState *interp, int reloading)
return 0;
}

static PyMutex mutex = {0};
PyMutex_Lock(&mutex);
// `&...` is not a constant expression according to a strict reading
// of C standards. Fill tp_base at run-time rather than statically.
// See https://bugs.python.org/issue40777
Expand All @@ -7346,11 +7348,14 @@ init_static_types(PyInterpreterState *interp, int reloading)
* so capi_types must have the types in the appropriate order. */
for (size_t i = 0; i < Py_ARRAY_LENGTH(capi_types); i++) {
PyTypeObject *type = capi_types[i];
if (_PyStaticType_InitForExtension(interp, type) < 0) {
int ret = _PyStaticType_InitForExtension(interp, type);
if (ret < 0) {
PyMutex_Unlock(&mutex);
Comment thread
aisk marked this conversation as resolved.
return -1;
}
}

PyMutex_Unlock(&mutex);
return 0;
}

Expand Down
Loading

Back | FazBrowse Home | New Git URL