1 /* $NetBSD: assertions.h,v 1.1.1.1 2004/05/20 19:49:41 christos Exp $ */ 2 3 /* 4 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") 5 * Copyright (c) 1997-1999 by Internet Software Consortium. 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 17 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 /* 21 * Id: assertions.h,v 1.1.206.1 2004/03/09 08:33:30 marka Exp 22 */ 23 24 #ifndef ASSERTIONS_H 25 #define ASSERTIONS_H 1 26 27 typedef enum { 28 assert_require, assert_ensure, assert_insist, assert_invariant 29 } assertion_type; 30 31 typedef void (*assertion_failure_callback)(const char *, int, assertion_type, 32 const char *, int); 33 34 extern assertion_failure_callback __assertion_failed; 35 void set_assertion_failure_callback(assertion_failure_callback f); 36 const char *assertion_type_to_text(assertion_type type); 37 38 #ifdef CHECK_ALL 39 #define CHECK_REQUIRE 1 40 #define CHECK_ENSURE 1 41 #define CHECK_INSIST 1 42 #define CHECK_INVARIANT 1 43 #endif 44 45 #ifdef CHECK_NONE 46 #define CHECK_REQUIRE 0 47 #define CHECK_ENSURE 0 48 #define CHECK_INSIST 0 49 #define CHECK_INVARIANT 0 50 #endif 51 52 #ifndef CHECK_REQUIRE 53 #define CHECK_REQUIRE 1 54 #endif 55 56 #ifndef CHECK_ENSURE 57 #define CHECK_ENSURE 1 58 #endif 59 60 #ifndef CHECK_INSIST 61 #define CHECK_INSIST 1 62 #endif 63 64 #ifndef CHECK_INVARIANT 65 #define CHECK_INVARIANT 1 66 #endif 67 68 #if CHECK_REQUIRE != 0 69 #define REQUIRE(cond) \ 70 ((void) ((cond) || \ 71 ((__assertion_failed)(__FILE__, __LINE__, assert_require, \ 72 #cond, 0), 0))) 73 #define REQUIRE_ERR(cond) \ 74 ((void) ((cond) || \ 75 ((__assertion_failed)(__FILE__, __LINE__, assert_require, \ 76 #cond, 1), 0))) 77 #else 78 #define REQUIRE(cond) ((void) (cond)) 79 #define REQUIRE_ERR(cond) ((void) (cond)) 80 #endif /* CHECK_REQUIRE */ 81 82 #if CHECK_ENSURE != 0 83 #define ENSURE(cond) \ 84 ((void) ((cond) || \ 85 ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \ 86 #cond, 0), 0))) 87 #define ENSURE_ERR(cond) \ 88 ((void) ((cond) || \ 89 ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \ 90 #cond, 1), 0))) 91 #else 92 #define ENSURE(cond) ((void) (cond)) 93 #define ENSURE_ERR(cond) ((void) (cond)) 94 #endif /* CHECK_ENSURE */ 95 96 #if CHECK_INSIST != 0 97 #define INSIST(cond) \ 98 ((void) ((cond) || \ 99 ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \ 100 #cond, 0), 0))) 101 #define INSIST_ERR(cond) \ 102 ((void) ((cond) || \ 103 ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \ 104 #cond, 1), 0))) 105 #else 106 #define INSIST(cond) ((void) (cond)) 107 #define INSIST_ERR(cond) ((void) (cond)) 108 #endif /* CHECK_INSIST */ 109 110 #if CHECK_INVARIANT != 0 111 #define INVARIANT(cond) \ 112 ((void) ((cond) || \ 113 ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \ 114 #cond, 0), 0))) 115 #define INVARIANT_ERR(cond) \ 116 ((void) ((cond) || \ 117 ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \ 118 #cond, 1), 0))) 119 #else 120 #define INVARIANT(cond) ((void) (cond)) 121 #define INVARIANT_ERR(cond) ((void) (cond)) 122 #endif /* CHECK_INVARIANT */ 123 124 #endif /* ASSERTIONS_H */ 125