Conversation
The alignment test introduced in pythongh-140557 guards against empty-allocation optimisations handing out oddly-aligned pointers, as had been observed for the empty `bytearray` used by pickle protocol 5. It compared every array buffer against the maximum alignment of any array element type, which over-specifies the requirement: an allocation only needs to be aligned for the type stored in it. This failed on 32-bit platforms using mimalloc for single-byte element types such as 'B', where the tiny allocation region only guarantees 4-byte alignment rather than the 8-byte alignment of `double`. Check instead that each array's buffer, empty or allocated, is aligned to at least the alignment of its element type. The alignment is derived from `struct` rather than from `itemsize`, since the two differ for types such as `Zf` and `Zd`. Co-authored-by: Jake Lishman <jake@binhbar.com>
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
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.
The alignment test introduced in gh-140557 guards against empty-allocation optimisations handing out oddly-aligned pointers, as had been observed for the empty
bytearrayused by pickle protocol 5. It compared every array buffer against the maximum alignment of any array element type, which over-specifies the requirement: an allocation only needs to be aligned for the type stored in it. This failed on 32-bit platforms using mimalloc for single-byte element types such as 'B', where the tiny allocation region only guarantees 4-byte alignment rather than the 8-byte alignment ofdouble.Check instead that each array's buffer, empty or allocated, is aligned to at least the alignment of its element type. The alignment is derived from
structrather than fromitemsize, since the two differ for types such asZfandZd.I took @jakelishman's PR and added the fixes from review by @colesbury in GH-145026