Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-129069: make list ass_slice and memory_repeat safe in free-threading#131882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
0c8dcfc67c9459e460b5afcdb634b1e9216944abf03a9e2490f96d5847f3d81adf2c15b56986587d48ff26ee081ac4e968890186e7c250faa0dca2680c12d2f16eb60e36e314f220d83bed61d9656a5a0d34d11a8610e27ce439d7a16cf5b8ab9d168e2d83e1c14be79bf93f2272fec60721321e34fa03a7850bebe4f11823c1bceaef4baab26b262839f772c8fb96132238cb08298ee5d372b7a6eb550e2c5f2ec3a23fb5813655635d217088c40e2063f7311b616c191c2610784d19154a132a5f4d9e73c7cc193b90c7bf15e9339bee16387232d6f4ef28c2de542e6d3e5c9c4debdf16774732f960400c57d338a3787File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -87,6 +87,8 @@ | ||
| # error "this header file must not be included directly" | ||
| #endif | ||
| #include <assert.h> | ||
| // --- _Py_atomic_add -------------------------------------------------------- | ||
| // Atomically adds `value` to `obj` and returns the previous value | ||
| @@ -545,6 +547,63 @@ static inline Py_ssize_t | ||
| _Py_atomic_load_ssize_acquire(const Py_ssize_t *obj); | ||
| // --- _Py_atomic_memcpy / _Py_atomic_memmove ------------ | ||
| static inline void * | ||
| _Py_atomic_memcpy_ptr_store_relaxed(void *dest, void *src, size_t n) | ||
| { | ||
| void **dest_, **src_, **end; | ||
| assert(((uintptr_t)dest & (uintptr_t)(sizeof (void *) - 1)) == 0); | ||
| assert(((uintptr_t)src & (uintptr_t)(sizeof (void *) - 1)) == 0); | ||
| assert(n % (size_t)sizeof(void *) == 0); | ||
| if (dest != src) { | ||
kumaraditya303 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| dest_ = (void **)dest; | ||
| src_ = (void **)src; | ||
| end = dest_ + n / sizeof(void *); | ||
| for (; dest_ != end; dest_++, src_++) { | ||
| _Py_atomic_store_ptr_relaxed(dest_, *src_); | ||
| } | ||
| } | ||
| return dest; | ||
| } | ||
| static inline void * | ||
| _Py_atomic_memmove_ptr_store_relaxed(void *dest, void *src, size_t n) | ||
| { | ||
| void **dest_, **src_, **end; | ||
| assert(((uintptr_t)dest & (uintptr_t)(sizeof (void *) - 1)) == 0); | ||
| assert(((uintptr_t)src & (uintptr_t)(sizeof (void *) - 1)) == 0); | ||
| assert(n % (size_t)sizeof(void *) == 0); | ||
| if (dest < src || dest >= (void *)((char *)src + n)) { | ||
| dest_ = (void **)dest; | ||
| src_ = (void **)src; | ||
| end = dest_ + n / sizeof(void *); | ||
| for (; dest_ != end; dest_++, src_++) { | ||
| _Py_atomic_store_ptr_relaxed(dest_, *src_); | ||
| } | ||
| } | ||
| else if (dest > src) { | ||
| n = n / sizeof(void *) - 1; | ||
| dest_ = (void **)dest + n; | ||
| src_ = (void **)src + n; | ||
| end = (void **)dest - 1; | ||
| for (; dest_ != end; dest_--, src_--) { | ||
| _Py_atomic_store_ptr_relaxed(dest_, *src_); | ||
| } | ||
| } | ||
| return dest; | ||
| } | ||
| // --- _Py_atomic_fence ------------------------------------------------------ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,6 +12,8 @@ extern "C" { | ||
| #include "pycore_stackref.h" | ||
| #endif | ||
| #include "pycore_pyatomic_ft_wrappers.h" | ||
| PyAPI_FUNC(PyObject*) _PyList_Extend(PyListObject *, PyObject *); | ||
| PyAPI_FUNC(PyObject) *_PyList_SliceSubscript(PyObject*, PyObject*); | ||
| extern void _PyList_DebugMallocStats(FILE *out); | ||
| @@ -51,15 +53,17 @@ _PyList_AppendTakeRef(PyListObject *self, PyObject *newitem) | ||
| return _PyList_AppendTakeRefListResize(self, newitem); | ||
| } | ||
| // Repeat the bytes of a buffer in place | ||
| // Repeat the bytes of a buffer of pointers in place | ||
| static inline void | ||
| _Py_memory_repeat(char* dest, Py_ssize_t len_dest, Py_ssize_t len_src) | ||
| _Py_memory_ptrs_repeat(char* dest, Py_ssize_t len_dest, Py_ssize_t len_src) | ||
| { | ||
| assert(len_src > 0); | ||
| assert(len_src % sizeof(void *) == 0); | ||
| assert(((uintptr_t)dest & (sizeof (void *) - 1)) == 0); | ||
tom-pytel marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| Py_ssize_t copied = len_src; | ||
| while (copied < len_dest) { | ||
| Py_ssize_t bytes_to_copy = Py_MIN(copied, len_dest - copied); | ||
| memcpy(dest + copied, dest, (size_t)bytes_to_copy); | ||
| FT_ATOMIC_MEMCPY_PTR_STORE_RELAXED(dest + copied, dest, (size_t)bytes_to_copy); | ||
| copied += bytes_to_copy; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix data race when assigning list slices concurrently. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.