summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederic Peters <fpeters@entrouvert.com>2005-02-08 10:14:01 +0000
committerFrederic Peters <fpeters@entrouvert.com>2005-02-08 10:14:01 +0000
commiteb43346d79b1e2d3e3cc54874e118417ed794142 (patch)
tree9c7bad6e13ee7e386346b4aae8fd9ffbd73ee9d1
parent32bc5ad3616a474311060ecaa8552b1804c3fdb0 (diff)
downloadlasso-eb43346d79b1e2d3e3cc54874e118417ed794142.tar.gz
lasso-eb43346d79b1e2d3e3cc54874e118417ed794142.tar.xz
lasso-eb43346d79b1e2d3e3cc54874e118417ed794142.zip
detect when it is possible to use variadic macros and fall back to inline
functions when it is not the case.
-rw-r--r--configure.ac15
-rw-r--r--lasso/xml/private.h25
2 files changed, 36 insertions, 4 deletions
diff --git a/configure.ac b/configure.ac
index 2d6164a6..0865278e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -128,6 +128,21 @@ dnl Make sure we have an ANSI compiler
AM_C_PROTOTYPES
test "z$U" != "z" && AC_MSG_ERROR(Compiler not ANSI compliant)
+dnl Check for variadic macros
+AC_CACHE_CHECK([for variadic cpp macros],
+ [ac_cv_cpp_variadic_macros],
+ [CFLAGS="${CFLAGS_save}"
+ AC_TRY_COMPILE(
+ [#include <stdio.h>
+ #define a(b,c...) printf(b,##c)],
+ [a("foo");a("%s","bar");a("%s%s","baz","quux");],
+ ac_cv_cpp_variadic_macros=yes,
+ ac_cv_cpp_variadic_macros=no)])
+if test "x${ac_cv_cpp_variadic_macros}" != "xno"; then
+ AC_DEFINE(HAVE_VARIADIC_MACROS, 1, Support for variadic macros)
+fi
+
+
dnl ==========================================================================
dnl Version Super.Size.Me.L
dnl ==========================================================================
diff --git a/lasso/xml/private.h b/lasso/xml/private.h
index d3a73e3b..780ae019 100644
--- a/lasso/xml/private.h
+++ b/lasso/xml/private.h
@@ -119,23 +119,40 @@ void _debug(GLogLevelFlags level, const char *filename, int line,
int error_code(GLogLevelFlags level, int error, ...);
-#if defined LASSO_DEBUG && defined __GNUC__
+#if defined(LASSO_DEBUG) && defined(__GNUC__)
# define debug(format, args...) \
_debug(G_LOG_LEVEL_DEBUG, __FILE__, __LINE__,__FUNCTION__, format, ##args)
-#else
+#elif defined(HAVE_VARIADIC_MACROS)
# define debug(...) ;
+#else
+inline void debug(const char *format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ va_end(ap);
+}
#endif
#ifndef __FUNCTION__
# define __FUNCTION__ ""
#endif
-#if defined __GNUC__
+#if defined(__GNUC__)
# define message(level, format, args...) \
_debug(level, __FILE__, __LINE__, __FUNCTION__, format, ##args)
-#else
+#elif defined(HAVE_VARIADIC_MACROS)
# define message(level, ...) \
_debug(level, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
+#else
+inline void message(GLogLevelFlags level, const char *format, ...)
+{
+ va_list ap;
+ char s[1024];
+ va_start(ap, format);
+ vsnprintf(s, 1024, format, args);
+ va_end(ap);
+ _debug(level, __FILE__, __LINE__, __FUNCTION__, s);
+}
#endif
#define critical_error(rc) error_code(G_LOG_LEVEL_CRITICAL, rc)