Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyMem_Malloc() should guarantee alignof(max_align_t) #76093

Closed
skrah mannequin opened this issue Oct 31, 2017 · 5 comments
Closed

PyMem_Malloc() should guarantee alignof(max_align_t) #76093

skrah mannequin opened this issue Oct 31, 2017 · 5 comments
Labels
3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@skrah
Copy link
Mannequin

skrah mannequin commented Oct 31, 2017

BPO 31912
Nosy @Yhg1s, @gpshead, @vstinner, @skrah

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2017-10-31.18:01:35.929>
labels = ['interpreter-core', 'type-bug', '3.7']
title = 'PyMem_Malloc() should guarantee alignof(max_align_t)'
updated_at = <Date 2018-01-31.10:55:10.425>
user = 'https://github.com/skrah'

bugs.python.org fields:

activity = <Date 2018-01-31.10:55:10.425>
actor = 'fweimer'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Interpreter Core']
creation = <Date 2017-10-31.18:01:35.929>
creator = 'skrah'
dependencies = []
files = []
hgrepos = []
issue_num = 31912
keywords = []
message_count = 4.0
messages = ['305320', '305322', '305324', '311322']
nosy_count = 5.0
nosy_names = ['twouters', 'gregory.p.smith', 'vstinner', 'skrah', 'fweimer']
pr_nums = []
priority = 'normal'
resolution = None
stage = 'needs patch'
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue31912'
versions = ['Python 3.4', 'Python 3.5', 'Python 3.6', 'Python 3.7']

@skrah
Copy link
Mannequin Author

skrah mannequin commented Oct 31, 2017

This is related to bpo-27987 and bpo-20064 and perhaps the pymalloc patch
from bpo-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.

@skrah skrah mannequin added 3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Oct 31, 2017
@vstinner
Copy link
Member

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.

@skrah
Copy link
Mannequin Author

skrah mannequin commented Oct 31, 2017

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.

@fweimer
Copy link
Mannequin

fweimer mannequin commented Jan 31, 2018

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

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@erlend-aasland
Copy link
Contributor

Superseded by gh-91335

@erlend-aasland erlend-aasland closed this as not planned Won't fix, can't repro, duplicate, stale Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants