FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-143100: Fix memcpy data race in setobject.c by colesbury · Pull Request #143127 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .txt  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
16 changes: 16 additions & 0 deletions Objects/setobject.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,17 @@ set_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return make_new_set(type, NULL);
}

#ifdef Py_GIL_DISABLED
static void
copy_small_table(setentry *dest, setentry *src)
{
for (Py_ssize_t i = 0; i < PySet_MINSIZE; i++) {
_Py_atomic_store_ptr_release(&dest[i].key, src[i].key);
_Py_atomic_store_ssize_relaxed(&dest[i].hash, src[i].hash);
}
}
#endif

/* set_swap_bodies() switches the contents of any two sets by moving their
internal data pointers and, if needed, copying the internal smalltables.
Semantically equivalent to:
Expand Down Expand Up @@ -1462,8 +1473,13 @@ set_swap_bodies(PySetObject *a, PySetObject *b)

if (a_table == a->smalltable || b_table == b->smalltable) {
memcpy(tab, a->smalltable, sizeof(tab));
#ifndef Py_GIL_DISABLED
memcpy(a->smalltable, b->smalltable, sizeof(tab));
memcpy(b->smalltable, tab, sizeof(tab));
#else
copy_small_table(a->smalltable, b->smalltable);
copy_small_table(b->smalltable, tab);
#endif
}

if (PyType_IsSubtype(Py_TYPE(a), &PyFrozenSet_Type) &&
Expand Down
3 changes: 0 additions & 3 deletions Tools/tsan/suppressions_free_threading.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,3 @@ thread:pthread_create
# PyObject_Realloc internally does memcpy which isn't atomic so can race
# with non-locking reads. See #132070
race:PyObject_Realloc

# gh-143100: set_swap_bodies in setobject.c calls memcpy, which isn't atomic
race:set_swap_bodies
Loading

Back | FazBrowse Home | New Git URL