This is the mail archive of the libffi-discuss@sourceware.org mailing list for the libffi project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Detect compiler's _Complex support with a configure check.


Fixes the build issue for compilers without C99 complex type
support as discussed.  Detection uses a configure test because
checking macros and compiler versions seemed too hairy.  Tested on
s390x. 

As a slight safety measure, the patched code uses "<type>
_Complex" instead of "_Complex <type>" as in the examples of the
C99 standard document, just in case there's some odd compiler out
there that requires that specific order (although the standard
demands that any order is allowed).

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany
>From c023e2248275d360ee1d0d26552c10b43cd13272 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]