xref: /freebsd/contrib/sendmail/include/sm/assert.h (revision cab6a39d7b343596a5823e65c0f7b426551ec22d)
1 /*
2  * Copyright (c) 2000-2001 Proofpoint, Inc. and its suppliers.
3  *	All rights reserved.
4  *
5  * By using this file, you agree to the terms and conditions set
6  * forth in the LICENSE file which can be found at the top level of
7  * the sendmail distribution.
8  *
9  *	$Id: assert.h,v 1.11 2013-11-22 20:51:31 ca Exp $
10  */
11 
12 /*
13 **  libsm abnormal program termination and assertion checking
14 **  See libsm/assert.html for documentation.
15 */
16 
17 #ifndef SM_ASSERT_H
18 # define SM_ASSERT_H
19 
20 # include <sm/gen.h>
21 # include <sm/debug.h>
22 
23 /*
24 **  abnormal program termination
25 */
26 
27 typedef void (*SM_ABORT_HANDLER_T) __P((const char *, int, const char *));
28 
29 extern SM_DEAD(void
30 sm_abort_at __P((
31 	const char *,
32 	int,
33 	const char *)));
34 
35 extern void
36 sm_abort_sethandler __P((
37 	SM_ABORT_HANDLER_T));
38 
39 extern SM_DEAD(void PRINTFLIKE(1, 2)
40 sm_abort __P((
41 	char *,
42 	...)));
43 
44 /*
45 **  assertion checking
46 */
47 
48 # ifndef SM_CHECK_ALL
49 #  define SM_CHECK_ALL		1
50 # endif
51 
52 # ifndef SM_CHECK_REQUIRE
53 #  define SM_CHECK_REQUIRE	SM_CHECK_ALL
54 # endif
55 
56 # ifndef SM_CHECK_ENSURE
57 #  define SM_CHECK_ENSURE	SM_CHECK_ALL
58 # endif
59 
60 # ifndef SM_CHECK_ASSERT
61 #  define SM_CHECK_ASSERT	SM_CHECK_ALL
62 # endif
63 
64 # if SM_CHECK_REQUIRE
65 #  if defined(__STDC__) || defined(__cplusplus)
66 #   define SM_REQUIRE(cond) \
67 	((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
68 	"SM_REQUIRE(" #cond ") failed"), 0)))
69 #  else /* defined(__STDC__) || defined(__cplusplus) */
70 #   define SM_REQUIRE(cond) \
71 	((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
72 	"SM_REQUIRE(cond) failed"), 0)))
73 #  endif /* defined(__STDC__) || defined(__cplusplus) */
74 # else /* SM_CHECK_REQUIRE */
75 #  define SM_REQUIRE(cond)	((void) 0)
76 # endif /* SM_CHECK_REQUIRE */
77 
78 # define SM_REQUIRE_ISA(obj, magic) \
79 		SM_REQUIRE((obj) != NULL && (obj)->sm_magic == (magic))
80 
81 # if SM_CHECK_ENSURE
82 #  if defined(__STDC__) || defined(__cplusplus)
83 #   define SM_ENSURE(cond) \
84 	((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
85 	"SM_ENSURE(" #cond ") failed"), 0)))
86 #  else /* defined(__STDC__) || defined(__cplusplus) */
87 #   define SM_ENSURE(cond) \
88 	((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
89 	"SM_ENSURE(cond) failed"), 0)))
90 #  endif /* defined(__STDC__) || defined(__cplusplus) */
91 # else /* SM_CHECK_ENSURE */
92 #  define SM_ENSURE(cond)	((void) 0)
93 # endif /* SM_CHECK_ENSURE */
94 
95 # if SM_CHECK_ASSERT
96 #  if defined(__STDC__) || defined(__cplusplus)
97 #   define SM_ASSERT(cond) \
98 	((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
99 	"SM_ASSERT(" #cond ") failed"), 0)))
100 #  else /* defined(__STDC__) || defined(__cplusplus) */
101 #   define SM_ASSERT(cond) \
102 	((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
103 	"SM_ASSERT(cond) failed"), 0)))
104 #  endif /* defined(__STDC__) || defined(__cplusplus) */
105 # else /* SM_CHECK_ASSERT */
106 #  define SM_ASSERT(cond)	((void) 0)
107 # endif /* SM_CHECK_ASSERT */
108 
109 extern SM_DEBUG_T SmExpensiveRequire;
110 extern SM_DEBUG_T SmExpensiveEnsure;
111 extern SM_DEBUG_T SmExpensiveAssert;
112 
113 #endif /* ! SM_ASSERT_H */
114