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