Question: stack allocation and alignment

"Scott L. Burson" <[email protected]> Sat, 4 Jul 2026 15:28:56 -0700
Newsgroups gmane.lisp.steel-bank.devel
Message-ID <CAF5LJ4BO84dmr+TXF3hst=9OdxBFv+YcXfWQaEs=T1xzycxkDw@mail.gmail.com>
--===============2205872637683583936==
Content-Type: multipart/alternative; boundary="000000000000406b820655d09396"

--000000000000406b820655d09396
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hi all,

I posted this question on the CFFI discussion board just now, but the board
seems somewhat abandoned; I'm not sure I'll receive a reply.  I thought I
would run it by you as well.

=EF=BB=BF=EF=BB=BFJust started using CFFI, and I'm curious about something.=
 There is
> machinery to compute the alignment of any type, but `with-foreign-pointer=
'
> doesn't accept an alignment; on SBCL, it calls `sb-alien:with-alien'
> requesting a byte (octet) array, which presumably has alignment 1.
> `with-foreign-object', in contrast, knows the desired type and in princip=
le
> could guarantee the required alignment, but there's no code to do this.
>
> Now, this seems like the kind of thing that would have been fixed years
> ago if it actually caused SIGBUS or whatever on some CPUs. (I gather that
> x86-64 handles misalignment without complaint, albeit at some performance
> cost.) But I'm still curious exactly how we get away with it. Are stack
> allocations in all CL implementations guaranteed to produce a pointer wit=
h
> the largest alignment the hardware could require?


-- Scott

--000000000000406b820655d09396
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hi all,</div><div><br></div><div>I posted this questi=
on on the CFFI discussion board just now, but the board seems somewhat aban=
doned; I&#39;m not sure I&#39;ll receive a reply.=C2=A0 I thought I would r=
un it by you as well.</div><div><br></div><blockquote class=3D"gmail_quote"=
 style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);p=
adding-left:1ex">=EF=BB=BF=EF=BB=BFJust started using CFFI, and I&#39;m cur=
ious about something. There is machinery to compute the alignment of any ty=
pe, but `with-foreign-pointer&#39; doesn&#39;t accept an alignment; on SBCL=
, it calls `sb-alien:with-alien&#39; requesting a byte (octet) array, which=
 presumably has alignment 1. `with-foreign-object&#39;, in contrast, knows =
the desired type and in principle could guarantee the required alignment, b=
ut there&#39;s no code to do this.<br><br>Now, this seems like the kind of =
thing that would have been fixed years ago if it actually caused SIGBUS or =
whatever on some CPUs. (I gather that x86-64 handles misalignment without c=
omplaint, albeit at some performance cost.) But I&#39;m still curious exact=
ly how we get away with it. Are stack allocations in all CL implementations=
 guaranteed to produce a pointer with the largest alignment the hardware co=
uld require?</blockquote><div><br></div><div>-- Scott</div><div><br></div><=
/div>

--000000000000406b820655d09396--


--===============2205872637683583936==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============2205872637683583936==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Sbcl-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sbcl-devel

--===============2205872637683583936==--