Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / ntp / dist / include / ntp_assert.h
blob6f4eb136bf2e602aff8e6a1d7c23fc370c1e21ee
1 /* $NetBSD$ */
3 /*
4 * ntp_assert.h - design by contract stuff
6 * example:
8 * int foo(char *a) {
9 * int result;
10 * int value;
12 * NTP_REQUIRE(a != NULL);
13 * ...
14 * bar(&value);
15 * NTP_INSIST(value > 2);
16 * ...
18 * NTP_ENSURE(result != 12);
19 * return result;
20 * }
22 * open question: when would we use NTP_INVARIANT()?
25 #ifndef NTP_ASSERT_H
26 #define NTP_ASSERT_H
28 # ifdef CALYSTO
30 extern void calysto_assume(unsigned char cnd); /* assume this always holds */
31 extern void calysto_assert(unsigned char cnd); /* check whether this holds */
32 #define NTP_REQUIRE(x) calysto_assert(x)
33 #define NTP_INSIST(x) calysto_assume(x) /* DLH calysto_assert()? */
34 #define NTP_INVARIANT(x) calysto_assume(x)
35 #define NTP_ENSURE(x) calysto_assert(x)
37 # elif defined(__COVERITY__)
40 * Coverity has special knowledge that assert(x) terminates the process
41 * if x is not true. Rather than teach it about our assertion macros,
42 * just use the one it knows about for Coverity Prevent scans. This
43 * means our assertion code (and ISC's) escapes Coverity analysis, but
44 * that seems to be a reasonable trade-off.
47 #define NTP_REQUIRE(x) assert(x)
48 #define NTP_INSIST(x) assert(x)
49 #define NTP_INVARIANT(x) assert(x)
50 #define NTP_ENSURE(x) assert(x)
52 # else /* neither Coverity nor Calysto */
54 #include "isc/assertions.h"
56 #define NTP_REQUIRE(x) ISC_REQUIRE(x)
57 #define NTP_INSIST(x) ISC_INSIST(x)
58 #define NTP_INVARIANT(x) ISC_INVARIANT(x)
59 #define NTP_ENSURE(x) ISC_ENSURE(x)
61 # endif /* neither Coverity nor Calysto */
62 #endif /* NTP_ASSERT_H */