[3.13] gh-128759: fix data race in type_modified_unlocked (GH-128764) (#128769)

* gh-128759: fix data race in `type_modified_unlocked` (GH-128764)
(cherry picked from commit 6e1e780540)

Co-authored-by: sobolevn <mail@sobolevn.me>
This commit is contained in:
Miss Islington (bot) 2025-01-13 13:39:39 +01:00 committed by GitHub
parent afcf238ed4
commit 632745ade1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -996,9 +996,15 @@ type_modified_unlocked(PyTypeObject *type)
We don't assign new version tags eagerly, but only as
needed.
*/
#ifdef Py_GIL_DISABLED
if (_Py_atomic_load_uint_relaxed(&type->tp_version_tag) == 0) {
return;
}
#else
if (type->tp_version_tag == 0) {
return;
}
#endif
// Cannot modify static builtin types.
assert((type->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) == 0);