aboutsummaryrefslogtreecommitdiff
path: root/src/njs_assert.h
blob: d325613d7390d0fc36c83cc81cde5bd6544724c2 (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
/*
 * Copyright (C) Dmitry Volyntsev
 * Copyright (C) NGINX, Inc.
 */

#ifndef _NJS_ASSERT_H_INCLUDED_
#define _NJS_ASSERT_H_INCLUDED_

#if (NJS_DEBUG)

#define njs_assert(condition)                                                 \
    do {                                                                      \
        if (!(condition)) {                                                   \
            njs_stderror("Assertion \"%s\" failed at %s:%d\n", #condition,    \
                         __FILE__, __LINE__);                                 \
            abort();                                                          \
        }                                                                     \
    } while (0)

#define njs_assert_msg(condition, fmt, ...)                                   \
    do {                                                                      \
        if (!(condition)) {                                                   \
            njs_stderror(fmt, ##__VA_ARGS__);                                 \
            njs_stderror(" at %s:%d\n", __FILE__, __LINE__);                  \
            abort();                                                          \
        }                                                                     \
    } while (0)

#else

#define njs_assert(condition)
#define njs_assert_msg(condition, fmt, ...)

#endif

#endif /* _NJS_ASSERT_H_INCLUDED_ */