1 /* 2 * Copyright (C) 2004-2009 Internet Systems Consortium, Inc. ("ISC") 3 * Copyright (C) 1997-2001 Internet Software Consortium. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 * PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 /* 19 * $Id: assertions.h,v 1.28 2009/09/29 23:48:04 tbox Exp $ 20 */ 21 /*! \file isc/assertions.h 22 */ 23 24 #ifndef ISC_ASSERTIONS_H 25 #define ISC_ASSERTIONS_H 1 26 27 #include <isc/lang.h> 28 #include <isc/platform.h> 29 30 ISC_LANG_BEGINDECLS 31 32 /*% isc assertion type */ 33 typedef enum { 34 isc_assertiontype_require, 35 isc_assertiontype_ensure, 36 isc_assertiontype_insist, 37 isc_assertiontype_invariant 38 } isc_assertiontype_t; 39 40 typedef void (*isc_assertioncallback_t)(const char *, int, isc_assertiontype_t, 41 const char *); 42 43 /* coverity[+kill] */ 44 ISC_PLATFORM_NORETURN_PRE 45 void isc_assertion_failed(const char *, int, isc_assertiontype_t, 46 const char *) ISC_PLATFORM_NORETURN_POST; 47 48 void 49 isc_assertion_setcallback(isc_assertioncallback_t); 50 51 const char * 52 isc_assertion_typetotext(isc_assertiontype_t type); 53 54 #if defined(ISC_CHECK_ALL) || defined(__COVERITY__) 55 #define ISC_CHECK_REQUIRE 1 56 #define ISC_CHECK_ENSURE 1 57 #define ISC_CHECK_INSIST 1 58 #define ISC_CHECK_INVARIANT 1 59 #endif 60 61 #if defined(ISC_CHECK_NONE) && !defined(__COVERITY__) 62 #define ISC_CHECK_REQUIRE 0 63 #define ISC_CHECK_ENSURE 0 64 #define ISC_CHECK_INSIST 0 65 #define ISC_CHECK_INVARIANT 0 66 #endif 67 68 #ifndef ISC_CHECK_REQUIRE 69 #define ISC_CHECK_REQUIRE 1 70 #endif 71 72 #ifndef ISC_CHECK_ENSURE 73 #define ISC_CHECK_ENSURE 1 74 #endif 75 76 #ifndef ISC_CHECK_INSIST 77 #define ISC_CHECK_INSIST 1 78 #endif 79 80 #ifndef ISC_CHECK_INVARIANT 81 #define ISC_CHECK_INVARIANT 1 82 #endif 83 84 #if ISC_CHECK_REQUIRE != 0 85 #define ISC_REQUIRE(cond) \ 86 ((void) ((cond) || \ 87 ((isc_assertion_failed)(__FILE__, __LINE__, \ 88 isc_assertiontype_require, \ 89 #cond), 0))) 90 #else 91 #define ISC_REQUIRE(cond) ((void) 0) 92 #endif /* ISC_CHECK_REQUIRE */ 93 94 #if ISC_CHECK_ENSURE != 0 95 #define ISC_ENSURE(cond) \ 96 ((void) ((cond) || \ 97 ((isc_assertion_failed)(__FILE__, __LINE__, \ 98 isc_assertiontype_ensure, \ 99 #cond), 0))) 100 #else 101 #define ISC_ENSURE(cond) ((void) 0) 102 #endif /* ISC_CHECK_ENSURE */ 103 104 #if ISC_CHECK_INSIST != 0 105 #define ISC_INSIST(cond) \ 106 ((void) ((cond) || \ 107 ((isc_assertion_failed)(__FILE__, __LINE__, \ 108 isc_assertiontype_insist, \ 109 #cond), 0))) 110 #else 111 #define ISC_INSIST(cond) ((void) 0) 112 #endif /* ISC_CHECK_INSIST */ 113 114 #if ISC_CHECK_INVARIANT != 0 115 #define ISC_INVARIANT(cond) \ 116 ((void) ((cond) || \ 117 ((isc_assertion_failed)(__FILE__, __LINE__, \ 118 isc_assertiontype_invariant, \ 119 #cond), 0))) 120 #else 121 #define ISC_INVARIANT(cond) ((void) 0) 122 #endif /* ISC_CHECK_INVARIANT */ 123 124 ISC_LANG_ENDDECLS 125 126 #endif /* ISC_ASSERTIONS_H */ 127