Skip to contentSkip to conversation

log: Use __func__ for function name

PATCH In review Mat Martineau 2 participants 3 messages Oct 23, 2018 – Oct 24, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 log: Use __func__ for function name

__FUNCTION__ and __PRETTY_FUNCTION__ are older gcc aliases for __func__. Switch to use __func__ in L_DEBUG_SYMBOL(), like l_log() already does. This resolves some compiler warnings in ELL headers when a program is built with compiler flags that are more strict than the maintainer-mode build.

---
 ell/log.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
ell/log.h +2 -2
index d21e2aa..a86705f 100644
@@ -66,12 +66,12 @@ struct l_debug_desc {
 #define L_DEBUG_SYMBOL(symbol, format, args...) do { \
 	static struct l_debug_desc symbol \
 	__attribute__((used, section("__ell_debug"), aligned(8))) = { \
-		.file = __FILE__, .func = __FUNCTION__, \
+		.file = __FILE__, .func = __func__, \
 		.flags = L_DEBUG_FLAG_DEFAULT, \
 	}; \
 	if (symbol.flags & L_DEBUG_FLAG_PRINT) \
 		l_log(L_LOG_DEBUG, "%s:%s() " format, __FILE__, \
-					__PRETTY_FUNCTION__ , ## args); \
+					__func__ , ## args); \
 } while (0)
 
 void l_debug_enable_full(const char *pattern,
Signature · 1 line
2.19.1
#1 lore raw

PATCH 2/2 util: Silence warnings from strict compiler settings

Use the standardized __func__ symbol instead of gcc's __PRETTY_FUNCTION__ alias, and add the __extension__ keyword for braced-groups within expressions. This allows use of more strict compiler settings in ELL-based programs.

---
 ell/util.c | 12 ++++++------
 ell/util.h |  6 +++---
 2 files changed, 9 insertions(+), 9 deletions(-)
ell/util.c +6 -6
index c021a83..4d74ced 100644
@@ -64,7 +64,7 @@ LIB_EXPORT void *l_malloc(size_t size)
 			return ptr;
 
 		fprintf(stderr, "%s:%s(): failed to allocate %zd bytes\n",
-					STRLOC, __PRETTY_FUNCTION__, size);
+					STRLOC, __func__, size);
 		abort();
 	}
 
@@ -94,7 +94,7 @@ LIB_EXPORT void *l_realloc(void *mem, size_t size)
 			return ptr;
 
 		fprintf(stderr, "%s:%s(): failed to re-allocate %zd bytes\n",
-					STRLOC, __PRETTY_FUNCTION__, size);
+					STRLOC, __func__, size);
 		abort();
 	} else
 		l_free(mem);
@@ -154,7 +154,7 @@ LIB_EXPORT char *l_strdup(const char *str)
 			return tmp;
 
 		fprintf(stderr, "%s:%s(): failed to allocate string\n",
-						STRLOC, __PRETTY_FUNCTION__);
+						STRLOC, __func__);
 		abort();
 	}
 
@@ -182,7 +182,7 @@ LIB_EXPORT char *l_strndup(const char *str, size_t max)
 			return tmp;
 
 		fprintf(stderr, "%s:%s(): failed to allocate string\n",
-						STRLOC, __PRETTY_FUNCTION__);
+						STRLOC, __func__);
 		abort();
 	}
 
@@ -208,7 +208,7 @@ LIB_EXPORT char *l_strdup_printf(const char *format, ...)
 
 	if (len < 0) {
 		fprintf(stderr, "%s:%s(): failed to allocate string\n",
-					STRLOC, __PRETTY_FUNCTION__);
+					STRLOC, __func__);
 		abort();
 
 		return NULL;
@@ -233,7 +233,7 @@ LIB_EXPORT char *l_strdup_vprintf(const char *format, va_list args)
 
 	if (len < 0) {
 		fprintf(stderr, "%s:%s(): failed to allocate string\n",
-					STRLOC, __PRETTY_FUNCTION__);
+					STRLOC, __func__);
 		abort();
 
 		return NULL;
ell/util.h +3 -3
index e42d751..7bfcbfa 100644
@@ -41,11 +41,11 @@ extern "C" {
 #define L_STRINGIFY(val) L_STRINGIFY_ARG(val)
 #define L_STRINGIFY_ARG(contents) #contents
 
-#define L_WARN_ON(condition) ({						\
+#define L_WARN_ON(condition) __extension__ ({				\
 		bool r = !!(condition);					\
 		if (unlikely(r))					\
 			l_warn("WARNING: %s:%s() condition %s failed",	\
-				__FILE__, __PRETTY_FUNCTION__,		\
+				__FILE__, __func__,			\
 				#condition);				\
 		unlikely(r);						\
 	})
@@ -56,7 +56,7 @@ extern "C" {
 #define L_PTR_TO_INT(p) ((int) ((intptr_t) (p)))
 #define L_INT_TO_PTR(u) ((void *) ((intptr_t) (u)))
 
-#define L_GET_UNALIGNED(ptr)			\
+#define L_GET_UNALIGNED(ptr) __extension__	\
 ({						\
 	struct __attribute__((packed)) {	\
 		typeof(*(ptr)) __v;		\
Signature · 1 line
2.19.1
#2 lore raw
In reply to Mat Martineau

Hi Mat,

Quoted 9 lines · Mat Martineau

__FUNCTION__ and __PRETTY_FUNCTION__ are older gcc aliases for __func__. Switch to use __func__ in L_DEBUG_SYMBOL(), like l_log() already does. This resolves some compiler warnings in ELL headers when a program is built with compiler flags that are more strict than the maintainer-mode build.

---
  ell/log.h | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

Both applied, thanks.

Regards,
-Denis