From 663b75b357e77bfc47e31830b4e49cf1b026b141 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 21 May 2022 18:50:10 -0700 Subject: ffi: fat bitfield bugfix for big endian. * ffi.c (make_ffi_type_struct, make_ffi_type_union): We must take fat bitfields into account when calculating mtft->shift on big endian. We must subtract from bits_llint not bits_int for big endian. --- ffi.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ffi.c b/ffi.c index c8b7c62d..a2bad2b3 100644 --- a/ffi.c +++ b/ffi.c @@ -3588,7 +3588,12 @@ static val make_ffi_type_struct(val syntax, val lisp_type, #if HAVE_LITTLE_ENDIAN mtft->shift = bit_offs; #else - mtft->shift = bits_int - bit_offs - bits; +#if HAVE_I64 + if (size > sizeof (int)) + mtft->shift = bits_llint - bit_offs - bits; + else +#endif + mtft->shift = bits_int - bit_offs - bits; #endif #if HAVE_I64 @@ -3748,7 +3753,12 @@ static val make_ffi_type_union(val syntax, val use_existing, val self) #if HAVE_LITTLE_ENDIAN mtft->shift = 0; #else - mtft->shift = bits_int - bits; +#if HAVE_I64 + if (size > sizeof (int)) + mtft->shift = bits_llint - bits; + else +#endif + mtft->shift = bits_int - bits; #endif #if HAVE_I64 -- cgit v1.2.3