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