pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/c00ac578241b3213ceb79c1f32bc83ea471f02da

> gh-131113: Fix data race in dict.popitem() (gh-131115) · python/cpython@c00ac57 · GitHub
Skip to content

Commit c00ac57

Browse files
authored
gh-131113: Fix data race in dict.popitem() (gh-131115)
The clearing of the key, hash, and value need to use atomic operations to avoid a data race with concurrent read operations.
1 parent ad90c5f commit c00ac57

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

Objects/dictobject.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,10 @@ load_keys_nentries(PyDictObject *mp)
275275

276276
#endif
277277

278-
#define STORE_KEY(ep, key) FT_ATOMIC_STORE_PTR_RELEASE(ep->me_key, key)
279-
#define STORE_VALUE(ep, value) FT_ATOMIC_STORE_PTR_RELEASE(ep->me_value, value)
278+
#define STORE_KEY(ep, key) FT_ATOMIC_STORE_PTR_RELEASE((ep)->me_key, key)
279+
#define STORE_VALUE(ep, value) FT_ATOMIC_STORE_PTR_RELEASE((ep)->me_value, value)
280280
#define STORE_SPLIT_VALUE(mp, idx, value) FT_ATOMIC_STORE_PTR_RELEASE(mp->ma_values->values[idx], value)
281-
#define STORE_HASH(ep, hash) FT_ATOMIC_STORE_SSIZE_RELAXED(ep->me_hash, hash)
281+
#define STORE_HASH(ep, hash) FT_ATOMIC_STORE_SSIZE_RELAXED((ep)->me_hash, hash)
282282
#define STORE_KEYS_USABLE(keys, usable) FT_ATOMIC_STORE_SSIZE_RELAXED(keys->dk_usable, usable)
283283
#define STORE_KEYS_NENTRIES(keys, nentries) FT_ATOMIC_STORE_SSIZE_RELAXED(keys->dk_nentries, nentries)
284284
#define STORE_USED(mp, used) FT_ATOMIC_STORE_SSIZE_RELAXED(mp->ma_used, used)
@@ -4534,8 +4534,8 @@ dict_popitem_impl(PyDictObject *self)
45344534
_PyDict_NotifyEvent(interp, PyDict_EVENT_DELETED, self, key, NULL);
45354535
hash = unicode_get_hash(key);
45364536
value = ep0[i].me_value;
4537-
ep0[i].me_key = NULL;
4538-
ep0[i].me_value = NULL;
4537+
STORE_KEY(&ep0[i], NULL);
4538+
STORE_VALUE(&ep0[i], NULL);
45394539
}
45404540
else {
45414541
PyDictKeyEntry *ep0 = DK_ENTRIES(self->ma_keys);
@@ -4549,9 +4549,9 @@ dict_popitem_impl(PyDictObject *self)
45494549
_PyDict_NotifyEvent(interp, PyDict_EVENT_DELETED, self, key, NULL);
45504550
hash = ep0[i].me_hash;
45514551
value = ep0[i].me_value;
4552-
ep0[i].me_key = NULL;
4553-
ep0[i].me_hash = -1;
4554-
ep0[i].me_value = NULL;
4552+
STORE_KEY(&ep0[i], NULL);
4553+
STORE_HASH(&ep0[i], -1);
4554+
STORE_VALUE(&ep0[i], NULL);
45554555
}
45564556

45574557
j = lookdict_index(self->ma_keys, hash, i);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy