| 1 | // © 2016 and later: Unicode, Inc. and others. |
| 2 | // License & terms of use: http://www.unicode.org/copyright.html |
| 3 | /* |
| 4 | ****************************************************************************** |
| 5 | * |
| 6 | * Copyright (C) 2002-2011, International Business Machines |
| 7 | * Corporation and others. All Rights Reserved. |
| 8 | * |
| 9 | ****************************************************************************** |
| 10 | * |
| 11 | * File uassert.h |
| 12 | * |
| 13 | * Contains the U_ASSERT and UPRV_UNREACHABLE_* macros |
| 14 | * |
| 15 | ****************************************************************************** |
| 16 | */ |
| 17 | #ifndef U_ASSERT_H |
| 18 | #define U_ASSERT_H |
| 19 | |
| 20 | /* utypes.h is included to get the proper define for uint8_t */ |
| 21 | #include "unicode/utypes.h" |
| 22 | /* for abort */ |
| 23 | #include <stdlib.h> |
| 24 | |
| 25 | /** |
| 26 | * \def U_ASSERT |
| 27 | * By default, U_ASSERT just wraps the C library assert macro. |
| 28 | * By changing the definition here, the assert behavior for ICU can be changed |
| 29 | * without affecting other non - ICU uses of the C library assert(). |
| 30 | */ |
| 31 | #if U_DEBUG |
| 32 | # include <assert.h> |
| 33 | # define U_ASSERT(exp) assert(exp) |
| 34 | #elif U_CPLUSPLUS_VERSION |
| 35 | # define U_ASSERT(exp) (void)0 |
| 36 | #else |
| 37 | # define U_ASSERT(exp) |
| 38 | #endif |
| 39 | |
| 40 | /** |
| 41 | * \def UPRV_UNREACHABLE_ASSERT |
| 42 | * This macro is used in places that we had believed were unreachable, but |
| 43 | * experience has shown otherwise (possibly due to memory corruption, etc). |
| 44 | * In this case we call assert() in debug versions as with U_ASSERT, instead |
| 45 | * of unconditionally calling abort(). However we also allow redefinition as |
| 46 | * with UPRV_UNREACHABLE_EXIT. |
| 47 | * @internal |
| 48 | */ |
| 49 | #if defined(UPRV_UNREACHABLE_ASSERT) |
| 50 | // Use the predefined value. |
| 51 | #elif U_DEBUG |
| 52 | # include <assert.h> |
| 53 | # define UPRV_UNREACHABLE_ASSERT assert(false) |
| 54 | #elif U_CPLUSPLUS_VERSION |
| 55 | # define UPRV_UNREACHABLE_ASSERT (void)0 |
| 56 | #else |
| 57 | # define UPRV_UNREACHABLE_ASSERT |
| 58 | #endif |
| 59 | |
| 60 | /** |
| 61 | * \def UPRV_UNREACHABLE_EXIT |
| 62 | * This macro is used to unconditionally abort if unreachable code is ever executed. |
| 63 | * @internal |
| 64 | */ |
| 65 | #if defined(UPRV_UNREACHABLE_EXIT) |
| 66 | // Use the predefined value. |
| 67 | #else |
| 68 | # define UPRV_UNREACHABLE_EXIT abort() |
| 69 | #endif |
| 70 | |
| 71 | #endif |
| 72 | |