Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.1k
gh-127545: Replace _Py_ALIGN_AS(V) by _Py_ALIGNED_DEF(N, T)#135209
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
Draft
encukou wants to merge3 commits intopython:mainChoose a base branch fromencukou:gc_crash
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+123 −106
Conversation
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
As documented in InternalDocs/garbage_collector.md, the garbage collectorstores flags in the least significant two bits of the _gc_prev pointerin struct PyGC_Head. Consequently, this pointer is only capable of storinga location that's aligned to a 4-byte boundary.This alignment requirement is documented but it's not actually encoded.The code only works when python happens to run on a platform that has asufficiently large minimum alignment for the structs in question.The same problem arises with PyObject pointers because the leastsignificant bits get used for PyStackRef tags.Since we know that 2 bits are needed, we also know the minimum alignmentthat's needed. Let's make that explicit, so the compiler can then makethose bits available.This patch fixes a segfault in _bootstrap_python. In 3.14.0 beta 2this fixes the "Assertion `!PyStackRef_IsTaggedInt(ref)' failed" whenbuilt with --config-pydebug.Also, making the requirements explicit improves clarity.This bug was previously investigated by Adrian Glaubitz here:https://lists.debian.org/debian-68k/2024/11/msg00020.htmlhttps://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1087600Although Adrian's patch isn't really correct (because natural alignmentis not needed), he deserves full credit for finding the root cause.
This is a common façade for the various `_Alignas` alternatives,which behave in interesting ways.The standard `alignas` errors if it would decrease the alignment;to prevent that it can be used again with the defined variable'stype.The standard `alignas` can't be used on a `struct` definition,the workaround is to use it on one of the `struct`'s members.MSVC `declspec(aligned)` only takes integer literals.MSVC `declspec(aligned)` had a bug when applied to a combinedstruct+member definition.The workaround is to separate the struct definition.Do that for `PyASCIIObject.state`.
bedevere-bot commentedJun 6, 2025
🤖 New build scheduled with the buildbot fleet by@encukou for commit512fe58 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F135209%2Fmerge If you want to schedule another build, you need to add the🔨 test-with-buildbots label again. |
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading.Please reload this page.
_Py_ALIGNED_DEF(N, T)
might be a better way to make the various_Alignas
alternatives,which behave in interesting ways,increase (rather thanset) a variable's alignment.
The standard
alignas
/_Alignas
error out if they would decrease the alignment. To prevent that, they can be used again with the defined variable's type.The standard
alignas
/_Alignas
can't be used on astruct
definition, the workaround is to use it on one of thestruct
's members.MSVC
declspec(aligned)
only takes integer literals.MSVC
declspec(aligned)
had a bug when applied to a combined struct+member definition; a workaround is to separate the struct definition. This avoids the C5274 warning.This PR does that for
PyASCIIObject.state
.