10Sstevel@tonic-gate /* 2*11038SRao.Shoaib@Sun.COM * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") 3*11038SRao.Shoaib@Sun.COM * Copyright (C) 1997-2001 Internet Software Consortium. 40Sstevel@tonic-gate * 5*11038SRao.Shoaib@Sun.COM * Permission to use, copy, modify, and/or distribute this software for any 60Sstevel@tonic-gate * purpose with or without fee is hereby granted, provided that the above 70Sstevel@tonic-gate * copyright notice and this permission notice appear in all copies. 80Sstevel@tonic-gate * 9*11038SRao.Shoaib@Sun.COM * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10*11038SRao.Shoaib@Sun.COM * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11*11038SRao.Shoaib@Sun.COM * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12*11038SRao.Shoaib@Sun.COM * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13*11038SRao.Shoaib@Sun.COM * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14*11038SRao.Shoaib@Sun.COM * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15*11038SRao.Shoaib@Sun.COM * PERFORMANCE OF THIS SOFTWARE. 160Sstevel@tonic-gate */ 170Sstevel@tonic-gate 180Sstevel@tonic-gate /* 19*11038SRao.Shoaib@Sun.COM * $Id: assertions.h,v 1.5 2008/11/14 02:36:51 marka Exp $ 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate 220Sstevel@tonic-gate #ifndef ASSERTIONS_H 230Sstevel@tonic-gate #define ASSERTIONS_H 1 240Sstevel@tonic-gate 250Sstevel@tonic-gate typedef enum { 260Sstevel@tonic-gate assert_require, assert_ensure, assert_insist, assert_invariant 270Sstevel@tonic-gate } assertion_type; 280Sstevel@tonic-gate 290Sstevel@tonic-gate typedef void (*assertion_failure_callback)(const char *, int, assertion_type, 300Sstevel@tonic-gate const char *, int); 310Sstevel@tonic-gate 32*11038SRao.Shoaib@Sun.COM /* coverity[+kill] */ 330Sstevel@tonic-gate extern assertion_failure_callback __assertion_failed; 340Sstevel@tonic-gate void set_assertion_failure_callback(assertion_failure_callback f); 350Sstevel@tonic-gate const char *assertion_type_to_text(assertion_type type); 360Sstevel@tonic-gate 37*11038SRao.Shoaib@Sun.COM #if defined(CHECK_ALL) || defined(__COVERITY__) 380Sstevel@tonic-gate #define CHECK_REQUIRE 1 390Sstevel@tonic-gate #define CHECK_ENSURE 1 400Sstevel@tonic-gate #define CHECK_INSIST 1 410Sstevel@tonic-gate #define CHECK_INVARIANT 1 420Sstevel@tonic-gate #endif 430Sstevel@tonic-gate 44*11038SRao.Shoaib@Sun.COM #if defined(CHECK_NONE) && !defined(__COVERITY__) 450Sstevel@tonic-gate #define CHECK_REQUIRE 0 460Sstevel@tonic-gate #define CHECK_ENSURE 0 470Sstevel@tonic-gate #define CHECK_INSIST 0 480Sstevel@tonic-gate #define CHECK_INVARIANT 0 490Sstevel@tonic-gate #endif 500Sstevel@tonic-gate 510Sstevel@tonic-gate #ifndef CHECK_REQUIRE 520Sstevel@tonic-gate #define CHECK_REQUIRE 1 530Sstevel@tonic-gate #endif 540Sstevel@tonic-gate 550Sstevel@tonic-gate #ifndef CHECK_ENSURE 560Sstevel@tonic-gate #define CHECK_ENSURE 1 570Sstevel@tonic-gate #endif 580Sstevel@tonic-gate 590Sstevel@tonic-gate #ifndef CHECK_INSIST 600Sstevel@tonic-gate #define CHECK_INSIST 1 610Sstevel@tonic-gate #endif 620Sstevel@tonic-gate 630Sstevel@tonic-gate #ifndef CHECK_INVARIANT 640Sstevel@tonic-gate #define CHECK_INVARIANT 1 650Sstevel@tonic-gate #endif 660Sstevel@tonic-gate 670Sstevel@tonic-gate #if CHECK_REQUIRE != 0 680Sstevel@tonic-gate #define REQUIRE(cond) \ 690Sstevel@tonic-gate ((void) ((cond) || \ 700Sstevel@tonic-gate ((__assertion_failed)(__FILE__, __LINE__, assert_require, \ 710Sstevel@tonic-gate #cond, 0), 0))) 720Sstevel@tonic-gate #define REQUIRE_ERR(cond) \ 730Sstevel@tonic-gate ((void) ((cond) || \ 740Sstevel@tonic-gate ((__assertion_failed)(__FILE__, __LINE__, assert_require, \ 750Sstevel@tonic-gate #cond, 1), 0))) 760Sstevel@tonic-gate #else 770Sstevel@tonic-gate #define REQUIRE(cond) ((void) (cond)) 780Sstevel@tonic-gate #define REQUIRE_ERR(cond) ((void) (cond)) 790Sstevel@tonic-gate #endif /* CHECK_REQUIRE */ 800Sstevel@tonic-gate 810Sstevel@tonic-gate #if CHECK_ENSURE != 0 820Sstevel@tonic-gate #define ENSURE(cond) \ 830Sstevel@tonic-gate ((void) ((cond) || \ 840Sstevel@tonic-gate ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \ 850Sstevel@tonic-gate #cond, 0), 0))) 860Sstevel@tonic-gate #define ENSURE_ERR(cond) \ 870Sstevel@tonic-gate ((void) ((cond) || \ 880Sstevel@tonic-gate ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \ 890Sstevel@tonic-gate #cond, 1), 0))) 900Sstevel@tonic-gate #else 910Sstevel@tonic-gate #define ENSURE(cond) ((void) (cond)) 920Sstevel@tonic-gate #define ENSURE_ERR(cond) ((void) (cond)) 930Sstevel@tonic-gate #endif /* CHECK_ENSURE */ 940Sstevel@tonic-gate 950Sstevel@tonic-gate #if CHECK_INSIST != 0 960Sstevel@tonic-gate #define INSIST(cond) \ 970Sstevel@tonic-gate ((void) ((cond) || \ 980Sstevel@tonic-gate ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \ 990Sstevel@tonic-gate #cond, 0), 0))) 1000Sstevel@tonic-gate #define INSIST_ERR(cond) \ 1010Sstevel@tonic-gate ((void) ((cond) || \ 1020Sstevel@tonic-gate ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \ 1030Sstevel@tonic-gate #cond, 1), 0))) 1040Sstevel@tonic-gate #else 1050Sstevel@tonic-gate #define INSIST(cond) ((void) (cond)) 1060Sstevel@tonic-gate #define INSIST_ERR(cond) ((void) (cond)) 1070Sstevel@tonic-gate #endif /* CHECK_INSIST */ 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate #if CHECK_INVARIANT != 0 1100Sstevel@tonic-gate #define INVARIANT(cond) \ 1110Sstevel@tonic-gate ((void) ((cond) || \ 1120Sstevel@tonic-gate ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \ 1130Sstevel@tonic-gate #cond, 0), 0))) 1140Sstevel@tonic-gate #define INVARIANT_ERR(cond) \ 1150Sstevel@tonic-gate ((void) ((cond) || \ 1160Sstevel@tonic-gate ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \ 1170Sstevel@tonic-gate #cond, 1), 0))) 1180Sstevel@tonic-gate #else 1190Sstevel@tonic-gate #define INVARIANT(cond) ((void) (cond)) 1200Sstevel@tonic-gate #define INVARIANT_ERR(cond) ((void) (cond)) 1210Sstevel@tonic-gate #endif /* CHECK_INVARIANT */ 1220Sstevel@tonic-gate #endif /* ASSERTIONS_H */ 123*11038SRao.Shoaib@Sun.COM /*! \file */ 124