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