Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
tom-pytel wants to merge13 commits intopython:main
base:main
Choose a base branch
Loading
fromtom-pytel:fix-issue-129069
Open
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
13 commits
Select commitHold shift + click to select a range
0c8dcfc
gh-129069: make list ass_slice and memory_repeat safe
tom-pytelMar 29, 2025
67c9459
📜🤖 Added by blurb_it.
blurb-it[bot]Mar 29, 2025
e460b5a
include atomic wrappers in pycore_list.h
tom-pytelMar 29, 2025
fcdb634
provisional fix to compile on windows
tom-pytelMar 29, 2025
b1e9216
requested changes so far
tom-pytelApr 1, 2025
944abf0
Merge branch 'main' into fix-issue-129069
tom-pytelApr 1, 2025
3a9e249
Merge branch 'main' into fix-issue-129069
tom-pytelApr 4, 2025
0f96d58
remove atomic load and rename
tom-pytelApr 8, 2025
47f3d81
Merge branch 'main' into fix-issue-129069
tom-pytelApr 8, 2025
adf2c15
Merge branch 'main' into fix-issue-129069
tom-pytelApr 14, 2025
b569865
Merge branch 'main' into fix-issue-129069
tom-pytelApr 23, 2025
87d48ff
Merge branch 'main' into fix-issue-129069
tom-pytelMay 18, 2025
26ee081
requested variable name changes
tom-pytelMay 18, 2025
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
PrevPrevious commit
NextNext commit
requested changes so far
  • Loading branch information
@tom-pytel
tom-pytel committedApr 1, 2025
commitb1e92160cbfa9a8cbb76ab006be3e2c51a1c8776
58 changes: 58 additions & 0 deletionsInclude/cpython/pyatomic.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -545,6 +545,64 @@ 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_relaxed(void *dest, void *src, Py_ssize_t sn)
{
size_t n = (size_t)sn;
assert(((uintptr_t)dest & (sizeof (void *) - 1)) == 0);
assert(((uintptr_t)src & (sizeof (void *) - 1)) == 0);
assert(n % sizeof(void *) == 0);

if (dest != src) {
void **d = (void **)dest;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

For the sake of my brain: could we use some more descriptive variable names here?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

How brain feel about these?

void **s = (void **)src;
void **e = d + n / sizeof(void *);

for (; d != e; d++, s++) {
void *v = _Py_atomic_load_ptr_relaxed(s);
_Py_atomic_store_ptr_relaxed(d, v);
}
}

return dest;
}

static inline void *
_Py_atomic_memmove_ptr_relaxed(void *dest, void *src, Py_ssize_t sn)
{
size_t n = (size_t)sn;
assert(((uintptr_t)dest & (sizeof (void *) - 1)) == 0);
assert(((uintptr_t)src & (sizeof (void *) - 1)) == 0);
assert(n % sizeof(void *) == 0);

if (dest < src || dest >= (void *)((char *)src + n)) {
void **d = (void **)dest;
void **s = (void **)src;
void **e = d + n / sizeof(void *);

for (; d != e; d++, s++) {
void *v = _Py_atomic_load_ptr_relaxed(s);
_Py_atomic_store_ptr_relaxed(d, v);
}
}
else if (dest > src) {
n = n / sizeof(void *) - 1;
void **d = (void **)dest + n;
void **s = (void **)src + n;
void **e = (void **)dest - 1;

for (; d != e; d--, s--) {
void *v = _Py_atomic_load_ptr_relaxed(s);
_Py_atomic_store_ptr_relaxed(d, v);
}
}

return dest;
}




// --- _Py_atomic_fence ------------------------------------------------------
Expand Down
45 changes: 0 additions & 45 deletionsInclude/internal/pycore_pyatomic_ft_wrappers.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -110,53 +110,8 @@ extern "C" {
#define FT_ATOMIC_LOAD_ULLONG_RELAXED(value) \
_Py_atomic_load_ullong_relaxed(&value)

// This should probably be moved into its own file as a real function.
static inline void *
_Py_atomic_memcpy_ptr_relaxed(void *dest, void *src, Py_ssize_t sn)
{
size_t n = (size_t)sn;
assert(((uintptr_t)dest & (sizeof (void *) - 1)) == 0);
assert(((uintptr_t)src & (sizeof (void *) - 1)) == 0);
assert(n % sizeof(void *) == 0);

if (dest != src) {
for (void **d = (void **)dest, **s = (void **)src, **e = d + n / sizeof(void *); d != e; d++, s++) {
void *v = _Py_atomic_load_ptr_relaxed(s);
_Py_atomic_store_ptr_relaxed(d, v);
}
}

return dest;
}

#define FT_ATOMIC_MEMCPY_PTR_RELAXED(dest, src, n) \
_Py_atomic_memcpy_ptr_relaxed(dest, src, (Py_ssize_t)(n))

static inline void *
_Py_atomic_memmove_ptr_relaxed(void *dest, void *src, Py_ssize_t sn)
{
size_t n = (size_t)sn;
assert(((uintptr_t)dest & (sizeof (void *) - 1)) == 0);
assert(((uintptr_t)src & (sizeof (void *) - 1)) == 0);
assert(n % sizeof(void *) == 0);

if (dest < src || dest >= (void *)((char *)src + n)) { // prefer incrementing copy
for (void **d = (void **)dest, **s = (void **)src, **e = d + n / sizeof(void *); d != e; d++, s++) {
void *v = _Py_atomic_load_ptr_relaxed(s);
_Py_atomic_store_ptr_relaxed(d, v);
}
}
else if (dest > src) {
n = n / sizeof(void *) - 1;
for (void **d = (void **)dest + n, **s = (void **)src + n, **e = (void **)dest - 1; d != e; d--, s--) {
void *v = _Py_atomic_load_ptr_relaxed(s);
_Py_atomic_store_ptr_relaxed(d, v);
}
}

return dest;
}

#define FT_ATOMIC_MEMMOVE_PTR_RELAXED(dest, src, n) \
_Py_atomic_memmove_ptr_relaxed(dest, src, (Py_ssize_t)(n))

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
Fix data race andmake sure no jagged writes in ``list.list_ass_slice``.
Fix data race andavoid jagged writes in ``list.list_ass_slice``.
Loading

[8]ページ先頭

©2009-2025 Movatter.jp