Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2003:
[Freeciv-Dev] Re: (PR#6254) configure check for C99 variadic macros
Home

[Freeciv-Dev] Re: (PR#6254) configure check for C99 variadic macros

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#6254) configure check for C99 variadic macros
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 23 Sep 2003 12:41:15 -0700
Reply-to: rt@xxxxxxxxxxxxxx

Jason Short wrote:
> 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.

This is basically the same patch except now the variadic macros are 
required.  This allows some cleanup.

jason

# Check for the presense of C99-style variadic macros:
#
#  #define PRINTF(msg, ...) (printf(msg, __VA_ARGS__)
#
# These are required or configure will fail.

AC_DEFUN(FC_VARIADIC_MACROS,
[
  dnl Check for variadic macros
  AC_CACHE_CHECK([for C99 variadic macros],
    [ac_cv_c99_variadic_macros],
     [AC_TRY_COMPILE(
          [#include <stdio.h>
           #define MSG(...) fprintf(stderr, __VA_ARGS__)
          ],
          [MSG("foo");
           MSG("%s", "foo");
           MSG("%s%d", "foo", 1);],
          ac_cv_c99_variadic_macros=yes,
          ac_cv_c99_variadic_macros=no)])
  echo "${CFLAGS_save}"
  if test "x${ac_cv_c99_variadic_macros}" != "xyes"; then
    AC_MSG_ERROR([A compiler supporting C99 variadic macros is required])
  fi
])
? rc
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 19:40:08
@@ -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 19:40:09
@@ -263,6 +263,7 @@
 fi
 
 FC_DEBUG
+FC_VARIADIC_MACROS
 
 if test "$CVS_DEPS" = "maybe"; then
    dnl Should also check for gmake?
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 19:40:09
@@ -87,39 +87,20 @@
 #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) 
+#  define freelog(level, ...)                                             \
+  do {                                                                      \
+    if ((level) != LOG_DEBUG || logdebug_check(__FILE__, __LINE__)) {       \
+      real_freelog((level), __VA_ARGS__);                                   \
+    }                                                                       \
+  } while(FALSE)
 #else
-#define freelog(level, args...) do { \
-  if ((level) != LOG_DEBUG) { \
-    real_freelog((level), args); } \
-} while(FALSE) 
+#  define freelog(level, ...)                                             \
+  do {                                                                      \
+    if ((level) != LOG_DEBUG) {                                             \
+      real_freelog((level), __VA_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__ */
 
 #endif  /* FC__LOG_H */

[Prev in Thread] Current Thread [Next in Thread]