This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: PyMem_Malloc() should guarantee alignof(max_align_t)
Type: behavior Stage: needs patch
Components: Interpreter Core Versions: Python 3.7, Python 3.6, Python 3.4, Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: fweimer, gregory.p.smith, skrah, twouters, vstinner
Priority: normal Keywords:

Created on 2017-10-31 18:01 by skrah, last changed 2022-04-11 14:58 by admin.

Messages (4)
msg305320 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2017-10-31 18:01
This is related to #27987 and #20064 and perhaps the pymalloc patch
from #18835.

I think PyMem_Malloc() should guarantee alignof(max_align_t).

It actually did before the "#define PYMEM_FUNCS PYOBJ_FUNCS" optimization,
so we have a sort of regression here.
msg305322 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-10-31 18:07
> I think PyMem_Malloc() should guarantee alignof(max_align_t).

Do you mean the C++ std::max_align_t? Does C99 have something like that?

The Linux malloc() manual page says:

"The malloc() and calloc() functions return a pointer to  the  allocated memory,  which  is  suitably  aligned for any built-in type."

But I don't know the list of C built-in types.
msg305324 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2017-10-31 18:14
> Do you mean the C++ std::max_align_t? Does C99 have something like that?
> 
> The Linux malloc() manual page says:
> 
> "The malloc() and calloc() functions return a pointer to  the  allocated memory,  which  is  suitably  aligned for any built-in type."

C11 has max_align_t, but also for C99 "any builtin type" means 16 byte alignment
for long double on x64, so malloc() and calloc() are required to align 16 bytes
with -std=c99 (and earlier).

max_align_t is just a shorthand to express the concept.
msg311322 - (view) Author: Florian Weimer (fweimer) Date: 2018-01-31 10:55
max_align_t is a bit of a kitchen sink and will specify larger and larger alignment in the future, e.g. 32-byte alignment for a complex _Float128 type (a pair of two _Float128 variables).  The alignment is also not generally useful for allocations whose size is smaller than the alignment.  (Many mallocs do not follow the C standard and do not provide 16-byte alignment when 8 bytes are allocated, although alignof(max_align_t) is 16.)
History
Date User Action Args
2022-04-11 14:58:53adminsetgithub: 76093
2018-01-31 10:55:10fweimersetnosy: + fweimer
messages: + msg311322
2018-01-31 00:13:00gregory.p.smithsetnosy: + twouters, gregory.p.smith
2017-10-31 18:14:43skrahsetmessages: + msg305324
2017-10-31 18:07:15vstinnersetmessages: + msg305322
2017-10-31 18:02:09skrahsetnosy: + vstinner
2017-10-31 18:01:35skrahcreate