Skip to content

Commit

Permalink
moduleobject: fix data races
Browse files Browse the repository at this point in the history
  • Loading branch information
colesbury committed Apr 23, 2023
1 parent 4ca2924 commit 3cfbc49
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Objects/moduleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ PyModuleDef_Init(PyModuleDef* def)
{
assert(PyModuleDef_Type.tp_flags & Py_TPFLAGS_READY);
if (def->m_base.m_index == 0) {
_PyRuntime.imports.last_module_index++;
Py_ssize_t last_module_index =
_Py_atomic_add_ssize(&_PyRuntime.imports.last_module_index, 1) + 1;
assert(_PyObject_IS_IMMORTAL((PyObject*) def));
Py_SET_TYPE(def, &PyModuleDef_Type);
def->m_base.m_index = _PyRuntime.imports.last_module_index;
def->m_base.m_index = last_module_index;
}
return (PyObject*)def;
}
Expand Down

0 comments on commit 3cfbc49

Please sign in to comment.