From 44fea2aa6193f5f06678cfef689649a987545f34 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 4 Jan 2005 05:31:44 +0000 Subject: [PATCH] Fix the inlining magic. (#157536, Jens Hatlak, and #149907, Morten 2005-01-04 Matthias Clasen Fix the inlining magic. (#157536, Jens Hatlak, and #149907, Morten Welinder) * configure.in: Define G_CAN_INLINE in glibconfig.h * glib/gutils.h: Streamline the inlining magic a bit, don't use extern when implementing the non-inlined version. --- ChangeLog | 11 +++++++++++ ChangeLog.pre-2-10 | 11 +++++++++++ ChangeLog.pre-2-12 | 11 +++++++++++ ChangeLog.pre-2-6 | 11 +++++++++++ ChangeLog.pre-2-8 | 11 +++++++++++ configure.in | 43 +++++++++++++++++++++++++++++++++++++++++++ glib/gutils.h | 35 ++++++++++++----------------------- 7 files changed, 110 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 697439f..8d8a63c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2005-01-04 Matthias Clasen + + Fix the inlining magic. (#157536, Jens Hatlak, and + #149907, Morten Welinder) + + * configure.in: Define G_CAN_INLINE in glibconfig.h + + * glib/gutils.h: Streamline the inlining magic a bit, + don't use extern when implementing the non-inlined + version. + 2005-01-03 Matthias Clasen * glib/gutils.c (g_find_program_in_path): Don't return diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 697439f..8d8a63c 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,14 @@ +2005-01-04 Matthias Clasen + + Fix the inlining magic. (#157536, Jens Hatlak, and + #149907, Morten Welinder) + + * configure.in: Define G_CAN_INLINE in glibconfig.h + + * glib/gutils.h: Streamline the inlining magic a bit, + don't use extern when implementing the non-inlined + version. + 2005-01-03 Matthias Clasen * glib/gutils.c (g_find_program_in_path): Don't return diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 697439f..8d8a63c 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,14 @@ +2005-01-04 Matthias Clasen + + Fix the inlining magic. (#157536, Jens Hatlak, and + #149907, Morten Welinder) + + * configure.in: Define G_CAN_INLINE in glibconfig.h + + * glib/gutils.h: Streamline the inlining magic a bit, + don't use extern when implementing the non-inlined + version. + 2005-01-03 Matthias Clasen * glib/gutils.c (g_find_program_in_path): Don't return diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 697439f..8d8a63c 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,14 @@ +2005-01-04 Matthias Clasen + + Fix the inlining magic. (#157536, Jens Hatlak, and + #149907, Morten Welinder) + + * configure.in: Define G_CAN_INLINE in glibconfig.h + + * glib/gutils.h: Streamline the inlining magic a bit, + don't use extern when implementing the non-inlined + version. + 2005-01-03 Matthias Clasen * glib/gutils.c (g_find_program_in_path): Don't return diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 697439f..8d8a63c 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,14 @@ +2005-01-04 Matthias Clasen + + Fix the inlining magic. (#157536, Jens Hatlak, and + #149907, Morten Welinder) + + * configure.in: Define G_CAN_INLINE in glibconfig.h + + * glib/gutils.h: Streamline the inlining magic a bit, + don't use extern when implementing the non-inlined + version. + 2005-01-03 Matthias Clasen * glib/gutils.c (g_find_program_in_path): Don't return diff --git a/configure.in b/configure.in index 7009747..8083b7c 100644 --- a/configure.in +++ b/configure.in @@ -662,6 +662,34 @@ case x$glib_cv_hasinline in xyes) AC_DEFINE(G_HAVE_INLINE,1,[Have inline keyword]) esac +# if we can use inline functions in headers +AC_MSG_CHECKING(if inline functions in headers work) +AC_LINK_IFELSE([ +#if defined (G_HAVE_INLINE) && defined (__GNUC__) && defined (__STRICT_ANSI__) +# undef inline +# define inline __inline__ +#elif !defined (G_HAVE_INLINE) +# undef inline +# if defined (G_HAVE___INLINE__) +# define inline __inline__ +# elif defined (G_HAVE___INLINE) +# define inline __inline +# endif +#endif + +int glib_test_func2 (int); + +static inline int +glib_test_func1 (void) { + return glib_test_func2 (1); +} + +int +main (void) { + int i = 1; +}],[g_can_inline=yes],[g_can_inline=no]) +AC_MSG_RESULT($g_can_inline) + # check for flavours of varargs macros AC_MSG_CHECKING(for ISO C99 varargs macros in C) AC_TRY_COMPILE([],[ @@ -2212,6 +2240,20 @@ $glib_vacopy $glib_inline #endif /* !__cplusplus */ +#ifdef __cplusplus +#define G_CAN_INLINE 1 +_______EOF + + if test x$g_can_inline = xyes ; then + cat >>$outfile <<_______EOF +#else /* !__cplusplus */ +#define G_CAN_INLINE 1 +_______EOF + fi + + cat >>$outfile <<_______EOF +#endif + _______EOF if test x$g_have_iso_c_varargs = xyes ; then @@ -2591,6 +2633,7 @@ g_have_gnuc_varargs=$g_have_gnuc_varargs g_have_iso_c_varargs=$g_have_iso_c_varargs g_have_iso_cxx_varargs=$g_have_iso_cxx_varargs +g_can_inline=$g_can_inline g_have_gnuc_visibility=$g_have_gnuc_visibility case xyes in diff --git a/glib/gutils.h b/glib/gutils.h index 8e43cde..c996673 100644 --- a/glib/gutils.h +++ b/glib/gutils.h @@ -71,21 +71,14 @@ G_BEGIN_DECLS /* inlining hassle. for compilers that don't allow the `inline' keyword, * mostly because of strict ANSI C compliance or dumbness, we try to fall * back to either `__inline__' or `__inline'. - * we define G_CAN_INLINE, if the compiler seems to be actually - * *capable* to do function inlining, in which case inline function bodys - * do make sense. we also define G_INLINE_FUNC to properly export the - * function prototypes if no inlining can be performed. + * G_CAN_INLINE is defined in glibconfig.h if the compiler seems to be + * actually *capable* to do function inlining, in which case inline + * function bodies do make sense. we also define G_INLINE_FUNC to properly + * export the function prototypes if no inlining can be performed. * inline function bodies have to be special cased with G_CAN_INLINE and a * .c file specific macro to allow one compiled instance with extern linkage * of the functions by defining G_IMPLEMENT_INLINES and the .c file macro. */ -#ifdef G_IMPLEMENT_INLINES -# define G_INLINE_FUNC extern -# undef G_CAN_INLINE -#endif -#ifndef G_INLINE_FUNC -# define G_CAN_INLINE 1 -#endif #if defined (G_HAVE_INLINE) && defined (__GNUC__) && defined (__STRICT_ANSI__) # undef inline # define inline __inline__ @@ -97,20 +90,16 @@ G_BEGIN_DECLS # define inline __inline # else /* !inline && !__inline__ && !__inline */ # define inline /* don't inline, then */ -# ifndef G_INLINE_FUNC -# undef G_CAN_INLINE -# endif # endif #endif -#ifndef G_INLINE_FUNC -# if defined (__GNUC__) && defined (__OPTIMIZE__) -# define G_INLINE_FUNC extern inline -# elif defined (G_CAN_INLINE) && !defined (__GNUC__) -# define G_INLINE_FUNC static inline -# else /* can't inline */ -# define G_INLINE_FUNC extern -# undef G_CAN_INLINE -# endif +#ifdef G_IMPLEMENT_INLINES +# define G_INLINE_FUNC +#elif defined (__GNUC__) && defined (__OPTIMIZE__) +# define G_INLINE_FUNC extern inline +#elif defined (G_CAN_INLINE) && !defined (__GNUC__) +# define G_INLINE_FUNC static inline +#else /* can't inline */ +# define G_INLINE_FUNC #endif /* !G_INLINE_FUNC */ /* Retrive static string info -- 2.7.4