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