Skip to content

Commit

Permalink
Cleanup __func__ detection
Browse files Browse the repository at this point in the history
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: libevent#644
  • Loading branch information
azat committed Aug 1, 2018
1 parent c3a6fe7 commit e85818d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 31 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions WIN32-Code/nmake/event2/event-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,6 @@
/* Version number of package */
#define EVENT__VERSION "2.2.0-alpha-dev"

/* 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
Expand Down
28 changes: 15 additions & 13 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 3 additions & 10 deletions event-config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -496,6 +486,9 @@
#define EVENT__inline @EVENT__inline@
#endif

#cmakedefine EVENT__HAVE___func__ 1
#cmakedefine EVENT__HAVE___FUNCTION__ 1

/* Define to `unsigned' if <sys/types.h> does not define. */
#define EVENT__size_t @EVENT__size_t@

Expand Down
10 changes: 8 additions & 2 deletions event_rpcgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1582,8 +1582,14 @@ def BodyPreamble(self, name, header_file):
'#include <event2/event.h>\n'
'#include <event2/buffer.h>\n'
'#include <event2/tag.h>\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'
)

Expand Down
12 changes: 10 additions & 2 deletions util-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down

0 comments on commit e85818d

Please sign in to comment.