It seems like a bug in NLFFI SML/NJ implementation. C function is
void f0
( short a0
, short a1
and so on
, short a7
) {
printf ("a0 == %hx\n", a0);
printf ("a1 == %hx\n", a1);
and so on
printf ("a7 == %hx\n", a7);
}
I compile it by
gcc -shared -fPIC -m32 -o libdelme.so _.c
and install. Invocation from C
f0 (0x7654, 0x3210, 0x9876, 0x5432, 0x1234, 0x5678, 0x9012, 0x3456);
prints correct values, and invocation from ML
F_f0.f' (0x7654, 0x3210, 0x9876, 0x5432, 0x1234, 0x5678, 0x9012, 0x3456);
prints this
a0 == 7654
a1 == 9876
a2 == 1234
a3 == 9012
a4 == 0
a5 == 1800
a6 == 3cf0
a7 == ee00
A similar effect is with signed char
. It seems that my C library is expecting arguments aligned to 2^5-bit address and NLFFI does not align them.
I was encountered this error when creating a binding to XCB, so I can't change its header files, function prototypes and such. Everything is already prepared in my Linux distribution.
Maybe it is related that I cross-compile, i.e. compile to x86 code on AMD64.
SML/NJ version
$ pacman -Q smlnj
smlnj 110.77-1