xref: /titanic_50/usr/src/cmd/sendmail/include/sm/assert.h (revision d7ddd43c70ebe97a1118be9f663a54d0d1d89fe6)
1 /*
2  * Copyright (c) 2000-2001 Sendmail, 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.10 2001/06/07 20:04:53 ca Exp $
10  */
11 
12 #pragma ident	"%Z%%M%	%I%	%E% SMI"
13 
14 /*
15 **  libsm abnormal program termination and assertion checking
16 **  See libsm/assert.html for documentation.
17 */
18 
19 #ifndef SM_ASSERT_H
20 # define SM_ASSERT_H
21 
22 # include <sm/gen.h>
23 # include <sm/debug.h>
24 
25 /*
26 **  abnormal program termination
27 */
28 
29 typedef void (*SM_ABORT_HANDLER_T) __P((const char *, int, const char *));
30 
31 extern SM_DEAD(void
32 sm_abort_at __P((
33 	const char *,
34 	int,
35 	const char *)));
36 
37 extern void
38 sm_abort_sethandler __P((
39 	SM_ABORT_HANDLER_T));
40 
41 extern SM_DEAD(void PRINTFLIKE(1, 2)
42 sm_abort __P((
43 	char *,
44 	...)));
45 
46 /*
47 **  assertion checking
48 */
49 
50 # ifndef SM_CHECK_ALL
51 #  define SM_CHECK_ALL		1
52 # endif /* ! SM_CHECK_ALL */
53 
54 # ifndef SM_CHECK_REQUIRE
55 #  define SM_CHECK_REQUIRE	SM_CHECK_ALL
56 # endif /* ! SM_CHECK_REQUIRE */
57 
58 # ifndef SM_CHECK_ENSURE
59 #  define SM_CHECK_ENSURE	SM_CHECK_ALL
60 # endif /* ! SM_CHECK_ENSURE */
61 
62 # ifndef SM_CHECK_ASSERT
63 #  define SM_CHECK_ASSERT	SM_CHECK_ALL
64 # endif /* ! SM_CHECK_ASSERT */
65 
66 # if SM_CHECK_REQUIRE
67 #  if defined(__STDC__) || defined(__cplusplus)
68 #   define SM_REQUIRE(cond) \
69 	((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
70 	"SM_REQUIRE(" #cond ") failed"), 0)))
71 #  else /* defined(__STDC__) || defined(__cplusplus) */
72 #   define SM_REQUIRE(cond) \
73 	((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
74 	"SM_REQUIRE(cond) failed"), 0)))
75 #  endif /* defined(__STDC__) || defined(__cplusplus) */
76 # else /* SM_CHECK_REQUIRE */
77 #  define SM_REQUIRE(cond)	((void) 0)
78 # endif /* SM_CHECK_REQUIRE */
79 
80 # define SM_REQUIRE_ISA(obj, magic) \
81 		SM_REQUIRE((obj) != NULL && (obj)->sm_magic == (magic))
82 
83 # if SM_CHECK_ENSURE
84 #  if defined(__STDC__) || defined(__cplusplus)
85 #   define SM_ENSURE(cond) \
86 	((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
87 	"SM_ENSURE(" #cond ") failed"), 0)))
88 #  else /* defined(__STDC__) || defined(__cplusplus) */
89 #   define SM_ENSURE(cond) \
90 	((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
91 	"SM_ENSURE(cond) failed"), 0)))
92 #  endif /* defined(__STDC__) || defined(__cplusplus) */
93 # else /* SM_CHECK_ENSURE */
94 #  define SM_ENSURE(cond)	((void) 0)
95 # endif /* SM_CHECK_ENSURE */
96 
97 # if SM_CHECK_ASSERT
98 #  if defined(__STDC__) || defined(__cplusplus)
99 #   define SM_ASSERT(cond) \
100 	((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
101 	"SM_ASSERT(" #cond ") failed"), 0)))
102 #  else /* defined(__STDC__) || defined(__cplusplus) */
103 #   define SM_ASSERT(cond) \
104 	((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
105 	"SM_ASSERT(cond) failed"), 0)))
106 #  endif /* defined(__STDC__) || defined(__cplusplus) */
107 # else /* SM_CHECK_ASSERT */
108 #  define SM_ASSERT(cond)	((void) 0)
109 # endif /* SM_CHECK_ASSERT */
110 
111 extern SM_DEBUG_T SmExpensiveRequire;
112 extern SM_DEBUG_T SmExpensiveEnsure;
113 extern SM_DEBUG_T SmExpensiveAssert;
114 
115 #endif /* ! SM_ASSERT_H */
116