Browse Source

[core] log_failed_assert() __attribute__((cold))

personal/stbuehler/fix-fdevent
Glenn Strauss 3 years ago
parent
commit
b192231392
  1. 7
      src/buffer.h
  2. 39
      src/first.h

7
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");

39
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

Loading…
Cancel
Save