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