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