From c023e2248275d360ee1d0d26552c10b43cd13272 Mon Sep 17 00:00:00 2001 From: Dominik Vogt Date: Tue, 11 Nov 2014 13:55:22 +0100 Subject: [PATCH] Detect compiler's _Complex support with a configure check. This is needed in types.c to initialise the ffi_type_complex_... structs. --- configure.ac | 9 +++++++++ src/types.c | 21 ++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 4a44bff..cb44dbf 100644 --- a/configure.ac +++ b/configure.ac @@ -363,6 +363,15 @@ fi AC_SUBST(HAVE_LONG_DOUBLE) AC_SUBST(HAVE_LONG_DOUBLE_VARIANT) +# detect c99 complex type support +AH_TEMPLATE([HAVE_COMPLEX_TYPES],[Compiler supports C99 complex types]) +AC_MSG_CHECKING([whether compiler supports C99 complex types]) +AC_TRY_COMPILE(, + [float _Complex cf;], + AC_DEFINE(HAVE_COMPLEX_TYPES) + AC_MSG_RESULT(yes), + AC_MSG_RESULT([no[,] guess their size and alignment])) + AC_C_BIGENDIAN GCC_AS_CFI_PSEUDO_OP diff --git a/src/types.c b/src/types.c index ef4f151..e16153b 100644 --- a/src/types.c +++ b/src/types.c @@ -44,13 +44,14 @@ maybe_const ffi_type ffi_type_##name = { \ id, NULL \ } +#ifdef HAVE_COMPLEX_TYPES #define FFI_COMPLEX_TYPEDEF(name, type, maybe_const) \ static ffi_type *ffi_elements_complex_##name [2] = { \ (ffi_type *)(&ffi_type_##name), NULL \ }; \ struct struct_align_complex_##name { \ char c; \ - _Complex type x; \ + type _Complex x; \ }; \ maybe_const ffi_type ffi_type_complex_##name = { \ sizeof(_Complex type), \ @@ -58,6 +59,24 @@ maybe_const ffi_type ffi_type_complex_##name = { \ FFI_TYPE_COMPLEX, \ (ffi_type **)ffi_elements_complex_##name \ } +#else +/* Bogus definition for compilers without C99 complex support. */ +#define FFI_COMPLEX_TYPEDEF(name, type, maybe_const) \ +static ffi_type *ffi_elements_complex_##name [2] = { \ + (ffi_type *)(&ffi_type_##name), NULL \ +}; \ +struct struct_align_complex_##name { \ + char c; \ + type x; \ + type y; \ +}; \ +maybe_const ffi_type ffi_type_complex_##name = { \ + 2 * sizeof(type), \ + offsetof(struct struct_align_complex_##name, x), \ + FFI_TYPE_COMPLEX, \ + (ffi_type **)ffi_elements_complex_##name \ +} +#endif /* Size and alignment are fake here. They must not be 0. */ const ffi_type ffi_type_void = { -- 1.8.4.2