From 65ef5eb9a15d27874c81e58d0ab63fd8830a94ce Mon Sep 17 00:00:00 2001 From: Juan Jose Garcia Ripoll Date: Thu, 16 Dec 2010 16:13:16 +0100 Subject: [PATCH] Reimplement the way we search for alignments using a more portable strategy -- MSVC complains saying that the difference of two known pointers is not a constant expression. --- src/c/ffi.d | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/c/ffi.d b/src/c/ffi.d index 497aca2be..36ab3256d 100644 --- a/src/c/ffi.d +++ b/src/c/ffi.d @@ -61,16 +61,30 @@ static const cl_object ecl_aet_to_ffi_table[aet_bc+1] = { #define AUX_PTR(type) \ ((struct { char a[1]; union { type c[1]; char d[sizeof(type)]; } b; } *)0) -#define ALIGNMENT(type) \ - (AUX_PTR(type)->b.d - AUX_PTR(type)->a) +#ifdef __GNUC__ +typedef struct { + cl_object name; + cl_index size; + cl_index alignment; +} ecl_foreign_type_record; +# define ALIGNMENT(tag) (ecl_foreign_type_table[tag].alignment) +# define FFI_DESC(symbol,type) \ + {symbol, sizeof(type), (AUX_PTR(type)->b.d - AUX_PTR(type)->a)} +#else +typedef struct { + cl_object name; + cl_index size; + char *d, *a; +} ecl_foreign_type_record; +#define ALIGNMENT(tag) (ecl_foreign_type_table[tag].d - ecl_foreign_type_table[tag].a) +#define AUX_PTR(type) \ + ((struct { char a[1]; union { type c[1]; char d[sizeof(type)]; } b; } *)0) #define FFI_DESC(symbol,type) \ - {symbol, sizeof(type), ALIGNMENT(type)} + {symbol, sizeof(type), AUX_PTR(type)->b.d, AUX_PTR(type)->a} +#endif -static const struct{ - cl_object name; - cl_index size; - cl_index alignment; -} ecl_foreign_type_table[] = { +static const ecl_foreign_type_record +ecl_foreign_type_table[] = { FFI_DESC(@':char', char), FFI_DESC(@':unsigned-char', unsigned char), FFI_DESC(@':byte', ecl_int8_t), @@ -109,12 +123,6 @@ static const struct{ {@':void', 0, 0} }; -static const int foreign_type_alignment[] = { - ALIGNMENT(char), - ALIGNMENT(unsigned char), - ALIGNMENT(int) -}; - #ifdef ECL_DYNAMIC_FFI static const cl_object ecl_foreign_cc_table[] = { @':cdecl', @@ -645,7 +653,7 @@ cl_object si_alignment_of_foreign_elt_type(cl_object type) { enum ecl_ffi_tag tag = ecl_foreign_type_code(type); - @(return MAKE_FIXNUM(ecl_foreign_type_table[tag].alignment)) + @(return MAKE_FIXNUM(ALIGNMENT(tag))) } cl_object