From be683858d8618500dfd3ca3db2cba35a2180d3e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Thu, 3 Apr 2008 17:28:42 +0200 Subject: [PATCH] Fix inline machinery for GCC 4.3 and later in C99 mode. --- NEWS | 1 + libguile/ChangeLog | 7 +++++ libguile/inline.h | 77 ++++++++++++++++++++++------------------------ 3 files changed, 45 insertions(+), 40 deletions(-) diff --git a/NEWS b/NEWS index 394eacfb7..ad476f94d 100644 --- a/NEWS +++ b/NEWS @@ -30,6 +30,7 @@ Previously, parsing short option names of argument-less options would lead to a stack overflow. ** Fixed type-checking for the second argument of `eval' +** Allow compilation of Guile-using programs in C99 mode with GCC 4.3 and later ** Fixed build issue for GNU/Linux on IA64 ** Fixed build issues on NetBSD 1.6 ** Fixed build issue on Solaris 2.10 x86_64 diff --git a/libguile/ChangeLog b/libguile/ChangeLog index c9bc110df..bacfe2456 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -1,3 +1,10 @@ +2008-04-03 Ludovic Courtès + + * inline.h (SCM_C_EXTERN_INLINE): New macro, addresses the + "extern inline" semantic change in C99 mode with GCC 4.3 and + later and the warning in C99 mode with GCC 4.2. Use it in the + inline function definitions. + 2008-03-10 Ludovic Courtès * eval.c, filesys.c: Enclose `alloca' blob in `#ifndef alloca', diff --git a/libguile/inline.h b/libguile/inline.h index a27024bea..2b5b2a4dc 100644 --- a/libguile/inline.h +++ b/libguile/inline.h @@ -38,6 +38,32 @@ #include "libguile/pairs.h" +#ifndef SCM_INLINE_C_INCLUDING_INLINE_H + +/* GCC has `__inline__' in all modes, including strict ansi. GCC 4.3 and + above with `-std=c99' or `-std=gnu99' implements ISO C99 inline semantics, + unless `-fgnu89-inline' is used. Here we want GNU "extern inline" + semantics, hence the `__gnu_inline__' attribute, in accordance with: + http://gcc.gnu.org/gcc-4.3/porting_to.html . + + With GCC 4.2, `__GNUC_STDC_INLINE__' is never defined (because C99 inline + semantics are not supported), but a warning is issued in C99 mode if + `__gnu_inline__' is not used. */ + +# ifdef __GNUC__ +# if (defined __GNUC_STDC_INLINE__) || (__GNUC__ == 4 && __GNUC_MINOR__ == 2) +# define SCM_C_EXTERN_INLINE \ + extern __inline__ __attribute__ ((__gnu_inline__)) +# else +# define SCM_C_EXTERN_INLINE extern __inline__ +# endif +# elif (defined SCM_C_INLINE) +# define SCM_C_EXTERN_INLINE static SCM_C_INLINE +# endif + +#endif /* SCM_INLINE_C_INCLUDING_INLINE_H */ + + #if ((!defined SCM_C_INLINE) && (!defined SCM_INLINE_C_INCLUDING_INLINE_H)) \ || (defined __GNUC__) @@ -66,14 +92,9 @@ SCM_API int scm_is_pair (SCM x); extern unsigned scm_newcell2_count; extern unsigned scm_newcell_count; -#if defined SCM_C_INLINE && ! defined SCM_INLINE_C_INCLUDING_INLINE_H -/* definitely inlining */ -#ifdef __GNUC__ -extern -#else -static -#endif -SCM_C_INLINE + +#if defined SCM_C_EXTERN_INLINE && ! defined SCM_INLINE_C_INCLUDING_INLINE_H +SCM_C_EXTERN_INLINE #endif SCM scm_cell (scm_t_bits car, scm_t_bits cdr) @@ -142,14 +163,8 @@ scm_cell (scm_t_bits car, scm_t_bits cdr) return z; } -#if defined SCM_C_INLINE && ! defined SCM_INLINE_C_INCLUDING_INLINE_H -/* definitely inlining */ -#ifdef __GNUC__ -extern -#else -static -#endif -SCM_C_INLINE +#if defined SCM_C_EXTERN_INLINE && ! defined SCM_INLINE_C_INCLUDING_INLINE_H +SCM_C_EXTERN_INLINE #endif SCM scm_double_cell (scm_t_bits car, scm_t_bits cbr, @@ -217,14 +232,8 @@ scm_double_cell (scm_t_bits car, scm_t_bits cbr, return z; } -#if defined SCM_C_INLINE && ! defined SCM_INLINE_C_INCLUDING_INLINE_H -/* definitely inlining */ -#ifdef __GNUC__ -extern -#else -static -#endif -SCM_C_INLINE +#if defined SCM_C_EXTERN_INLINE && ! defined SCM_INLINE_C_INCLUDING_INLINE_H +SCM_C_EXTERN_INLINE #endif SCM scm_array_handle_ref (scm_t_array_handle *h, ssize_t p) @@ -232,14 +241,8 @@ scm_array_handle_ref (scm_t_array_handle *h, ssize_t p) return h->ref (h, p); } -#if defined SCM_C_INLINE && ! defined SCM_INLINE_C_INCLUDING_INLINE_H -/* definitely inlining */ -#ifdef __GNUC__ -extern -#else -static -#endif -SCM_C_INLINE +#if defined SCM_C_EXTERN_INLINE && ! defined SCM_INLINE_C_INCLUDING_INLINE_H +SCM_C_EXTERN_INLINE #endif void scm_array_handle_set (scm_t_array_handle *h, ssize_t p, SCM v) @@ -247,14 +250,8 @@ scm_array_handle_set (scm_t_array_handle *h, ssize_t p, SCM v) h->set (h, p, v); } -#if defined SCM_C_INLINE && ! defined SCM_INLINE_C_INCLUDING_INLINE_H -/* definitely inlining */ -#ifdef __GNUC__ -extern -#else -static -#endif -SCM_C_INLINE +#if defined SCM_C_EXTERN_INLINE && ! defined SCM_INLINE_C_INCLUDING_INLINE_H +SCM_C_EXTERN_INLINE #endif int scm_is_pair (SCM x)