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)
This commit is contained in:
Azat Khuzhin 2018-06-19 10:15:08 +03:00 committed by Azat Khuzhin
parent 21bfaa702f
commit b3af7bdde3
No known key found for this signature in database
GPG Key ID: B86086848EF8686D
6 changed files with 41 additions and 31 deletions

View File

@ -421,6 +421,10 @@ else()
set(EVENT__inline) set(EVENT__inline)
endif() 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_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(CTL_KERN sys/sysctl.h EVENT__HAVE_DECL_CTL_KERN)
CHECK_CONST_EXISTS(KERN_ARND sys/sysctl.h EVENT__HAVE_DECL_KERN_ARND) CHECK_CONST_EXISTS(KERN_ARND sys/sysctl.h EVENT__HAVE_DECL_KERN_ARND)

View File

@ -337,9 +337,6 @@
/* Version number of package */ /* Version number of package */
#define EVENT__VERSION "2.1.8-stable" #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 /* 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. */ calls it, or to nothing if 'inline' is not supported under any name. */
#define EVENT__inline __inline #define EVENT__inline __inline

View File

@ -739,21 +739,23 @@ AC_TRY_COMPILE([
[Define to unsigned int if you dont have it])] [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_MSG_CHECKING([whether our compiler supports __func__])
AC_TRY_COMPILE([], AC_TRY_COMPILE([],
[ const char *cp = __func__; ], [ const char *cp = __func__; ],
AC_MSG_RESULT([yes]), [ AC_DEFINE(HAVE___func__, 1, [Define to 1 if compiler have __func__])
AC_MSG_RESULT([yes])
],
AC_MSG_RESULT([no]) AC_MSG_RESULT([no])
)
AC_MSG_CHECKING([whether our compiler supports __FUNCTION__]) AC_MSG_CHECKING([whether our compiler supports __FUNCTION__])
AC_TRY_COMPILE([], AC_TRY_COMPILE([],
[ const char *cp = __FUNCTION__; ], [ const char *cp = __FUNCTION__; ],
[ AC_DEFINE(HAVE___FUNCTION__, 1, [Define to 1 if compiler have __FUNCTION__])
AC_MSG_RESULT([yes]) AC_MSG_RESULT([yes])
AC_DEFINE(__func__, __FUNCTION__, ],
[Define to appropriate substitue if compiler doesnt have __func__]),
AC_MSG_RESULT([no]) AC_MSG_RESULT([no])
AC_DEFINE(__func__, __FILE__, )
[Define to appropriate substitue if compiler doesnt have __func__])))
# check if we can compile with pthreads # check if we can compile with pthreads
have_pthreads=no have_pthreads=no

View File

@ -470,16 +470,6 @@
/* The size of 'void *', as computer by sizeof */ /* The size of 'void *', as computer by sizeof */
#define EVENT__SIZEOF_VOID_P @EVENT__SIZEOF_VOID_P@ #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 /* 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. */ calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus #ifndef __cplusplus
@ -496,6 +486,9 @@
#define EVENT__inline @EVENT__inline@ #define EVENT__inline @EVENT__inline@
#endif #endif
#cmakedefine EVENT__HAVE___func__ 1
#cmakedefine EVENT__HAVE___FUNCTION__ 1
/* Define to `unsigned' if <sys/types.h> does not define. */ /* Define to `unsigned' if <sys/types.h> does not define. */
#define EVENT__size_t @EVENT__size_t@ #define EVENT__size_t @EVENT__size_t@

View File

@ -1582,8 +1582,14 @@ class CCodeGenerator:
'#include <event2/event.h>\n' '#include <event2/event.h>\n'
'#include <event2/buffer.h>\n' '#include <event2/buffer.h>\n'
'#include <event2/tag.h>\n\n' '#include <event2/tag.h>\n\n'
'#if defined(EVENT____func__) && !defined(__func__)\n' '#if defined(EVENT__HAVE___func__)\n'
'#define __func__ EVENT____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' '#endif\n\n'
) )

View File

@ -68,8 +68,16 @@ extern "C" {
#ifdef EVENT__inline #ifdef EVENT__inline
#define inline EVENT__inline #define inline EVENT__inline
#endif #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 #endif
/* A good no-op to use in macro definitions. */ /* A good no-op to use in macro definitions. */