michael@0: /* $NetBSD: assertions.h,v 1.1.1.1 2004/05/20 19:49:41 christos Exp $ */ michael@0: michael@0: /* michael@0: * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") michael@0: * Copyright (c) 1997-1999 by Internet Software Consortium. michael@0: * michael@0: * Permission to use, copy, modify, and distribute this software for any michael@0: * purpose with or without fee is hereby granted, provided that the above michael@0: * copyright notice and this permission notice appear in all copies. michael@0: * michael@0: * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES michael@0: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF michael@0: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR michael@0: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES michael@0: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN michael@0: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT michael@0: * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. michael@0: */ michael@0: michael@0: /* michael@0: * Id: assertions.h,v 1.1.206.1 2004/03/09 08:33:30 marka Exp michael@0: */ michael@0: michael@0: /* michael@0: * This version of this file is derived from Android 2.3 "Gingerbread", michael@0: * which contains uncredited changes by Android/Google developers. It has michael@0: * been modified in 2011 for use in the Android build of Mozilla Firefox by michael@0: * Mozilla contributors (including Michael Edwards , michael@0: * and Steve Workman ). michael@0: * These changes are offered under the same license as the original NetBSD michael@0: * file, whose copyright and license are unchanged above. michael@0: */ michael@0: michael@0: #ifndef ASSERTIONS_H michael@0: #define ASSERTIONS_H 1 michael@0: michael@0: typedef enum { michael@0: assert_require, assert_ensure, assert_insist, assert_invariant michael@0: } assertion_type; michael@0: michael@0: typedef void (*assertion_failure_callback)(const char *, int, assertion_type, michael@0: const char *, int); michael@0: michael@0: extern assertion_failure_callback __assertion_failed; michael@0: void set_assertion_failure_callback(assertion_failure_callback f); michael@0: const char *assertion_type_to_text(assertion_type type); michael@0: michael@0: #ifdef CHECK_ALL michael@0: #define CHECK_REQUIRE 1 michael@0: #define CHECK_ENSURE 1 michael@0: #define CHECK_INSIST 1 michael@0: #define CHECK_INVARIANT 1 michael@0: #endif michael@0: michael@0: #ifdef CHECK_NONE michael@0: #define CHECK_REQUIRE 0 michael@0: #define CHECK_ENSURE 0 michael@0: #define CHECK_INSIST 0 michael@0: #define CHECK_INVARIANT 0 michael@0: #endif michael@0: michael@0: #ifndef CHECK_REQUIRE michael@0: #define CHECK_REQUIRE 1 michael@0: #endif michael@0: michael@0: #ifndef CHECK_ENSURE michael@0: #define CHECK_ENSURE 1 michael@0: #endif michael@0: michael@0: #ifndef CHECK_INSIST michael@0: #define CHECK_INSIST 1 michael@0: #endif michael@0: michael@0: #ifndef CHECK_INVARIANT michael@0: #define CHECK_INVARIANT 1 michael@0: #endif michael@0: michael@0: #if CHECK_REQUIRE != 0 michael@0: #define REQUIRE(cond) \ michael@0: ((void) ((cond) || \ michael@0: ((__assertion_failed)(__FILE__, __LINE__, assert_require, \ michael@0: #cond, 0), 0))) michael@0: #define REQUIRE_ERR(cond) \ michael@0: ((void) ((cond) || \ michael@0: ((__assertion_failed)(__FILE__, __LINE__, assert_require, \ michael@0: #cond, 1), 0))) michael@0: #else michael@0: #define REQUIRE(cond) ((void) (cond)) michael@0: #define REQUIRE_ERR(cond) ((void) (cond)) michael@0: #endif /* CHECK_REQUIRE */ michael@0: michael@0: #if CHECK_ENSURE != 0 michael@0: #define ENSURE(cond) \ michael@0: ((void) ((cond) || \ michael@0: ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \ michael@0: #cond, 0), 0))) michael@0: #define ENSURE_ERR(cond) \ michael@0: ((void) ((cond) || \ michael@0: ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \ michael@0: #cond, 1), 0))) michael@0: #else michael@0: #define ENSURE(cond) ((void) (cond)) michael@0: #define ENSURE_ERR(cond) ((void) (cond)) michael@0: #endif /* CHECK_ENSURE */ michael@0: michael@0: #if CHECK_INSIST != 0 michael@0: #define INSIST(cond) \ michael@0: ((void) ((cond) || \ michael@0: ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \ michael@0: #cond, 0), 0))) michael@0: #define INSIST_ERR(cond) \ michael@0: ((void) ((cond) || \ michael@0: ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \ michael@0: #cond, 1), 0))) michael@0: #else michael@0: #define INSIST(cond) ((void) (cond)) michael@0: #define INSIST_ERR(cond) ((void) (cond)) michael@0: #endif /* CHECK_INSIST */ michael@0: michael@0: #if CHECK_INVARIANT != 0 michael@0: #define INVARIANT(cond) \ michael@0: ((void) ((cond) || \ michael@0: ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \ michael@0: #cond, 0), 0))) michael@0: #define INVARIANT_ERR(cond) \ michael@0: ((void) ((cond) || \ michael@0: ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \ michael@0: #cond, 1), 0))) michael@0: #else michael@0: #define INVARIANT(cond) ((void) (cond)) michael@0: #define INVARIANT_ERR(cond) ((void) (cond)) michael@0: #endif /* CHECK_INVARIANT */ michael@0: michael@0: #endif /* ASSERTIONS_H */