diff options
Diffstat (limited to 'mps/code/assert.c')
| -rw-r--r-- | mps/code/assert.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/mps/code/assert.c b/mps/code/assert.c new file mode 100644 index 00000000000..206112e5d30 --- /dev/null +++ b/mps/code/assert.c | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | /* impl.c.assert: ASSERTION IMPLEMENTATION | ||
| 2 | * | ||
| 3 | * $HopeName$ | ||
| 4 | * Copyright (C) 1999 Harlequin Limited. All rights reserved. | ||
| 5 | * | ||
| 6 | * This source provides the AssertFail function which is | ||
| 7 | * invoked by the assertion macros (see impl.h.assert). | ||
| 8 | * It also provides for user-installed assertion failure handlers. | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include "check.h" | ||
| 12 | #include "mpm.h" | ||
| 13 | |||
| 14 | SRCID(assert, "$HopeName: MMsrc!assert.c(trunk.11) $"); | ||
| 15 | |||
| 16 | |||
| 17 | /* CheckLevel -- Control check level | ||
| 18 | * | ||
| 19 | * This controls the behaviour of Check methods unless MPS_HOT_RED | ||
| 20 | * is defined, when it is effectively stuck at "CheckNONE". | ||
| 21 | */ | ||
| 22 | |||
| 23 | unsigned CheckLevel = CheckSHALLOW; | ||
| 24 | |||
| 25 | |||
| 26 | static void AssertLib(const char *cond, const char *id, | ||
| 27 | const char *file, unsigned line) | ||
| 28 | { | ||
| 29 | WriteF(mps_lib_stderr, | ||
| 30 | "\n" | ||
| 31 | "MPS ASSERTION FAILURE\n" | ||
| 32 | "\n" | ||
| 33 | "Id: $S\n", id, | ||
| 34 | "File: $S\n", file, | ||
| 35 | "Line: $U\n", (WriteFU)line, | ||
| 36 | "Condition: $S\n", cond, | ||
| 37 | "\n", | ||
| 38 | NULL); | ||
| 39 | |||
| 40 | mps_lib_abort(); | ||
| 41 | } | ||
| 42 | |||
| 43 | |||
| 44 | static AssertHandler handler = &AssertLib; | ||
| 45 | |||
| 46 | |||
| 47 | AssertHandler AssertDefault(void) | ||
| 48 | { | ||
| 49 | return &AssertLib; | ||
| 50 | } | ||
| 51 | |||
| 52 | |||
| 53 | AssertHandler AssertInstall(AssertHandler new) | ||
| 54 | { | ||
| 55 | AssertHandler prev = handler; | ||
| 56 | handler = new; | ||
| 57 | return prev; | ||
| 58 | } | ||
| 59 | |||
| 60 | |||
| 61 | /* AssertFail -- fail an assertion | ||
| 62 | * | ||
| 63 | * This function is called when an ASSERT macro fails a test. It | ||
| 64 | * calls the installed assertion handler, if it is not NULL. If | ||
| 65 | * handler returns the progam continues. | ||
| 66 | */ | ||
| 67 | void AssertFail1(const char *s) | ||
| 68 | { | ||
| 69 | if (handler != NULL) | ||
| 70 | (*handler)(s, "", "", 0); | ||
| 71 | } | ||