Replies: 2 comments 1 reply
|
SBCL's WITH-ALIEN calls malloc underneath, which is guaranteed to return
DWORD alignment. For larger alignments, you can use posix_memalign() or
static-vectors.
…On July 5, 2026 00:52:38 "Scott L. Burson" ***@***.***> wrote:
Just 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 with-alien requesting a byte
(octet) array, which presumably has alignment 1. with-foreign-object knows
the desired type and in principle 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 with
the largest alignment the hardware could require?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
Stelian Ionescu
|
1 reply
|
I see: people just haven't generally been stack-allocating structs. And I should assume that only single-word alignment is guaranteed in that case. The library I am calling via CFFI contains this: which means that This suggests two desirable features:
For the moment, I can work around the issue by writing my own version of |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Just started using CFFI, and I'm curious about something. There is machinery to compute the alignment of any type, but
with-foreign-pointerdoesn't accept an alignment; on SBCL, it callssb-alien:with-alienrequesting a byte (octet) array, which presumably has alignment 1.with-foreign-objectknows the desired type and in principle 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 with the largest alignment the hardware could require?
All reactions