Comment 13 for bug 436758

Revision history for this message
Scott James Remnant (Canonical) (canonical-scott) wrote :

Follow on from that, it turns out (unsurprisingly) that it's the alignment of the returned pointer that matters; and that since we only know the size, not the type, we have to guess what the maximum possible alignment must be.

Code (and comments) in glibc suggest:

 max (sizeof (size_t) * 2, __alignof__ (long long))

This is the alignment size we want for NihAllocCtx, thus

#define NIH_ALLOC_CTX_ALIGN nih_max (sizeof (size_t) * 2, __alignof__ (long long))
#define NIH_ALLOC_CTX_SIZE (NIH_ALLOC_CTX_ALIGN * (sizeof (NihAllocCtx) / NIH_ALLOC_CTX_ALIGN + 1))

is probably right.

On the bright side, it means there's a spare 4 bytes in the NihAllocCtx structure ;-)