[squeak-dev] Alignment of FFI ExternalStructure fields
Nicolas Cellier
nicolas.cellier.aka.nice at gmail.com
Fri Apr 13 17:53:57 UTC 2018
So the current algorithm in #defineFields: and compileFields: is producing
compact structures layout with all fields aligned on 1 byte.
It does not correspond to any platform behavior except when using special
pragmas or compiler options.
The current workaround is to force a length in 3rd column of spec.
https://stackoverflow.com/questions/49782651/how-one-aligns-structure-fields-in-squeak-ffi/49782754#49782754
But it's brainfuck:
- it depends both on the fields preceding and the fields following
- it becomes very hard to support both 32+64 bits
#(
(x 'char' 2)
(y 'short')
)
#(
(x 'char' 4) "depends on the field following"
(y 'long')
)
#(
(w 'char' 1)
(x 'char' 3) "but also on the field preceding"
(y 'long')
)
I'd like to make our default behavior match that of the current platform
- atomic fields of size 1,2,4,8 bytes have alignment = size
- pointers also have alignment = pointer size (4 or 8).
- nested structures have alignment = max of alignment of their fields
Then we can support exotic alignment with a 4th column in spec:
#( (x 'char' -1 1) (y 'short' -1 1) ) "compact"
The 3rd column -1 or nil would mean
"use the default size rather than force a user defined one"
Other suggestions?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20180413/deaae960/attachment.html>
More information about the Squeak-dev
mailing list
|