Cyrus Harmon wrote:
> Dear sbcl-devel,
> The following patch allows for explicitly setting an :alignment
> keyword option in sb-alien struct definitions such as the following:
> (sb-alien:define-alien-type align-test-struct
> (sb-alien:struct nil
> (s1 sb-alien:unsigned-char)
> (c1 sb-alien:unsigned-char :alignment 16)
> (c2 sb-alien:unsigned-char :alignment 32)
> (c3 sb-alien:unsigned-char :alignment 32)
> (c4 sb-alien:unsigned-char :alignment 8)))
> This may seem like a rather silly thing to do, but certain compilers
> support a #pragma pack that packs struct fields more tightly together
> and this can be used to ensure that the sb-alien struct alignment
> matches the compilers.
As a sidenote, a plain "#pragma pack" usually means byte-packed to the
minimal size, which is different to what is wanted here.
Sidenote 2, such pragmas break the C ABI guarantees about struct
layout, they usually shouldn't show up in exported interfaces.
> My actual motivation for this, although I
> would request that you not dismiss this out of hand just because this
> happens to be the motivating reason, is to make sb-alien struct
> definitions for various Mac OS toolbox structures that, for 68k
> compatibility reasons, are compiled with an Apple specific #pragma
> align=m68k directive that causes things to be 16-bit aligned instead
> of 32-bit aligned.
Since compiler writers don't use completely random alignment rules,
it might be better to have one :maximum-alignment key for the whole
(Probably I underestimate the insanity of Apple's compiler guys, the
struct you are describing usually has no padding whatsoever.)