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


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

URL: http://github.com/python/cpython/pull/149914/files

lesheet" href="https://github.githubassets.com/assets/code-34e10031edc15af1.css" /> gh-149816: fix `dict.clear()` race on split-table dict with non-embedded values by kumaraditya303 · Pull Request #149914 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 28 additions & 0 deletions Lib/test/test_free_threading/test_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,34 @@ def watcher():
finally:
_testcapi.clear_dict_watcher(wid)

def test_racing_split_dict_clear_and_lookup(self):
class C:
pass

keys = [f"a{i}" for i in range(16)]

def make_split_nonembedded():
inst = C()
for key in keys:
setattr(inst, key, keys.index(key))
# dict.copy() of a split instance dict yields a split table
# with non-embedded values
return inst.__dict__.copy()

d = make_split_nonembedded()

def clearer():
for _ in range(1000):
d.clear()
d.update(make_split_nonembedded())

def reader():
for _ in range(1000):
for k in keys:
d.get(k)

threading_helper.run_concurrently([clearer, reader, reader])

def test_racing_dict_update_and_method_lookup(self):
# gh-144295: test race between dict modifications and method lookups.
# Uses BytesIO because the race requires a type without Py_TPFLAGS_INLINE_VALUES
Expand Down
6 changes: 4 additions & 2 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3083,10 +3083,12 @@ clear_lock_held(PyObject *op)
set_keys(mp, Py_EMPTY_KEYS);
n = oldkeys->dk_nentries;
for (i = 0; i < n; i++) {
Py_CLEAR(oldvalues->values[i]);
PyObject *tmp = oldvalues->values[i];
FT_ATOMIC_STORE_PTR_RELEASE(oldvalues->values[i], NULL);
Py_XDECREF(tmp);
}
free_values(oldvalues, IS_DICT_SHARED(mp));
dictkeys_decref(oldkeys, false);
dictkeys_decref(oldkeys, IS_DICT_SHARED(mp));
}
ASSERT_CONSISTENT(mp);
}
Expand Down
Loading
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