public inbox for libffi-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
To: libffi-discuss@sourceware.org
Subject: [PATCH] Detect compiler's _Complex support with a configure check.
Date: Thu, 13 Nov 2014 07:11:00 -0000	[thread overview]
Message-ID: <20141113071138.GB10649@linux.vnet.ibm.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 543 bytes --]

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

[-- Attachment #2: 0001-Detect-compiler-s-_Complex-support-with-a-configure-.patch --]
[-- Type: text/x-diff, Size: 2423 bytes --]

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


                 reply	other threads:[~2014-11-13  7:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141113071138.GB10649@linux.vnet.ibm.com \
    --to=vogt@linux.vnet.ibm.com \
    --cc=libffi-discuss@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).