From: Azat Khuzhin Date: Tue, 19 Jun 2018 07:15:08 +0000 (+0300) Subject: Cleanup __func__ detection X-Git-Tag: release-2.1.9-beta^2~98 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b3af7bdde3ec25a045edcd4090483d470f421905;p=libevent Cleanup __func__ detection First of all __func__ is not a macro, it is char[] array, so the code that we had before in cmake, was incorrect, i.e.: #if defined (__func__) #define EVENT____func__ __func__ #elif defined(__FUNCTION__) #define EVENT____func__ __FUNCTION__ #else #define EVENT____func__ __FILE__ #endif So just detect do we have __func__/__FUNCTION__ in configure/cmake before build and define EVENT__HAVE___func__/EVENT__HAVE___FUNCTION__ to use the later to choose which should be used as a __func__ (if it is not presented). Closes: #644 (cherry picked from commit e85818d24850540d220e6d7bc0a30653ba2135f2) --- diff --git a/CMakeLists.txt b/CMakeLists.txt index c45e61e4..e1631602 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -412,7 +412,7 @@ endif() check_function_keywords("inline" "__inline" "__inline__") if (HAVE_INLINE) - set (EVENT__inline inline) + set(EVENT__inline inline) elseif (HAVE___INLINE) set(EVENT__inline __inline) elseif(HAVE___INLINE__) @@ -421,6 +421,10 @@ else() set(EVENT__inline) endif() +# __func__/__FUNCTION__ is not a macros in general +CHECK_SYMBOL_EXISTS("__func__" "" EVENT__HAVE___func__) +CHECK_SYMBOL_EXISTS("__FUNCTION__" "" EVENT__HAVE___FUNCTION__) + CHECK_SYMBOL_EXISTS(TAILQ_FOREACH sys/queue.h EVENT__HAVE_TAILQFOREACH) CHECK_CONST_EXISTS(CTL_KERN sys/sysctl.h EVENT__HAVE_DECL_CTL_KERN) CHECK_CONST_EXISTS(KERN_ARND sys/sysctl.h EVENT__HAVE_DECL_KERN_ARND) diff --git a/WIN32-Code/nmake/event2/event-config.h b/WIN32-Code/nmake/event2/event-config.h index af809398..6080f5ae 100644 --- a/WIN32-Code/nmake/event2/event-config.h +++ b/WIN32-Code/nmake/event2/event-config.h @@ -337,9 +337,6 @@ /* Version number of package */ #define EVENT__VERSION "2.1.8-stable" -/* Define to appropriate substitue if compiler doesnt have __func__ */ -#define EVENT____func__ __FUNCTION__ - /* Define to `__inline__' or `__inline' if that's what the C compiler calls it, or to nothing if 'inline' is not supported under any name. */ #define EVENT__inline __inline diff --git a/configure.ac b/configure.ac index d28c5918..fe4b7325 100644 --- a/configure.ac +++ b/configure.ac @@ -739,21 +739,23 @@ AC_TRY_COMPILE([ [Define to unsigned int if you dont have it])] ) +# __func__/__FUNCTION__ is not a macros in general AC_MSG_CHECKING([whether our compiler supports __func__]) AC_TRY_COMPILE([], - [ const char *cp = __func__; ], - AC_MSG_RESULT([yes]), - AC_MSG_RESULT([no]) - AC_MSG_CHECKING([whether our compiler supports __FUNCTION__]) - AC_TRY_COMPILE([], - [ const char *cp = __FUNCTION__; ], - AC_MSG_RESULT([yes]) - AC_DEFINE(__func__, __FUNCTION__, - [Define to appropriate substitue if compiler doesnt have __func__]), - AC_MSG_RESULT([no]) - AC_DEFINE(__func__, __FILE__, - [Define to appropriate substitue if compiler doesnt have __func__]))) - + [ const char *cp = __func__; ], + [ AC_DEFINE(HAVE___func__, 1, [Define to 1 if compiler have __func__]) + AC_MSG_RESULT([yes]) + ], + AC_MSG_RESULT([no]) +) +AC_MSG_CHECKING([whether our compiler supports __FUNCTION__]) +AC_TRY_COMPILE([], + [ const char *cp = __FUNCTION__; ], + [ AC_DEFINE(HAVE___FUNCTION__, 1, [Define to 1 if compiler have __FUNCTION__]) + AC_MSG_RESULT([yes]) + ], + AC_MSG_RESULT([no]) +) # check if we can compile with pthreads have_pthreads=no diff --git a/event-config.h.cmake b/event-config.h.cmake index 6cfbb953..3f8a9b59 100644 --- a/event-config.h.cmake +++ b/event-config.h.cmake @@ -470,16 +470,6 @@ /* The size of 'void *', as computer by sizeof */ #define EVENT__SIZEOF_VOID_P @EVENT__SIZEOF_VOID_P@ -/* set an alias for whatever __func__ __FUNCTION__ is, what sillyness */ -#if defined (__func__) -#define EVENT____func__ __func__ -#elif defined(__FUNCTION__) -#define EVENT____func__ __FUNCTION__ -#else -#define EVENT____func__ __FILE__ -#endif - - /* Define to `__inline__' or `__inline' if that's what the C compiler calls it, or to nothing if 'inline' is not supported under any name. */ #ifndef __cplusplus @@ -496,6 +486,9 @@ #define EVENT__inline @EVENT__inline@ #endif +#cmakedefine EVENT__HAVE___func__ 1 +#cmakedefine EVENT__HAVE___FUNCTION__ 1 + /* Define to `unsigned' if does not define. */ #define EVENT__size_t @EVENT__size_t@ diff --git a/event_rpcgen.py b/event_rpcgen.py index 2004090a..0911ca25 100755 --- a/event_rpcgen.py +++ b/event_rpcgen.py @@ -1582,8 +1582,14 @@ class CCodeGenerator: '#include \n' '#include \n' '#include \n\n' - '#if defined(EVENT____func__) && !defined(__func__)\n' - '#define __func__ EVENT____func__\n' + '#if defined(EVENT__HAVE___func__)\n' + '# ifndef __func__\n' + '# define __func__ __func__\n' + '# endif\n' + '#elif defined(EVENT__HAVE___FUNCTION__)\n' + '# define __func__ __FUNCTION__\n' + '#else\n' + '# define __func__ __FILE__\n' '#endif\n\n' ) diff --git a/util-internal.h b/util-internal.h index 507dceb7..fe416409 100644 --- a/util-internal.h +++ b/util-internal.h @@ -68,8 +68,16 @@ extern "C" { #ifdef EVENT__inline #define inline EVENT__inline #endif -#if defined(EVENT____func__) && !defined(__func__) -#define __func__ EVENT____func__ + +/* Define to appropriate substitute if compiler doesnt have __func__ */ +#if defined(EVENT__HAVE___func__) +# ifndef __func__ +# define __func__ __func__ +# endif +#elif defined(EVENT__HAVE___FUNCTION__) +# define __func__ __FUNCTION__ +#else +# define __func__ __FILE__ #endif /* A good no-op to use in macro definitions. */