Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a crash when ``_datetime`` is being imported in multiple
sub-interpreters at the same time.
7 changes: 6 additions & 1 deletion Modules/_datetimemodule.c
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);
return -1;
}
}

PyMutex_Unlock(&mutex);
return 0;
}

Expand Down
Loading