[Freeciv-Dev] (PR#6254) configure check for C99 variadic macros
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Attached is a patch to provide a configure-time check for variadic
macros. HAVE_VARIADIC_MACROS is defined if the compilation of some test
code succeeds.
It also fixes freelog:
- Instead of __GNUC__ check HAVE_VARIADIC_MACROS
- Instead of gcc-style variadic macros use C99-style
- Instead of a static function (which gives lots of warnings during
compilation) make the non-macro form a standard function.
- Add fc__attribute tag to freelog() function form.
- General style cleanups.
jason
# Check for the presense of C99-style variadic macros:
#
# #define PRINTF(msg, ...) (printf(msg, __VA_ARGS__)
#
# if present, HAVE_VARIADIC_MACROS will be defined.
AC_DEFUN(FC_VARIADIC_MACROS,
[
dnl Check for variadic macros
AC_CACHE_CHECK([for C99 variadic macros macros],
[ac_cv_c99_variadic_macros],
[CFLAGS="${CFLAGS_save}"
AC_TRY_COMPILE(
[#include <stdio.h>
#define MSG(...) fprintf(stderr, __VA_ARGS__)
],
[MSG("foo");
MSG("%d", 1);
MSG("%s%d", "foo", 1);],
ac_cv_c99_variadic_macros=yes,
ac_cv_c99_variadic_macros=no)])
if test "x${ac_cv_c99_variadic_macros}" != "xno"; then
AC_DEFINE(HAVE_VARIADIC_MACROS, 1, Support for C99 variadic macros)
fi
])
? foo.c
? rc
? m4/variadic_macros.diff
Index: Makefile.am
===================================================================
RCS file: /home/freeciv/CVS/freeciv/Makefile.am,v
retrieving revision 1.33
diff -u -r1.33 Makefile.am
--- Makefile.am 2003/09/19 18:29:40 1.33
+++ Makefile.am 2003/09/23 15:27:07
@@ -91,6 +91,7 @@
m4/sdl-client.m4 \
m4/sdl.m4 \
m4/sound.m4 \
+ m4/variadic_macros.m4 \
m4/vsnprintf.m4 \
m4/win32-client.m4 \
m4/x.213 \
Index: configure.ac
===================================================================
RCS file: /home/freeciv/CVS/freeciv/configure.ac,v
retrieving revision 1.50
diff -u -r1.50 configure.ac
--- configure.ac 2003/07/31 19:18:40 1.50
+++ configure.ac 2003/09/23 15:27:07
@@ -263,6 +263,7 @@
fi
FC_DEBUG
+FC_VARIADIC_MACROS
if test "$CVS_DEPS" = "maybe"; then
dnl Should also check for gmake?
Index: configure.in
===================================================================
RCS file: /home/freeciv/CVS/freeciv/configure.in,v
retrieving revision 1.226
diff -u -r1.226 configure.in
--- configure.in 2003/07/31 19:18:40 1.226
+++ configure.in 2003/09/23 15:27:07
@@ -262,6 +262,7 @@
fi
FC_DEBUG
+FC_VARIADIC_MACROS
if test "$CVS_DEPS" = "maybe"; then
dnl Should also check for gmake?
Index: common/log.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/log.c,v
retrieving revision 1.43
diff -u -r1.43 log.c
--- common/log.c 2003/04/04 15:47:49 1.43
+++ common/log.c 2003/09/23 15:27:07
@@ -324,3 +324,24 @@
vreal_freelog(level, message, ap);
va_end(ap);
}
+
+/****************************************************************************
+ Function form of freelog(). This is freeciv's standard logging function.
+****************************************************************************/
+void freelog(int level, const char *message, ...)
+{
+ bool log_this;
+
+#ifdef DEBUG
+ /* FIXME: __FILE__ and __LINE__ will not work in this way. */
+ log_this = (level != LOG_DEBUG || logdebug_check(__FILE__, __LINE__));
+#else
+ log_this = (level != LOG_DEBUG);
+#endif
+ if (log_this) {
+ va_list args;
+ va_start(args, message);
+ vreal_freelog(level, message, args);
+ va_end(args);
+ }
+}
Index: common/log.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/log.h,v
retrieving revision 1.20
diff -u -r1.20 log.h
--- common/log.h 2002/10/29 18:50:06 1.20
+++ common/log.h 2003/09/23 15:27:07
@@ -87,39 +87,27 @@
#define logdebug_suppress_warning
#endif
-/* For GCC we use a variadic macro; for others we take
- the performance hit of a function to get variadic args:
-*/
-#ifdef __GNUC__
-#ifdef DEBUG
-#define freelog(level, args...) do { \
- if ((level) != LOG_DEBUG || logdebug_check(__FILE__, __LINE__)) { \
- real_freelog((level), args); \
- } \
-} while(FALSE)
+/* Use variadic macros if available; otherwise we take the performance
+ * hit of a function. */
+#ifdef HAVE_VARIADIC_MACROS
+# ifdef DEBUG
+# define freelog(level, ...) \
+ do { \
+ if ((level) != LOG_DEBUG || logdebug_check(__FILE__, __LINE__)) { \
+ real_freelog((level), __VA_ARGS__); \
+ } \
+ } while(FALSE)
+# else
+# define freelog(level, ...) \
+ do { \
+ if ((level) != LOG_DEBUG) { \
+ real_freelog((level), __VA_ARGS__); \
+ } \
+ } while(FALSE)
+# endif /* DEBUG */
#else
-#define freelog(level, args...) do { \
- if ((level) != LOG_DEBUG) { \
- real_freelog((level), args); } \
-} while(FALSE)
-#endif /* DEBUG */
-#else
-/* non-GCC: */
-static void freelog(int level, const char *message, ...)
-{
- bool log_this;
-#ifdef DEBUG
- log_this = (level != LOG_DEBUG || logdebug_check(__FILE__, __LINE__));
-#else
- log_this = (level != LOG_DEBUG);
-#endif
- if (log_this) {
- va_list args;
- va_start(args, message);
- vreal_freelog(level, message, args);
- va_end(args);
- }
-}
-#endif /* __GNUC__ */
+void freelog(int level, const char *message, ...)
+ fc__attribute((format (printf, 2, 3)));
+#endif /* HAVE_VARIADIC_MACROS */
#endif /* FC__LOG_H */
- [Freeciv-Dev] (PR#6254) configure check for C99 variadic macros,
Jason Short <=
|
|