oi_assert.h 2.6 KB

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