Skip to content

gh-149965: use ptr_wise_atomic_memmove within element_ass_subscr#151271

Open
clin1234 wants to merge 19 commits into
python:mainfrom
clin1234:patch-4
Open

gh-149965: use ptr_wise_atomic_memmove within element_ass_subscr#151271
clin1234 wants to merge 19 commits into
python:mainfrom
clin1234:patch-4

Conversation

@clin1234

@clin1234 clin1234 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

clin1234 and others added 15 commits June 10, 2026 09:55
…FW3ZD.rst

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
…ternal helper and add unit tests

Extract the duplicated static `ptr_wise_atomic_memmove` from
`Modules/_elementtree.c` and `Objects/listobject.c` into a shared
`static inline _Py_ptr_wise_atomic_memmove(PyObject *a, ...)` in
`Include/internal/pycore_object.h`.  The first parameter is generalised
from a type-specific pointer to `PyObject *` since only `PyObject *`-
level operations (`_Py_IsOwnedByCurrentThread`, `_PyObject_GC_IS_SHARED`)
were ever performed on it.

`listobject.c` previously embedded `_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED`
inside the local helper.  That assertion is preserved by moving it
explicitly to each of the four call sites in `listobject.c` (which are
all called under a critical section).  `_elementtree.c`'s open question
about whether a critical section is needed remains unanswered, so no
assertion is added there.

Unit tests are added in `Modules/_testinternalcapi/test_ptr_wise_memmove.c`
covering: dest < src (forward copy), dest > src (backward copy),
dest == src (no-op), overlapping ranges, and the single-owner fast path.
The single-owner test explicitly clears the GC SHARED bit to guard against
freelist reuse leaving the bit set from a sibling test.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Commented out critical section assertion for ElementObject.
@clin1234 clin1234 changed the title gh-149965: ptr_wise_atomic_memmove use within element_ass_subscr gh-149965: use ptr_wise_atomic_memmove within element_ass_subscr Jun 10, 2026
@clin1234

Copy link
Copy Markdown
Contributor Author

@ZeroIntensity, I've reverted the header change and unit test additions, so my current PR is focused on only one file.

@ZeroIntensity

Copy link
Copy Markdown
Member

I think you misunderstood what I meant. You can move the function to a header (and in fact, you should, because otherwise we're duplicating code), but it was weird to do it in its own PR. Just combine this PR with #151255 and it'll be fine.

@clin1234 clin1234 marked this pull request as draft June 11, 2026 00:58
@clin1234 clin1234 marked this pull request as ready for review June 11, 2026 00:58
@clin1234

Copy link
Copy Markdown
Contributor Author

@ZeroIntensity, mind taking a look again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants