[or-cvs] ugly macros to make log_fn play nice on non-GCC compilers.

Nick Mathewson nickm at seul.org
Mon Nov 15 21:18:10 UTC 2004


Update of /home/or/cvsroot/tor/src/common
In directory moria.mit.edu:/tmp/cvs-serv8300/src/common

Modified Files:
	log.c log.h 
Log Message:
ugly macros to make log_fn play nice on non-GCC compilers.

Index: log.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/log.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -d -r1.67 -r1.68
--- log.c	14 Nov 2004 17:21:32 -0000	1.67
+++ log.c	15 Nov 2004 21:18:07 -0000	1.68
@@ -203,7 +203,9 @@
   va_end(ap);
 }
 
+
 /** Output a message to the log, prefixed with a function name <b>fn</b>. */
+#ifdef __GNUC__
 void _log_fn(int severity, const char *fn, const char *format, ...)
 {
   va_list ap;
@@ -211,6 +213,17 @@
   logv(severity, fn, format, ap);
   va_end(ap);
 }
+#else
+const char *_log_fn_function_name=NULL;
+void _log_fn(int severity, const char *format, ...)
+{
+  va_list ap;
+  va_start(ap,format);
+  logv(severity, _log_fn_function_name, format, ap);
+  va_end(ap);
+  _log_fn_function_name = NULL;
+}
+#endif
 
 /** Close all open log files. */
 void close_logs()

Index: log.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/log.h,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- log.h	9 Nov 2004 20:04:00 -0000	1.33
+++ log.h	15 Nov 2004 21:18:07 -0000	1.34
@@ -81,7 +81,14 @@
 #define log_fn(severity, args...) \
   _log_fn(severity, __PRETTY_FUNCTION__, args)
 #else
-#define log_fn _log
+/* We don't have GCC's varargs macros, so use a global variable to pass the
+ * function name to log_fn */
+extern const char *_log_fn_function_name;
+void _log_fn(int severity, const char *format, ...);
+/* We abuse the comma operator here, since we can't use the standard
+ * do {...} while(0) trick to wrap this macro, since the macro can't take
+ * arguments. */
+#define log_fn (_log_fn_function_name=__FUNCTION__),_log_fn
 #endif
 #define log _log /* hack it so we don't conflict with log() as much */
 



More information about the tor-commits mailing list