]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-127545: Add _Py_ALIGNED_DEF(N, T) and use it for PyObject (GH-135209)
authorPetr Viktorin <encukou@gmail.com>
Wed, 11 Jun 2025 10:44:58 +0000 (12:44 +0200)
committerGitHub <noreply@github.com>
Wed, 11 Jun 2025 10:44:58 +0000 (12:44 +0200)
commit49d72365cd2d6c09a154a9a061efef4130e2c758
tree39c318acad08458621004e4eff90a26d6d4774ed
parent2b8b4774d29a707330d463f226630185cbd3ceff
gh-127545: Add _Py_ALIGNED_DEF(N, T) and use it for PyObject (GH-135209)

* Replace _Py_ALIGN_AS(V) by _Py_ALIGNED_DEF(N, T)

This is now a common façade for the various `_Alignas` alternatives,
which behave in interesting ways -- see the source comment.

The new macro (and MSVC's `__declspec(align)`) should not be used
on a variable/member declaration that includes a struct declaraton.
A workaround is to separate the struct definition.
Do that for `PyASCIIObject.state`.

* Specify minimum PyGC_Head and PyObject alignment

As documented in InternalDocs/garbage_collector.md, the garbage collector
stores flags in the least significant two bits of the _gc_prev pointer
in struct PyGC_Head. Consequently, this pointer is only capable of storing
a location that's aligned to a 4-byte boundary.

Encode this requirement using _Py_ALIGNED_DEF.

This patch fixes a segfault in m68k, which was previously investigated
by Adrian Glaubitz here:
https://lists.debian.org/debian-68k/2024/11/msg00020.html
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1087600
Original patch (using the GCC-only Py_ALIGNED) by Finn Thain.

Co-authored-by: Finn Thain <fthain@linux-m68k.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Include/Python.h
Include/cpython/unicodeobject.h
Include/internal/pycore_interp_structs.h
Include/object.h
Include/pymacro.h
Misc/NEWS.d/next/Build/2024-12-04-10-00-35.gh-issue-127545.t0THjE.rst [new file with mode: 0644]