mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-01-21 03:51:47 -08:00
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.
This commit is contained in:
parent
50bb32d2c6
commit
65ef5eb9a1
1 changed files with 23 additions and 15 deletions
38
src/c/ffi.d
38
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue