diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2018-09-23 17:42:28 -0400 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2018-09-23 18:01:58 -0400 |
commit | b192231392e1d63f27880f1de9ef0d82253250a3 (patch) | |
tree | 7ab3d0c623a10803bf84208649a38412ae9ab8e2 | |
parent | 2dbcfc926604df95bb8ba7d6a8cfee96a2fcfefd (diff) | |
download | lighttpd-git-b192231392e1d63f27880f1de9ef0d82253250a3.tar.gz |
[core] log_failed_assert() __attribute__((cold))
-rw-r--r-- | src/buffer.h | 7 | ||||
-rw-r--r-- | src/first.h | 39 |
2 files changed, 41 insertions, 5 deletions
diff --git a/src/buffer.h b/src/buffer.h index 21a0cd63..51dd119c 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -173,12 +173,9 @@ static inline void buffer_append_slash(buffer *b); /* append '/' no non-empty st #define CONST_BUF_LEN(x) ((x) ? (x)->ptr : NULL), buffer_string_length(x) -#ifdef __GNUC__ -# define LI_NORETURN __attribute__((noreturn)) -#else -# define LI_NORETURN -#endif +#define LI_NORETURN __attribute_noreturn__ +__attribute_cold__ void log_failed_assert(const char *filename, unsigned int line, const char *msg) LI_NORETURN; #define force_assert(x) do { if (!(x)) log_failed_assert(__FILE__, __LINE__, "assertion failed: " #x); } while(0) #define SEGFAULT() log_failed_assert(__FILE__, __LINE__, "aborted"); diff --git a/src/first.h b/src/first.h index 33e52cb7..38c25929 100644 --- a/src/first.h +++ b/src/first.h @@ -55,4 +55,43 @@ #define UNUSED(x) ( (void)(x) ) + +#ifndef __has_attribute /* clang */ +#define __has_attribute(x) 0 +#endif + +#ifdef __GNUC__ +#ifndef __GNUC_PREREQ +# ifdef __GNUC_PREREQ__ +# define __GNUC_PREREQ __GNUC_PREREQ__ +# elif defined __GNUC__ && defined __GNUC_MINOR__ +# define __GNUC_PREREQ(maj, min) \ + ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) +# else +# define __GNUC_PREREQ(maj, min) 0 +# endif +#endif +#else +#define __GNUC_PREREQ(maj,min) 0 +#endif + +#ifndef __attribute_cold__ +#if __has_attribute(cold) \ + || __GNUC_PREREQ(4,3) +#define __attribute_cold__ __attribute__((__cold__)) +#else +#define __attribute_cold__ +#endif +#endif + +#ifndef __attribute_noreturn__ +#if __has_attribute(noreturn) \ + || __GNUC_PREREQ(2,5) +#define __attribute_noreturn__ __attribute__((__noreturn__)) +#else +#define __attribute_noreturn__ +#endif +#endif + + #endif |