1 /****************************************************************************** 2 * 3 * Copyright 2014 The Android Open Source Project 4 * Copyright 2002 - 2004 Open Interface North America, Inc. All rights 5 * reserved. 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at: 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * 19 ******************************************************************************/ 20 #ifndef _OI_ASSERT_H 21 #define _OI_ASSERT_H 22 /** @file 23 This file provides macros and functions for compile-time and run-time 24 assertions. 25 26 When the OI_DEBUG preprocessor value is defined, the macro OI_ASSERT is 27 compiled into 28 the program, providing for a runtime assertion failure check. 29 C_ASSERT is a macro that can be used to perform compile time checks. 30 */ 31 /******************************************************************************* 32 $Revision: #1 $ 33 ******************************************************************************/ 34 35 /** \addtogroup Debugging Debugging APIs */ 36 /**@{*/ 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 #ifdef OI_DEBUG 43 44 /** The macro OI_ASSERT takes a condition argument. If the asserted condition 45 does not evaluate to true, the OI_ASSERT macro calls the host-dependent 46 function, 47 OI_AssertFail(), which reports the failure and generates a runtime error. 48 */ 49 void OI_AssertFail(char* file, int line, char* reason); 50 51 #define OI_ASSERT(condition) \ 52 { \ 53 if (!(condition)) OI_AssertFail(__FILE__, __LINE__, #condition); \ 54 } 55 56 #define OI_ASSERT_FAIL(msg) \ 57 { OI_AssertFail(__FILE__, __LINE__, msg); } 58 59 #else 60 61 #define OI_ASSERT(condition) 62 #define OI_ASSERT_FAIL(msg) 63 64 #endif 65 66 /** 67 C_ASSERT() can be used to perform many compile-time assertions: type sizes, 68 field offsets, etc. 69 An assertion failure results in compile time error C2118: negative subscript. 70 Unfortunately, this elegant macro doesn't work with GCC, so it's all 71 commented out 72 for now. Perhaps later..... 73 */ 74 75 #ifndef C_ASSERT 76 // #define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1] 77 // #define C_ASSERT(e) 78 #endif 79 80 /*****************************************************************************/ 81 #ifdef __cplusplus 82 } 83 #endif 84 85 /**@}*/ 86 87 #endif /* _OI_ASSERT_H */ 88