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
|
/* arg.c: ARGUMENT LISTS
*
* $Id$
* Copyright (c) 2013-2020 Ravenbrook Limited. See end of file for license.
*
* .source: <design/keyword-arguments.rst>.
*/
#include "config.h"
#include "check.h"
#include "mpm.h"
#include "dbgpool.h"
SRCID(arg, "$Id$");
/* ArgCheckCant -- default argument checker
*
* This is a default value for the KeyStruct check field for keywords
* that don't have any meaningful checking they can do.
*/
Bool ArgCheckCant(Arg arg)
{
UNUSED(arg);
return TRUE;
}
static Bool ArgCheckShouldnt(Arg arg)
{
UNUSED(arg);
NOTREACHED;
return FALSE;
}
Bool ArgCheckFormat(Arg arg)
{
CHECKD(Format, arg->val.format);
return TRUE;
}
Bool ArgCheckChain(Arg arg)
{
CHECKD(Chain, arg->val.chain);
return TRUE;
}
Bool ArgCheckSize(Arg arg)
{
UNUSED(arg); /* TODO: Add and call SizeCheck */
return TRUE;
}
Bool ArgCheckAddr(Arg arg)
{
UNUSED(arg); /* TODO: Add and call AddrCheck */
return TRUE;
}
Bool ArgCheckPoolDebugOptions(Arg arg)
{
CHECKD_NOSIG(PoolDebugOptions, (PoolDebugOptions)arg->val.pool_debug_options);
return TRUE;
}
Bool ArgCheckFun(Arg arg)
{
/* TODO: Fix potential pun here on Harvard architectures where
function pointers are not compatible with other pointers. */
CHECKL(FUNCHECK(arg->val.addr_method));
return TRUE;
}
Bool ArgCheckAlign(Arg arg)
{
CHECKL(AlignCheck(arg->val.align));
return TRUE;
}
Bool ArgCheckBool(Arg arg)
{
CHECKL(BoolCheck(arg->val.b));
return TRUE;
}
Bool ArgCheckCount(Arg arg)
{
UNUSED(arg); /* TODO: Add and call CountCheck */
return TRUE;
}
Bool ArgCheckPointer(Arg arg)
{
CHECKL(arg != NULL);
return TRUE;
}
Bool ArgCheckRankSet(Arg arg)
{
CHECKL(COMPATTYPE(RankSet, unsigned));
CHECKL(RankSetCheck(arg->val.u));
return TRUE;
}
Bool ArgCheckRank(Arg arg)
{
CHECKL(RankCheck(arg->val.rank));
return TRUE;
}
Bool ArgCheckdouble(Arg arg)
{
/* Don't call isfinite() here because it's not in C89, and because
infinity is a valid value for MPS_KEY_PAUSE_TIME. */
UNUSED(arg);
return TRUE;
}
Bool ArgCheckPool(Arg arg)
{
CHECKD(Pool, arg->val.pool);
return TRUE;
}
ARG_DEFINE_KEY(ARGS_END, Shouldnt);
ArgStruct mps_args_none[] = {{MPS_KEY_ARGS_END, {0}}};
/* KeyCheck -- check the validity of an argument key */
Bool KeyCheck(Key key)
{
CHECKS(Key, key);
CHECKL(key->name != NULL);
CHECKL(FUNCHECK(key->check));
return TRUE;
}
Bool ArgCheck(Arg arg)
{
CHECKL(arg != NULL);
CHECKD(Key, arg->key);
CHECKL(arg->key->check(arg));
return TRUE;
}
/* ArgCheck -- check the validity of an argument list */
Bool ArgListCheck(ArgList args)
{
Index i;
CHECKL(args != NULL);
for (i = 0; args[i].key != MPS_KEY_ARGS_END; ++i) {
CHECKL(i < MPS_ARGS_MAX);
CHECKD_NOSIG(Arg, &args[i]);
}
return TRUE;
}
/* ArgPick -- try to pick an argument out of the argument list by keyword */
Bool ArgPick(ArgStruct *argOut, ArgList args, Key key)
{
Index i;
AVER(argOut != NULL);
AVERT(ArgList, args);
AVERT(Key, key);
for (i = 0; args[i].key != MPS_KEY_ARGS_END; ++i)
if (args[i].key == key)
goto found;
return FALSE;
found:
AVERT(Arg, &args[i]);
*argOut = args[i];
for(;;) {
args[i] = args[i + 1];
if (args[i].key == MPS_KEY_ARGS_END)
break;
++i;
}
return TRUE;
}
/* ArgRequire -- take a required argument out of the argument list by keyword */
void ArgRequire(ArgStruct *argOut, ArgList args, Key key)
{
Bool b = ArgPick(argOut, args, key);
ASSERT(b, key->name);
}
/* ArgTrivVarargs -- class method to ignore deprecated varargs */
void ArgTrivVarargs(ArgStruct args[MPS_ARGS_MAX], va_list varargs)
{
UNUSED(varargs);
args[0].key = MPS_KEY_ARGS_END;
AVERT(ArgList, args);
}
/* C. COPYRIGHT AND LICENSE
*
* Copyright (C) 2001-2020 Ravenbrook Limited <https://www.ravenbrook.com/>.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
|