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

gh-149965: promote `ptr_wise_atomic_memmove` to internal header by clin1234 · Pull Request #151255 · python/cpython · GitHub

/ cpython Public

gh-149965: promote ptr_wise_atomic_memmove to internal header - #151255

Closed
clin1234 wants to merge 14 commits into
python:mainfrom
clin1234:patch-4
Closed

gh-149965: promote ptr_wise_atomic_memmove to internal header#151255
clin1234 wants to merge 14 commits into
python:mainfrom
clin1234:patch-4

Conversation

clin1234 commented Jun 10, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

clin1234 and others added 12 commits June 10, 2026 09:55
Commented out critical section assertion for ElementObject.
…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>

Copy link
Copy Markdown
Contributor Author

@ericsnowcurrently, mind taking a look on helping me on resolving the mutable global variable issue in Modules/_testinternalcapi/test_ptr_wise_memmove.c?

ZeroIntensity left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm having a hard time understanding the motivation here. The DPO and C API WG threads look inconclusive.

There's not any reason to add tests and a generalized implementation for something that we only use in list; if we wanted to use it elsewhere, then we could move it to a header. If you have a plan to do so, then just do this in the PR you'll create. We don't need a separate patch just for moving the function.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Internal changes don't need changelog entries; you can remove this.

bedevere-app Bot commented Jun 10, 2026

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Copy link
Copy Markdown
Contributor Author

@ericsnowcurrently, mind taking a look on helping me on resolving the mutable global variable issue in Modules/_testinternalcapi/test_ptr_wise_memmove.c?

I'm having a hard time understanding the motivation here. The DPO and C API WG threads look inconclusive.

There's not any reason to add tests and a generalized implementation for something that we only use in list; if we wanted to use it elsewhere, then we could move it to a header. If you have a plan to do so, then just do this in the PR you'll create. We don't need a separate patch just for moving the function.

The reason for the generalized implementation is that I found it helpful for replacing certain memmoves in _elementtree.c, and because in the previous PR, someone suggested unit tests for this function: #149966 (comment)

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again.

bedevere-app Bot commented Jun 10, 2026

Copy link
Copy Markdown

Thanks for making the requested changes!

@ZeroIntensity: please review the changes made to this pull request.

bedevere-app Bot requested a review from ZeroIntensity June 10, 2026 16:44

Copy link
Copy Markdown
Member

Ok, do the move in that fix. I don't personally think this needs unit tests beyond just covering the code paths that use it, but if you really want to have them, just put them in that PR.

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
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


Back | FazBrowse Home | New Git URL