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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
/*** asrt.h - Definitions for Assertion Manager
*
* Microsoft Confidential
* Copyright (C) Microsoft Corporation 1993-1994
* All Rights Reserved.
*
* Author:
* Benjamin W. Slivka
*
* History:
* 10-Aug-1993 bens Initial version
* 11-Aug-1993 bens Lifted old code from 1988 PSCHAR.EXE
* 14-Aug-1993 bens Added Get/Set functions
* 01-Sep-1993 bens Added AssertSub function
* 10-Feb-1994 bens Added Set/ClearAssertSignature
* 15-Mar-1994 bens Put back AssertMessage macro
*
* Notes:
* o Every data structure must have a signature as first member.
* o Signatures MUST be unique over all structures.
* o sigBAD is a reserved signature.
* o When freeing a structure, blast the signature field with sigBAD.
* o Put an AssertXXX prior to dereferencing any pointer.
* o Signatures in structures and private Assert definitions should only
* be generated if ASSERT is defined.
*
* Functions available in ASSERT build:
* AssertRegisterFunc - Register assertion failure call back function
* AssertGetFunc - Get registered call back function
*
* AssertSetFlags - Set Assertion Manager flags
* AssertGetFlags - Get Assertion Manager flags
*
* Assert - Check that parameter is TRUE
* AssertSub - Check that parameter is TRUE, take explicit filename & line number
* AssertStrucure - Check that pointer points to specified structure
* AssertForce - Force an assertion failure
* AssertErrPath - Error Path assertion failure
*
* SetAssertSignature - Set the signature for a structure
* ClearAssertSignature - Clear the signature for a structure
*
* Other definitions available in ASSERT build:
* PFNASSERTFAILURE - Assertion failure call back function type
* FNASSERTFAILURE - Macro to simplify declaration of call back function
* SIGNATURE - Structure signature type
*/
#ifndef INCLUDED_ASSERT
#define INCLUDED_ASSERT 1
#ifdef _DEBUG
#ifndef ASSERT
#define ASSERT 1
#endif // !ASSERT
#endif // _DEBUG
#ifdef ASSERT
typedef unsigned long ASSERTFLAGS; /* asf - Assertion Manager Flags */
#define asfNONE 0x00
#define asfSKIP_ERROR_PATH_ASSERTS 0x01 /* Some clients may wish to set
* assertions in error paths, to
* ensure that the problem is
* noticed in a debug build. But,
* in order to support automated
* testing of error paths, these
* assertions must be disabled.
* This flag allows a test program
* to disable these informational
* asserts!
*/
typedef unsigned long SIGNATURE; /* sig - structure signature */
typedef SIGNATURE *PSIGNATURE; /* psig */
#define sigBAD 0 // Invalid signature for ALL structs
/*** MAKESIG - construct a structure signature
*
* Entry:
* ch1,ch2,ch3,ch4 - four characters
*
* Exit:
* returns SIGNATURE
*/
#define MAKESIG(ch1,ch2,ch3,ch4) \
( ((SIGNATURE)ch1) + \
(((SIGNATURE)ch2)<< 8) + \
(((SIGNATURE)ch3)<<16) + \
(((SIGNATURE)ch4)<<24) )
/*** AssertMessage -- Force an Assertion with supplied message
*
* Entry:
* pszMsg -- message to display
*
* Exit:
* none
*/
#define AssertMessage(pszMsg) AssertForce(pszMsg,__FILE__,__LINE__)
/*** PFNASSERTFAILURE - Assertion Failure call back function
*** FNASSERTFAILURE - Define Assertion Failure call back function
*
* Entry:
* pszMsg - Description of failure
* pszFile - File where assertion failed
* iLine - Line number in file where assertion failed
*
* Exit-Success:
* Returns; ignore failure and continue
*
* Exit-Failure:
* Function does not return, but cleans up and exits program.
*/
typedef void (*PFNASSERTFAILURE)(char *pszMsg, char *pszFile, int iLine);
#define FNASSERTFAILURE(fn) void fn(char *pszMsg, char *pszFile, int iLine)
/*** AssertRegisterFunc - Register assertion failure call back function
*
* Entry:
* pfnaf - Call back function
*
* Exit-Success:
* Returns; pfnaf is stored in the Assertion Manager
*
* NOTES:
* (1) This function *must* be called prior to executing an assertion
* checks. If not, and an assertion check fails, then the Assertion
* Manager will sit in a spin loop to catch the developer's attention.
*/
void AssertRegisterFunc(PFNASSERTFAILURE pfnaf);
/*** AssertGetFunc - Get current assertion failure call back function
*
* Entry:
* none
*
* Exit-Success:
* Returns current call back function registerd in Assertion Manager.
*/
PFNASSERTFAILURE AssertGetFunc(void);
/*** AssertSetFlags - Set special assertion control flags
*
* Entry:
* flags - Set with combination of asfXXXX flags
*
* Exit-Success:
* Returns; Flags are modified in Assertion Manager.
*/
void AssertSetFlags(ASSERTFLAGS asf);
/*** AssertGetFlags - Get special assertion control flags
*
* Entry:
* none
*
* Exit-Success:
* Returns current Assertion Manager flags.
*/
ASSERTFLAGS AssertGetFlags(void);
/*** Assert - Check assertion that argument is true
*
* Entry:
* b - Boolean value to check
*
* Exit-Success:
* Returns; b was TRUE
*
* Exit-Failure:
* Calls assertion failure callback function; b was FALSE
*/
#define Assert(b) AsrtCheck(b,__FILE__,__LINE__)
/*** AssertSub - Check assertion, use passed in filename and line number
*
* Entry:
* b - Boolean value to check
* pszFile - File where assertion occurred
* iLine - Line in file where assertion occurred
*
* Exit-Success:
* Returns; b was TRUE
*
* Exit-Failure:
* Calls assertion failure callback function; b was FALSE
*/
#define AssertSub(b,pszFile,iLine) AsrtCheck(b,pszFile,iLine)
/*** AssertStructure - Check assertion that pointer is of correct type
*
* Entry:
* pv - Pointer to structure
* sig - Expected signature
*
* Exit-Success:
* Returns; pv != NULL, and pv->sig == sig.
*
* Exit-Failure:
* Calls assertion failure callback function; pv was bad.
*/
#define AssertStructure(pv,sig) AsrtStruct(pv, sig, __FILE__, __LINE__)
/*** AssertForce - Force an assertion failure
*
* Entry:
* pszMsg - Message to display
* pszFile - File where assertion occurred
* iLine - Line in file where assertion occurred
*
* Exit-Success:
* Returns; client wanted to ignore assertion.
*
* Exit-Failure:
* Does not return.
*/
void AssertForce(char *pszMsg, char *pszFile, int iLine);
/*** AssertErrorPath - Report an internal error path
*
* Entry:
* pszMsg - Message to display
* pszFile - File where assertion occurred
* iLine - Line in file where assertion occurred
*
* Exit-Success:
* Returns; client wanted to ignore assertion.
*
* Exit-Failure:
* Does not return.
*/
void AssertErrPath(char *pszMsg, char *pszFile, int iLine);
/*** SetAssertSignature - Set the signature for a structure
*
* Entry:
* p - Structure with member "sigValue"
* sig - Signature to set
*
* Exit:
* p->sig = sig
*/
#define SetAssertSignature(p,sigValue) p->sig = sigValue
/*** ClearAssertSignature - Clear the signature for a structure
*
* Entry:
* p - Structure with member "sig"
*
* Exit:
* p->sig = sigBAD
*/
#define ClearAssertSignature(p) p->sig = sigBAD
//** Internal assertion manager worker routines
void AsrtCheck(BOOL f, char *pszFile, int iLine);
void AsrtStruct(void *pv, SIGNATURE sig, char *pszFile, int iLine);
#else // !ASSERT
//** Assertion checking is turned off, so it all evaporates!
#define FNASSERTFAILURE(fn)
#define AssertRegisterFunc(pfnaf)
#define Assert(b)
#define AssertSub(b,pszFile,iLine)
#define AssertStructure(pv,sig)
#define AssertMessage(pszMsg)
#define AssertForce(pszMsg,pszFile,iLine)
#define AssertErrPath(pszMsg,pszFile,iLine)
#define SetAssertSignature(p,sig)
#define ClearAssertSignature(p)
/** The following functions are not defined away, because any valid use
* of them requires a typedef'd variable or function that is not available
* in a non-ASSERT build. So we don't define them so that if a client
* has used these outside of an #ifdef ASSERT, a compiler error/warning
* will be generated:
*
* AssertGetFunc
* AssertSetFlags
* AssertGetFlags
*/
#endif // ASSERT
#endif // !INCLUDED_ASSERT
|