GLib: clean up the "inline" mess once and for all

It's been a long time since we've been unconditionally saying "static
inline" in GLib headers without complaints so it's safe to assume that
all compilers that we care about support this.

One thing that is not yet totally supported is the unadorned use of the
word "inline".  Depending on the flags (-std=c89, for example), even GCC
will complain about this.  Detect missing C99 support and define
"inline" to "__inline" in that case.  Some research shows "__inline"
appears to be the most widely-supported keyword here, but we may need to
tweak this if we get some reports of breakage.

Clean up all of the configure checks around this and define G_CAN_INLINE
unconditionally.  Unfortunately, we must assume that some people are
still using G_IMPLEMENT_INLINES, we must continue to implement that
(including undefining G_CAN_INLINE and redefining G_INLINE_FUNC) if
requested.

It is not our intent to break existing users of the old-style
G_INLINE_FUNC approach and if that has happened, we may need to make
some further adjustments.

https://bugzilla.gnome.org/show_bug.cgi?id=757374
This commit is contained in:
Allison Ryan Lortie 2015-11-09 11:36:10 -05:00
parent 9834f79279
commit db2367e878
4 changed files with 29 additions and 149 deletions

View File

@ -623,78 +623,6 @@ AC_CACHE_CHECK([for growing stack pointer],glib_cv_stack_grows,[
,)
])
dnl AC_C_INLINE is useless to us since it bails out too early, we need to
dnl truely know which ones of `inline', `__inline' and `__inline__' are
dnl actually supported.
AC_CACHE_CHECK([for __inline],glib_cv_has__inline,[
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
__inline int foo () { return 0; }
int main () { return foo (); }
]])],
glib_cv_has__inline=yes
,
glib_cv_has__inline=no
,)
])
case x$glib_cv_has__inline in
xyes) AC_DEFINE(G_HAVE___INLINE,1,[Have __inline keyword])
esac
AC_CACHE_CHECK([for __inline__],glib_cv_has__inline__,[
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
__inline__ int foo () { return 0; }
int main () { return foo (); }
]])],
glib_cv_has__inline__=yes
,
glib_cv_has__inline__=no
,)
])
case x$glib_cv_has__inline__ in
xyes) AC_DEFINE(G_HAVE___INLINE__,1,[Have __inline__ keyword])
esac
AC_CACHE_CHECK([for inline], glib_cv_hasinline,[
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#undef inline
inline int foo () { return 0; }
int main () { return foo (); }
]])],
glib_cv_hasinline=yes
,
glib_cv_hasinline=no
,)
])
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([AC_LANG_SOURCE([[
#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([],[
@ -2906,26 +2834,6 @@ $glib_static_compilation
$glib_vacopy
#ifdef __cplusplus
#define G_HAVE_INLINE 1
#else /* !__cplusplus */
$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
@ -3272,23 +3180,10 @@ if test x$glib_cv_va_val_copy = xno; then
#define G_VA_COPY_AS_ARRAY 1"
fi
if test x$glib_cv_hasinline = xyes; then
glib_inline='#define G_HAVE_INLINE 1'
fi
if test x$glib_cv_has__inline = xyes; then
glib_inline="\$glib_inline
#define G_HAVE___INLINE 1"
fi
if test x$glib_cv_has__inline__ = xyes; then
glib_inline="\$glib_inline
#define G_HAVE___INLINE__ 1"
fi
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
g_have_sunstudio_visibility=$g_have_sunstudio_visibility

View File

@ -1850,16 +1850,15 @@
/**
* G_INLINE_FUNC:
*
* This macro is used to export function prototypes so they can be linked
* with an external version when no inlining is performed. The file which
* implements the functions should define %G_IMPLEMENTS_INLINES
* before including the headers which contain %G_INLINE_FUNC declarations.
* Since inlining is very compiler-dependent using these macros correctly
* is very difficult. Their use is strongly discouraged.
* This macro used to be used to conditionally define inline functions
* in a compatible way before this feature was supported in all
* compilers. These days, GLib requires inlining support from the
* compiler, so your GLib-using programs can safely assume that the
* "inline" keywork works properly.
*
* This macro is often mistaken for a replacement for the inline keyword;
* inline is already declared in a portable manner in the GLib headers
* and can be used normally.
* Never use this macro anymore. Just say "static inline".
*
* Deprecated: 2.48: Use "static inline" instead
*/
/**

View File

@ -47,6 +47,27 @@
#define G_GNUC_EXTENSION
#endif
/* Every compiler that we target supports inlining, but some of them may
* complain about it if we don't say "__inline". If we have C99, then
* we can use "inline" directly. Otherwise, we say "__inline" to avoid
* the warning.
*/
#define G_CAN_INLINE
#if !(__STDC_VERSION__ > 199900)
#undef inline
#define inline __inline
#endif
/* For historical reasons we need to continue to support those who
* define G_IMPLEMENT_INLINES to mean "don't implement this here".
*/
#ifdef G_IMPLEMENT_INLINES
# define G_INLINE_FUNC extern
# undef G_CAN_INLINE
#else
# define G_INLINE_FUNC static inline
#endif /* G_IMPLEMENT_INLINES */
/* Provide macros to feature the GCC function attribute.
*/
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)

View File

@ -47,41 +47,6 @@ G_BEGIN_DECLS
# endif /* va_list is a pointer */
#endif /* !G_VA_COPY */
/* 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'.
* 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.
*/
#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
# else /* !inline && !__inline__ && !__inline */
# define inline /* don't inline, then */
# endif
#endif
#ifdef G_IMPLEMENT_INLINES
# define G_INLINE_FUNC _GLIB_EXTERN
# undef G_CAN_INLINE
#elif defined (__GNUC__)
# define G_INLINE_FUNC static __inline __attribute__ ((unused))
#elif defined (G_CAN_INLINE)
# define G_INLINE_FUNC static inline
#else /* can't inline */
# define G_INLINE_FUNC _GLIB_EXTERN
#endif /* !G_INLINE_FUNC */
GLIB_AVAILABLE_IN_ALL
const gchar * g_get_user_name (void);
GLIB_AVAILABLE_IN_ALL