Skip to content
Merged
Changes from 3 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
10 changes: 9 additions & 1 deletion Objects/unionobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,16 @@ union_getitem(PyObject *self, PyObject *item)
{
unionobject *alias = (unionobject *)self;
// Populate __parameters__ if needed.
// Avoid the critical section if it's already initialized.
if (alias->parameters == NULL) {
alias->parameters = _Py_make_parameters(alias->args);
Py_BEGIN_CRITICAL_SECTION(alias);
// Need to check again once we got the lock, another thread may have
// initialized it while we were waiting for the lock.
if (alias->parameters == NULL) {
alias->parameters = _Py_make_parameters(alias->args);
}
Py_END_CRITICAL_SECTION();

if (alias->parameters == NULL) {
return NULL;
}
Expand Down
Loading