summaryrefslogtreecommitdiffstats
path: root/contrib/sendmail/include/sm/assert.h
blob: 6b8653620c685c4c91967bb20c826368468d00d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
 *	All rights reserved.
 *
 * By using this file, you agree to the terms and conditions set
 * forth in the LICENSE file which can be found at the top level of
 * the sendmail distribution.
 *
 *	$Id: assert.h,v 1.10 2001/06/07 20:04:53 ca Exp $
 */

/*
**  libsm abnormal program termination and assertion checking
**  See libsm/assert.html for documentation.
*/

#ifndef SM_ASSERT_H
# define SM_ASSERT_H

# include <sm/gen.h>
# include <sm/debug.h>

/*
**  abnormal program termination
*/

typedef void (*SM_ABORT_HANDLER_T) __P((const char *, int, const char *));

extern SM_DEAD(void
sm_abort_at __P((
	const char *,
	int,
	const char *)));

extern void
sm_abort_sethandler __P((
	SM_ABORT_HANDLER_T));

extern SM_DEAD(void PRINTFLIKE(1, 2)
sm_abort __P((
	char *,
	...)));

/*
**  assertion checking
*/

# ifndef SM_CHECK_ALL
#  define SM_CHECK_ALL		1
# endif /* ! SM_CHECK_ALL */

# ifndef SM_CHECK_REQUIRE
#  define SM_CHECK_REQUIRE	SM_CHECK_ALL
# endif /* ! SM_CHECK_REQUIRE */

# ifndef SM_CHECK_ENSURE
#  define SM_CHECK_ENSURE	SM_CHECK_ALL
# endif /* ! SM_CHECK_ENSURE */

# ifndef SM_CHECK_ASSERT
#  define SM_CHECK_ASSERT	SM_CHECK_ALL
# endif /* ! SM_CHECK_ASSERT */

# if SM_CHECK_REQUIRE
#  if defined(__STDC__) || defined(__cplusplus)
#   define SM_REQUIRE(cond) \
	((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
	"SM_REQUIRE(" #cond ") failed"), 0)))
#  else /* defined(__STDC__) || defined(__cplusplus) */
#   define SM_REQUIRE(cond) \
	((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
	"SM_REQUIRE(cond) failed"), 0)))
#  endif /* defined(__STDC__) || defined(__cplusplus) */
# else /* SM_CHECK_REQUIRE */
#  define SM_REQUIRE(cond)	((void) 0)
# endif /* SM_CHECK_REQUIRE */

# define SM_REQUIRE_ISA(obj, magic) \
		SM_REQUIRE((obj) != NULL && (obj)->sm_magic == (magic))

# if SM_CHECK_ENSURE
#  if defined(__STDC__) || defined(__cplusplus)
#   define SM_ENSURE(cond) \
	((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
	"SM_ENSURE(" #cond ") failed"), 0)))
#  else /* defined(__STDC__) || defined(__cplusplus) */
#   define SM_ENSURE(cond) \
	((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
	"SM_ENSURE(cond) failed"), 0)))
#  endif /* defined(__STDC__) || defined(__cplusplus) */
# else /* SM_CHECK_ENSURE */
#  define SM_ENSURE(cond)	((void) 0)
# endif /* SM_CHECK_ENSURE */

# if SM_CHECK_ASSERT
#  if defined(__STDC__) || defined(__cplusplus)
#   define SM_ASSERT(cond) \
	((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
	"SM_ASSERT(" #cond ") failed"), 0)))
#  else /* defined(__STDC__) || defined(__cplusplus) */
#   define SM_ASSERT(cond) \
	((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
	"SM_ASSERT(cond) failed"), 0)))
#  endif /* defined(__STDC__) || defined(__cplusplus) */
# else /* SM_CHECK_ASSERT */
#  define SM_ASSERT(cond)	((void) 0)
# endif /* SM_CHECK_ASSERT */

extern SM_DEBUG_T SmExpensiveRequire;
extern SM_DEBUG_T SmExpensiveEnsure;
extern SM_DEBUG_T SmExpensiveAssert;

#endif /* ! SM_ASSERT_H */
OpenPOWER on IntegriCloud