summaryrefslogtreecommitdiff
path: root/vere/pkg/noun/error.h
blob: 57932bf4c44073da110f70c88b8a91d4c6d57f25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/// @file

#ifndef U3_ERROR_H
#define U3_ERROR_H

#include "manage.h"

/* Assert.  Good to capture.

   TODO: determine which u3_assert calls can rather call c3_dessert, i.e. in
   public releases, which calls to u3_assert should abort and which should
   no-op? If the latter, is the assert useful inter-development to validate
   conditions we might accidentally break or not useful at all?
*/

#if defined(ASAN_ENABLED) && defined(__clang__)
# define u3_assert(x)                       \
    do {                                    \
      if (!(x)) {                           \
        u3m_bail(c3__oops);                 \
        abort();                            \
      }                                     \
    } while(0)
#else
# define u3_assert(x)                       \
    do {                                    \
      if (!(x)) {                           \
        fflush(stderr);                     \
        fprintf(stderr, "\rAssertion '%s' " \
                "failed in %s:%d\r\n",      \
                #x, __FILE__, __LINE__);    \
        u3m_bail(c3__oops);                 \
        abort();                            \
      }                                     \
    } while(0)
#endif /* if defined(ASAN_ENABLED) && defined(__clang__) */

#endif /* ifndef U3_ERROR_H */