summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2006-03-13 00:25:36 +0000
committerNick Mathewson <nickm@torproject.org>2006-03-13 00:25:36 +0000
commit0c132ee2a1be2a4f6ce081bc883d88dcd810e8b8 (patch)
treeb65b1a626cb3486ef8a3a3078760e9460223efb0
parentbd8ffccae7e1bb4030f9ca5e6dd9c8918256de75 (diff)
downloadtor-0c132ee2a1be2a4f6ce081bc883d88dcd810e8b8.tar.gz
tor-0c132ee2a1be2a4f6ce081bc883d88dcd810e8b8.zip
Instead of listing a set of compilers that prefers __func__ to __FUNCTION__, use autoconf. Also, prefer __func__ in our own code: __func__ is a C99 standard, whereas __FUNCTION__ is not. [Fixes bug 254.]
svn:r6144
-rw-r--r--configure.in39
-rw-r--r--src/common/compat.h25
-rw-r--r--src/common/log.h24
-rw-r--r--src/common/util.h4
4 files changed, 73 insertions, 19 deletions
diff --git a/configure.in b/configure.in
index ed8f94130e..c744049803 100644
--- a/configure.in
+++ b/configure.in
@@ -491,6 +491,45 @@ AC_CHECK_FUNC(gethostbyname_r, [
CFLAGS=$OLD_CFLAGS
])
+AC_CACHE_CHECK([whether the C compiler supports __func__],
+ ac_cv_have_func_macro,
+ AC_COMPILE_IFELSE([
+#include <stdio.h>
+int main(int c, char **v) { puts(__func__); }],
+ ac_cv_have_func_macro=yes,
+ ac_cv_have_func_macro=no))
+
+AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
+ ac_cv_have_FUNC_macro,
+ AC_COMPILE_IFELSE([
+#include <stdio.h>
+int main(int c, char **v) { puts(__FUNC__); }],
+ ac_cv_have_FUNC_macro=yes,
+ ac_cv_have_FUNC_macro=no))
+
+AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
+ ac_cv_have_FUNCTION_macro,
+ AC_COMPILE_IFELSE([
+#include <stdio.h>
+int main(int c, char **v) { puts(__FUNCTION__); }],
+ ac_cv_have_FUNCTION_macro=yes,
+ ac_cv_have_FUNCTION_macro=no))
+
+if test $ac_cv_have_func_macro = 'yes'; then
+ AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
+fi
+
+
+if test $ac_cv_have_FUNC_macro = 'yes'; then
+ AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
+fi
+
+if test $ac_cv_have_FUNCTION_macro = 'yes'; then
+ AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
+ [Defined if the compiler supports __FUNCTION__])
+fi
+
+
# $prefix stores the value of the --prefix command line option, or
# NONE if the option wasn't set. In the case that it wasn't set, make
# it be the default, so that we can use it to expand directories now.
diff --git a/src/common/compat.h b/src/common/compat.h
index 417b40c136..08b3f76466 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -52,14 +52,29 @@
#define INLINE inline
#endif
-/* Windows compilers before VC7 don't have __FUNCTION__. */
-#if defined(_MSC_VER) && _MSC_VER < 1300
-#define __FUNCTION__ "???"
+/* Try to get a reasonable __func__ substitute in place. */
+#if defined(_MSC_VER)
+/* MSVC compilers before VC7 don't have __func__ at all; later ones call it
+ * __FUNCTION__. */
+#if _MSC_VER < 1300
+#define __func__ "???"
+#else
+#define __func__ __FUNCTION__
#endif
-#if defined(__sgi) && !defined(__GNUC__) && defined(__c99)
-#define __FUNCTION__ __func__
+#else
+/* For platforms where autoconf works, make sure __func__ is defined
+ * sanely. */
+#ifndef HAVE_MACRO__func__
+#ifdef HAVE_MACRO__FUNCTION__
+#define __func__ __FUNCTION__
+#elif HAVE_MACRO__FUNC__
+#define __func__ __FUNC__
+#else
+#define __func__ "???"
#endif
+#endif /* ifndef MAVE_MACRO__func__ */
+#endif /* if(not windows) */
/* ===== String compatibility */
#ifdef MS_WINDOWS
diff --git a/src/common/log.h b/src/common/log.h
index cf2f727f5f..1b4c96e8fa 100644
--- a/src/common/log.h
+++ b/src/common/log.h
@@ -149,7 +149,7 @@ void _log_warn(uint32_t domain, const char *format, ...);
void _log_err(uint32_t domain, const char *format, ...);
#if defined(_MSC_VER) && _MSC_VER < 1300
-/* MSVC 6 and earlier don't have __FUNCTION__, or even __LINE__. */
+/* MSVC 6 and earlier don't have __func__, or even __LINE__. */
#define log_fn _log_fn
#define log_debug _log_debug
#define log_info _log_info
@@ -170,18 +170,18 @@ extern const char *_log_fn_function_name;
/* 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
-#define log_debug (_log_fn_function_name=__FUNCTION__),_log_debug
-#define log_info (_log_fn_function_name=__FUNCTION__),_log_info
-#define log_notice (_log_fn_function_name=__FUNCTION__),_log_notice
-#define log_warn (_log_fn_function_name=__FUNCTION__),_log_warn
-#define log_err (_log_fn_function_name=__FUNCTION__),_log_err
+#define log_fn (_log_fn_function_name=__func__),_log_fn
+#define log_debug (_log_fn_function_name=__func__),_log_debug
+#define log_info (_log_fn_function_name=__func__),_log_info
+#define log_notice (_log_fn_function_name=__func__),_log_notice
+#define log_warn (_log_fn_function_name=__func__),_log_warn
+#define log_err (_log_fn_function_name=__func__),_log_err
/*
-#define debug (_log_fn_function_name=__FUNCTION__),_debug
-#define info (_log_fn_function_name=__FUNCTION__),_info
-#define notice (_log_fn_function_name=__FUNCTION__),_notice
-#define warn (_log_fn_function_name=__FUNCTION__),_warn
-#define err (_log_fn_function_name=__FUNCTION__),_err
+#define debug (_log_fn_function_name=__func__),_debug
+#define info (_log_fn_function_name=__func__),_info
+#define notice (_log_fn_function_name=__func__),_notice
+#define warn (_log_fn_function_name=__func__),_warn
+#define err (_log_fn_function_name=__func__),_err
*/
#endif
diff --git a/src/common/util.h b/src/common/util.h
index bed4f16c59..cdcd64f6b4 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -41,9 +41,9 @@
#define tor_assert(expr) do { \
if (!(expr)) { \
log(LOG_ERR, LD_BUG, "%s:%d: %s: Assertion %s failed; aborting.", \
- _SHORT_FILE_, __LINE__, __FUNCTION__, #expr); \
+ _SHORT_FILE_, __LINE__, __func__, #expr); \
fprintf(stderr,"%s:%d %s: Assertion %s failed; aborting.\n", \
- _SHORT_FILE_, __LINE__, __FUNCTION__, #expr); \
+ _SHORT_FILE_, __LINE__, __func__, #expr); \
abort(); \
} } while (0)
#endif