gh-112075: Make PyDictKeysObject thread-safe (#114741)

Adds locking for shared PyDictKeysObject's for dictionaries
This commit is contained in:
Dino Viehland 2024-02-20 16:40:37 -08:00 • committed by GitHub
parent 145bc2d638
commit 176df09adb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 257 additions and 93 deletions

View file

@ -136,6 +136,11 @@ struct _dictkeysobject {
/* Kind of keys */
uint8_t dk_kind;
#ifdef Py_GIL_DISABLED
/* Lock used to protect shared keys */
PyMutex dk_mutex;
#endif
/* Version number -- Reset to 0 by any modification to keys */
uint32_t dk_version;
@ -145,6 +150,7 @@ struct _dictkeysobject {
/* Number of used entries in dk_entries. */
Py_ssize_t dk_nentries;
/* Actual hash table of dk_size entries. It holds indices in dk_entries,
or DKIX_EMPTY(-1) or DKIX_DUMMY(-2).