<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">Hi Nicolas, Hi Marcel,<br><div dir="ltr"><br></div><div dir="ltr"><br><blockquote type="cite">On May 29, 2020, at 8:02 AM, Nicolas Cellier <nicolas.cellier.aka.nice@gmail.com> wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr"><div dir="ltr"><div>Try with this:</div><div><br></div><div>cat > test_align.c <<END<br></div><div>#include <stdio.h><br><br>struct foo1 {int a; long long b; int d;};<br>struct foo2 {int a; double c; int d;};<br></div></div></div></blockquote><div><br></div>Here’s a suggestion.  We add a primitive To the ThreadedFFIPlugin that answers structure alignment thusly:<div><br></div><div>- the primitive takes as it’s argument the numeric code for the integer or float type or a structure as used in the compiled type specs </div><div>- the primitive answers the alignment of the data type in a struct that looks like this:</div><div><br></div><div>struct alignment_of_longlong {</div><div>     char pad_to_force_alignment;</div><div>     long long element;</div><div>}</div><div><br></div><div>return &((struct alignment_of_longlong *)0)-> element);</div><div><br></div><div><div>struct alignment_of_double {</div><div>     char pad_to_force_alignment;</div><div>     long long element;</div><div>}</div><div><br></div><div>return &((struct alignment_of_double *)0)-> element);</div></div><div><br></div><div><br></div><div><div>struct alignment_of_struct {</div><div>     char pad_to_force_alignment;</div><div>     struct { char element; } element;</div><div>}</div><div><br></div><div>return &((struct alignment_of_struct *)0)-> element);</div></div><div><br></div><div>etc</div><div><br></div><div>Then we can remember these alignments in class vars of, say, ExternalStructure, check them on start-up, and resize/update ExternalStructure if any of the values change.</div><div><br><blockquote type="cite"><div dir="ltr"><div dir="ltr"><div>int main() {<br>struct foo1 x;<br>struct foo2 y;<br>printf("size of x = %d\n",sizeof(x));<br>printf("size of y = %d\n",sizeof(y));<br>return 0;<br>}</div><div>END</div><div>i686-w64-mingw32-gcc test_align.c</div><div> ./a.exe</div><div><br></div><div>size of x = 24<br>size of y = 24</div><div><br></div><div>so at leat in windows (mingw) the alignment is 8 bytes for both long long and double.</div><div>I have no 32bits linux handy, but it should be easy enough to pass the same test...<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le ven. 29 mai 2020 à 16:45, Nicolas Cellier <<a href="mailto:nicolas.cellier.aka.nice@gmail.com">nicolas.cellier.aka.nice@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Good catch!</div><div>Wikipedia page does not even agree on longlong... But it's not the ultimate normative reference, better check by ourselves!</div><div><a href="https://en.wikipedia.org/wiki/Data_structure_alignment" target="_blank">https://en.wikipedia.org/wiki/Data_structure_alignment</a></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le ven. 29 mai 2020 à 15:53, Marcel Taeumel <<a href="mailto:marcel.taeumel@hpi.de" target="_blank">marcel.taeumel@hpi.de</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div id="gmail-m_-350231688662115500gmail-m_3414838106470931193__MailbirdStyleContent" style="font-size:10pt;font-family:Arial;color:rgb(0,0,0)">Hi, there.<div></div><div><br></div><div>In ExternalType class >> #initializeAtomicTypes, there is an interesting claim and a piece of dead code:</div><div><br></div><div><div>"On 32 bits Windows and MacOS, double and long have an alignment of 8. But on Linux, their alignment is 4"</div><div>(Smalltalk wordSize = 4 and: [Smalltalk platformName = 'unix']) ifTrue: [</div><div><span style="white-space:pre-wrap">     </span>(#('double longlong ulonglong') includes: typeName) ifTrue: [</div><div><span style="white-space:pre-wrap">            </span>byteAlignment := 4</div><div><span style="white-space:pre-wrap">       </span>]</div><div>].</div></div><div><br></div><div>As you can see, there are single quotes missing and so will the path "byteAlignment  := 4" never be reached.</div><div><br></div><div>I tried to figure out whether one should either fix the conditional or remove the entire passage. Maybe this got long fixed inside the FFI plugin?</div><div><br></div><div>Best,</div><div>Marcel</div></div><br>
</blockquote></div>
</blockquote></div>
<span></span><br></div></blockquote></div></body></html>