* Renamed header macros to the SCM_<filename>_H format.
[bpt/guile.git] / libguile / validate.h
CommitLineData
e4b265d8 1/* Copyright (C) 1999,2000,2001 Free Software Foundation, Inc.
e94e3f21 2 *
5bff3127
GB
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
6 * any later version.
e94e3f21 7 *
5bff3127
GB
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
e94e3f21 12 *
5bff3127
GB
13 * You should have received a copy of the GNU General Public License
14 * along with this software; see the file COPYING. If not, write to
15 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 * Boston, MA 02111-1307 USA
1bbd0b84 17 *
5bff3127
GB
18 * As a special exception, the Free Software Foundation gives permission
19 * for additional uses of the text contained in its release of GUILE.
20 *
21 * The exception is that, if you link the GUILE library with other files
22 * to produce an executable, this does not by itself cause the
23 * resulting executable to be covered by the GNU General Public License.
24 * Your use of that executable is in no way restricted on account of
25 * linking the GUILE library code into it.
26 *
27 * This exception does not however invalidate any other reasons why
28 * the executable file might be covered by the GNU General Public License.
29 *
30 * This exception applies only to the code released by the
31 * Free Software Foundation under the name GUILE. If you copy
32 * code from other Free Software Foundation releases into a copy of
33 * GUILE, as the General Public License permits, the exception does
34 * not apply to the code that you add in this way. To avoid misleading
35 * anyone as to the status of such modified files, you must delete
36 * this exception notice from them.
37 *
38 * If you write modifications of your own for GUILE, it is your choice
39 * whether to permit this exception to apply to your modifications.
40 * If you do not wish that, delete this exception notice. */
41
42/* Written by Greg J. Badros <gjb@cs.washington.edu>, Dec-1999 */
1bbd0b84
GB
43
44#ifndef SCM_VALIDATE_H__
45#define SCM_VALIDATE_H__
46
39bcc76e 47#define SCM_SYSERROR do { scm_syserror (FUNC_NAME); } while (0)
1bbd0b84 48
39bcc76e 49#define SCM_MEMORY_ERROR do { scm_memory_error (FUNC_NAME); } while (0)
1bbd0b84 50
39bcc76e
MD
51#define SCM_SYSERROR_MSG(str, args, val) \
52 do { scm_syserror_msg (FUNC_NAME, (str), (args), (val)); } while (0)
1bbd0b84 53
39bcc76e
MD
54#define SCM_MISC_ERROR(str, args) \
55 do { scm_misc_error (FUNC_NAME, str, args); } while (0)
1bbd0b84 56
398d8ee1 57#define SCM_WRONG_NUM_ARGS() \
68baa7e7 58 do { scm_error_num_args_subr (FUNC_NAME); } while (0)
398d8ee1 59
39bcc76e
MD
60#define SCM_WRONG_TYPE_ARG(pos, obj) \
61 do { scm_wrong_type_arg (FUNC_NAME, pos, obj); } while (0)
1bbd0b84 62
1be6b49c
ML
63#define SCM_NUM2SIZE(pos, arg) (scm_num2size (arg, pos, FUNC_NAME))
64
65#define SCM_NUM2SIZE_DEF(pos, arg, def) \
66 (SCM_UNBNDP (arg) ? def : scm_num2size (arg, pos, FUNC_NAME))
67
68#define SCM_NUM2PTRDIFF(pos, arg) (scm_num2ptrdiff (arg, pos, FUNC_NAME))
69
70#define SCM_NUM2PTRDIFF_DEF(pos, arg, def) \
71 (SCM_UNBNDP (arg) ? def : scm_num2ptrdiff (arg, pos, FUNC_NAME))
72
73#define SCM_NUM2SHORT(pos, arg) (scm_num2short (arg, pos, FUNC_NAME))
74
75#define SCM_NUM2SHORT_DEF(pos, arg, def) \
76 (SCM_UNBNDP (arg) ? def : scm_num2short (arg, pos, FUNC_NAME))
77
78#define SCM_NUM2USHORT(pos, arg) (scm_num2ushort (arg, pos, FUNC_NAME))
79
80#define SCM_NUM2USHORT_DEF(pos, arg, def) \
81 (SCM_UNBNDP (arg) ? def : scm_num2ushort (arg, pos, FUNC_NAME))
82
1be6b49c
ML
83#define SCM_NUM2INT(pos, arg) (scm_num2int (arg, pos, FUNC_NAME))
84
85#define SCM_NUM2INT_DEF(pos, arg, def) \
86 (SCM_UNBNDP (arg) ? def : scm_num2int (arg, pos, FUNC_NAME))
87
88#define SCM_NUM2UINT(pos, arg) (scm_num2uint (arg, pos, FUNC_NAME))
89
90#define SCM_NUM2UINT_DEF(pos, arg, def) \
91 (SCM_UNBNDP (arg) ? def : scm_num2uint (arg, pos, FUNC_NAME))
92
e4b265d8 93#define SCM_NUM2ULONG(pos, arg) (scm_num2ulong (arg, pos, FUNC_NAME))
1bbd0b84 94
1be6b49c
ML
95#define SCM_NUM2ULONG_DEF(pos, arg, def) \
96 (SCM_UNBNDP (arg) ? def : scm_num2ulong (arg, pos, FUNC_NAME))
97
e4b265d8 98#define SCM_NUM2LONG(pos, arg) (scm_num2long (arg, pos, FUNC_NAME))
1bbd0b84 99
39bcc76e 100#define SCM_NUM2LONG_DEF(pos, arg, def) \
e4b265d8 101 (SCM_UNBNDP (arg) ? def : scm_num2long (arg, pos, FUNC_NAME))
c1bfcf60 102
39bcc76e 103#define SCM_NUM2LONG_LONG(pos, arg) \
e4b265d8 104 (scm_num2long_long (arg, pos, FUNC_NAME))
1bbd0b84 105
1be6b49c
ML
106#define SCM_NUM2LONG_LONG_DEF(pos, arg, def) \
107 (SCM_UNBNDP (arg) ? def : scm_num2long_long (arg, pos, FUNC_NAME))
108
109#define SCM_NUM2ULONG_LONG(pos, arg) \
110 (scm_num2ulong_long (arg, pos, FUNC_NAME))
111
112#define SCM_NUM2ULONG_LONG_DEF(pos, arg, def) \
113 (SCM_UNBNDP (arg) ? def : scm_num2ulong_long (arg, pos, FUNC_NAME))
114
39bcc76e
MD
115#define SCM_OUT_OF_RANGE(pos, arg) \
116 do { scm_out_of_range_pos (FUNC_NAME, arg, SCM_MAKINUM (pos)); } while (0)
1bbd0b84 117
39bcc76e 118#define SCM_ASSERT_RANGE(pos, arg, f) \
23deee81 119 do { if (!(f)) scm_out_of_range_pos (FUNC_NAME, arg, SCM_MAKINUM (pos)); } while (0)
1bbd0b84 120
39bcc76e
MD
121#define SCM_MUST_MALLOC_TYPE(type) \
122 ((type *) scm_must_malloc (sizeof (type), FUNC_NAME))
1bbd0b84 123
39bcc76e
MD
124#define SCM_MUST_MALLOC_TYPE_NUM(type, num) \
125 ((type *) scm_must_malloc (sizeof (type) * (num), FUNC_NAME))
1bbd0b84 126
39bcc76e 127#define SCM_MUST_MALLOC(size) (scm_must_malloc ((size), FUNC_NAME))
1bbd0b84 128
39bcc76e
MD
129#define SCM_MAKE_VALIDATE(pos, var, pred) \
130 do { \
131 SCM_ASSERT_TYPE (SCM_ ## pred (var), var, pos, FUNC_NAME, #pred); \
132 } while (0)
6b5a304f 133
6e8d25a6
GB
134\f
135
af45e3b0
DH
136#define SCM_VALIDATE_REST_ARGUMENT(x) \
137 do { \
138 if (SCM_DEBUG_REST_ARGUMENT) { \
139 if (scm_ilength (x) < 0) { \
140 SCM_MISC_ERROR ("Rest arguments do not form a proper list.", SCM_EOL); \
141 } \
142 } \
143 } while (0)
144
39bcc76e 145#define SCM_VALIDATE_NIM(pos, scm) SCM_MAKE_VALIDATE (pos, scm, NIMP)
6e8d25a6 146
39bcc76e 147#define SCM_VALIDATE_BOOL(pos, flag) SCM_MAKE_VALIDATE(pos, flag, BOOLP)
1bbd0b84 148
39bcc76e
MD
149#define SCM_VALIDATE_BOOL_COPY(pos, flag, cvar) \
150 do { \
151 SCM_ASSERT (SCM_BOOLP (flag), flag, pos, FUNC_NAME); \
9a09deb1 152 cvar = SCM_EQ_P (flag, SCM_BOOL_T) ? 1 : 0; \
39bcc76e 153 } while (0)
1bbd0b84 154
f5f2dcff 155#define SCM_VALIDATE_CHAR(pos, scm) SCM_MAKE_VALIDATE (pos, scm, CHARP)
1bbd0b84 156
39bcc76e
MD
157#define SCM_VALIDATE_CHAR_COPY(pos, scm, cvar) \
158 do { \
159 SCM_ASSERT (SCM_CHARP (scm), scm, pos, FUNC_NAME); \
160 cvar = SCM_CHAR (scm); \
161 } while (0)
1bbd0b84 162
39bcc76e 163#define SCM_VALIDATE_STRING(pos, str) SCM_MAKE_VALIDATE (pos, str, STRINGP)
1bbd0b84 164
39bcc76e
MD
165#define SCM_VALIDATE_STRING_COPY(pos, str, cvar) \
166 do { \
167 SCM_ASSERT (SCM_STRINGP (str), str, pos, FUNC_NAME); \
86c991c2 168 cvar = SCM_STRING_CHARS(str); \
39bcc76e 169 } while (0)
1bbd0b84 170
60d02d09
GH
171/* validate a string and optional start/end arguments which default to
172 0/string-len. this is unrelated to the old shared substring
173 support, so please do not deprecate it :) */
174#define SCM_VALIDATE_SUBSTRING_SPEC_COPY(pos_str, str, c_str, \
175 pos_start, start, c_start,\
176 pos_end, end, c_end) \
177 do {\
178 SCM_VALIDATE_STRING_COPY (pos_str, str, c_str);\
179 SCM_VALIDATE_INUM_DEF_COPY (pos_start, start, 0, c_start);\
180 SCM_VALIDATE_INUM_DEF_COPY (pos_end, end, SCM_STRING_LENGTH (str), c_end);\
181 SCM_ASSERT_RANGE (pos_start, start,\
36284627
DH
182 0 <= c_start \
183 && (size_t) c_start <= SCM_STRING_LENGTH (str));\
60d02d09 184 SCM_ASSERT_RANGE (pos_end, end,\
36284627
DH
185 c_start <= c_end \
186 && (size_t) c_end <= SCM_STRING_LENGTH (str));\
60d02d09
GH
187 } while (0)
188
39bcc76e 189#define SCM_VALIDATE_REAL(pos, z) SCM_MAKE_VALIDATE (pos, z, REALP)
1bbd0b84 190
e8a46ba8
MV
191#define SCM_VALIDATE_NUMBER(pos, z) SCM_MAKE_VALIDATE (pos, z, NUMBERP)
192
39bcc76e 193#define SCM_VALIDATE_INUM(pos, k) SCM_MAKE_VALIDATE (pos, k, INUMP)
1bbd0b84 194
39bcc76e
MD
195#define SCM_VALIDATE_INUM_COPY(pos, k, cvar) \
196 do { \
197 SCM_ASSERT (SCM_INUMP (k), k, pos, FUNC_NAME); \
198 cvar = SCM_INUM (k); \
199 } while (0)
1bbd0b84 200
d098d810
TTN
201#define SCM_VALIDATE_USHORT_COPY(pos, k, cvar) \
202 do { \
203 cvar = SCM_NUM2USHORT (pos, k); \
204 } while (0)
205
206#define SCM_VALIDATE_SHORT_COPY(pos, k, cvar) \
207 do { \
208 cvar = SCM_NUM2SHORT (pos, k); \
209 } while (0)
210
211#define SCM_VALIDATE_UINT_COPY(pos, k, cvar) \
212 do { \
213 cvar = SCM_NUM2UINT (pos, k); \
214 } while (0)
215
216#define SCM_VALIDATE_INT_COPY(pos, k, cvar) \
217 do { \
218 cvar = SCM_NUM2INT (pos, k); \
219 } while (0)
220
39bcc76e
MD
221#define SCM_VALIDATE_ULONG_COPY(pos, k, cvar) \
222 do { \
223 cvar = SCM_NUM2ULONG (pos, k); \
224 } while (0)
2cd04b42 225
39bcc76e
MD
226#define SCM_VALIDATE_LONG_COPY(pos, k, cvar) \
227 do { \
e4b265d8 228 cvar = SCM_NUM2LONG (pos, k); \
39bcc76e 229 } while (0)
2cd04b42 230
39bcc76e 231#define SCM_VALIDATE_BIGINT(pos, k) SCM_MAKE_VALIDATE (pos, k, BIGP)
1bbd0b84 232
39bcc76e
MD
233#define SCM_VALIDATE_INUM_MIN(pos, k, min) \
234 do { \
235 SCM_ASSERT (SCM_INUMP(k), k, pos, FUNC_NAME); \
236 SCM_ASSERT_RANGE (pos, k, (SCM_INUM (k) >= min)); \
237 } while (0)
1bbd0b84 238
39bcc76e
MD
239#define SCM_VALIDATE_INUM_MIN_COPY(pos, k, min, cvar) \
240 do { \
241 SCM_ASSERT (SCM_INUMP (k), k, pos, FUNC_NAME); \
fdf25853 242 SCM_ASSERT_RANGE (pos, k, (SCM_INUM (k) >= min)); \
39bcc76e 243 cvar = SCM_INUM (k); \
39bcc76e 244 } while (0)
1bbd0b84 245
39bcc76e
MD
246#define SCM_VALIDATE_INUM_MIN_DEF_COPY(pos, k, min, default, cvar) \
247 do { \
248 if (SCM_UNBNDP (k)) \
249 k = SCM_MAKINUM (default); \
250 SCM_ASSERT (SCM_INUMP (k), k, pos, FUNC_NAME); \
fdf25853 251 SCM_ASSERT_RANGE (pos, k, (SCM_INUM (k) >= min)); \
39bcc76e 252 cvar = SCM_INUM (k); \
39bcc76e 253 } while (0)
1bbd0b84 254
39bcc76e
MD
255#define SCM_VALIDATE_INUM_DEF(pos, k, default) \
256 do { \
257 if (SCM_UNBNDP (k)) \
258 k = SCM_MAKINUM (default); \
259 else SCM_ASSERT (SCM_INUMP (k), k, pos, FUNC_NAME); \
260 } while (0)
1bbd0b84 261
39bcc76e
MD
262#define SCM_VALIDATE_INUM_DEF_COPY(pos, k, default, cvar) \
263 do { \
264 if (SCM_UNBNDP (k)) \
265 { \
266 k = SCM_MAKINUM (default); \
267 cvar = default; \
268 } \
269 else \
270 { \
271 SCM_ASSERT (SCM_INUMP (k), k, pos, FUNC_NAME); \
272 cvar = SCM_INUM (k); \
273 } \
274 } while (0)
1bbd0b84
GB
275
276/* [low,high) */
120d4924
GB
277#define SCM_VALIDATE_INUM_RANGE(pos,k,low,high) \
278 do { SCM_ASSERT(SCM_INUMP(k), k, pos, FUNC_NAME); \
279 SCM_ASSERT_RANGE(pos,k, \
280 (SCM_INUM (k) >= low && \
281 SCM_INUM (k) < high)); \
282 } while (0)
39bcc76e 283
7642eb4b
MD
284#define SCM_VALIDATE_INUM_RANGE_COPY(pos, k, low, high, cvar) \
285 do { \
286 SCM_ASSERT (SCM_INUMP (k), k, pos, FUNC_NAME); \
fdf25853 287 SCM_ASSERT_RANGE (pos, k, low <= SCM_INUM (k) && SCM_INUM (k) < high); \
7642eb4b 288 cvar = SCM_INUM (k); \
7642eb4b
MD
289 } while (0)
290
39bcc76e 291#define SCM_VALIDATE_NULL(pos, scm) SCM_MAKE_VALIDATE (pos, scm, NULLP)
1bbd0b84 292
39bcc76e 293#define SCM_VALIDATE_CONS(pos, scm) SCM_MAKE_VALIDATE (pos, scm, CONSP)
1bbd0b84 294
39bcc76e
MD
295#define SCM_VALIDATE_LIST(pos, lst) \
296 do { \
297 SCM_ASSERT (scm_ilength (lst) >= 0, lst, pos, FUNC_NAME); \
298 } while (0)
1bbd0b84 299
39bcc76e
MD
300#define SCM_VALIDATE_NONEMPTYLIST(pos, lst) \
301 do { \
302 SCM_ASSERT (scm_ilength (lst) > 0, lst, pos, FUNC_NAME); \
303 } while (0)
1bbd0b84 304
39bcc76e
MD
305#define SCM_VALIDATE_LIST_COPYLEN(pos, lst, cvar) \
306 do { \
307 cvar = scm_ilength (lst); \
308 SCM_ASSERT (cvar >= 0, lst, pos, FUNC_NAME); \
309 } while (0)
c1bfcf60 310
39bcc76e
MD
311#define SCM_VALIDATE_NONEMPTYLIST_COPYLEN(pos, lst, cvar) \
312 do { \
313 cvar = scm_ilength (lst); \
314 SCM_ASSERT (cvar >= 1, lst, pos, FUNC_NAME); \
315 } while (0)
1bbd0b84 316
39bcc76e
MD
317#define SCM_VALIDATE_ALISTCELL(pos, alist) \
318 do { \
319 SCM_ASSERT (SCM_CONSP (alist) && SCM_CONSP (SCM_CAR (alist)), \
320 alist, pos, FUNC_NAME); \
321 } while (0)
1bbd0b84 322
39bcc76e 323#define SCM_VALIDATE_ALISTCELL_COPYSCM(pos, alist, cvar) \
1bbd0b84 324 do { \
39bcc76e
MD
325 SCM_ASSERT (SCM_CONSP (alist), alist, pos, FUNC_NAME); \
326 cvar = SCM_CAR (alist); \
327 SCM_ASSERT (SCM_CONSP (cvar), alist, pos, FUNC_NAME); \
30939477 328 } while (0)
1bbd0b84 329
39bcc76e 330#define SCM_VALIDATE_OPORT_VALUE(pos, port) \
1bbd0b84 331 do { \
39bcc76e
MD
332 SCM_ASSERT (scm_valid_oport_value_p (port), port, pos, FUNC_NAME); \
333 } while (0)
334
335#define SCM_VALIDATE_PRINTSTATE(pos, a) SCM_MAKE_VALIDATE(pos,a,PRINT_STATE_P)
1bbd0b84 336
39bcc76e
MD
337#define SCM_VALIDATE_SMOB(pos, obj, type) \
338 do { \
e841c3e0 339 SCM_ASSERT (SCM_TYP16_PREDICATE (scm_tc16_ ## type, obj), \
39bcc76e
MD
340 obj, pos, FUNC_NAME); \
341 } while (0)
1bbd0b84 342
39bcc76e 343#define SCM_VALIDATE_THREAD(pos, a) SCM_MAKE_VALIDATE (pos, a, THREADP)
1bbd0b84 344
39bcc76e
MD
345#define SCM_VALIDATE_THUNK(pos, thunk) \
346 do { \
347 SCM_ASSERT (SCM_NFALSEP (scm_thunk_p (thunk)), thunk, pos, FUNC_NAME); \
348 } while (0)
1bbd0b84 349
39bcc76e 350#define SCM_VALIDATE_SYMBOL(pos, sym) SCM_MAKE_VALIDATE (pos, sym, SYMBOLP)
0c95b57d 351
39bcc76e 352#define SCM_VALIDATE_VARIABLE(pos, var) SCM_MAKE_VALIDATE (pos, var, VARIABLEP)
1bbd0b84 353
39bcc76e 354#define SCM_VALIDATE_MEMOIZED(pos, obj) SCM_MAKE_VALIDATE (pos, obj, MEMOIZEDP)
1bbd0b84 355
39bcc76e 356#define SCM_VALIDATE_CLOSURE(pos, obj) SCM_MAKE_VALIDATE (pos, obj, CLOSUREP)
1bbd0b84 357
39bcc76e
MD
358#define SCM_VALIDATE_PROC(pos, proc) \
359 do { \
9a09deb1 360 SCM_ASSERT (SCM_EQ_P (scm_procedure_p (proc), SCM_BOOL_T), proc, pos, FUNC_NAME); \
39bcc76e 361 } while (0)
1bbd0b84 362
39bcc76e
MD
363#define SCM_VALIDATE_NULLORCONS(pos, env) \
364 do { \
365 SCM_ASSERT (SCM_NULLP (env) || SCM_CONSP (env), env, pos, FUNC_NAME); \
366 } while (0)
1bbd0b84 367
39bcc76e 368#define SCM_VALIDATE_HOOK(pos, a) SCM_MAKE_VALIDATE (pos, a, HOOKP)
1bbd0b84 369
39bcc76e 370#define SCM_VALIDATE_RGXP(pos, a) SCM_MAKE_VALIDATE (pos, a, RGXP)
1bbd0b84 371
39bcc76e 372#define SCM_VALIDATE_DIR(pos, port) SCM_MAKE_VALIDATE (pos, port, DIRP)
1bbd0b84 373
39bcc76e 374#define SCM_VALIDATE_PORT(pos, port) SCM_MAKE_VALIDATE (pos, port, PORTP)
1bbd0b84 375
39bcc76e
MD
376#define SCM_VALIDATE_INPUT_PORT(pos, port) \
377 SCM_MAKE_VALIDATE (pos, port, INPUT_PORT_P)
1bbd0b84 378
39bcc76e
MD
379#define SCM_VALIDATE_OUTPUT_PORT(pos, port) \
380 SCM_MAKE_VALIDATE (pos, port, OUTPUT_PORT_P)
1bbd0b84 381
39bcc76e 382#define SCM_VALIDATE_FPORT(pos, port) SCM_MAKE_VALIDATE (pos, port, FPORTP)
1bbd0b84 383
39bcc76e 384#define SCM_VALIDATE_OPFPORT(pos, port) SCM_MAKE_VALIDATE (pos, port, OPFPORTP)
1bbd0b84 385
39bcc76e
MD
386#define SCM_VALIDATE_OPINPORT(pos, port) \
387 SCM_MAKE_VALIDATE (pos, port, OPINPORTP)
1bbd0b84
GB
388
389#define SCM_VALIDATE_OPENPORT(pos,port) \
39bcc76e
MD
390 do { \
391 SCM_ASSERT (SCM_PORTP (port) && SCM_OPENP (port), \
392 port, pos, FUNC_NAME); \
393 } while (0)
1bbd0b84 394
39bcc76e 395#define SCM_VALIDATE_OPPORT(pos, port) SCM_MAKE_VALIDATE (pos, port, OPPORTP)
1bbd0b84 396
39bcc76e
MD
397#define SCM_VALIDATE_OPOUTPORT(pos, port) \
398 SCM_MAKE_VALIDATE (pos, port, OPOUTPORTP)
1bbd0b84 399
e87a03fc
MG
400#define SCM_VALIDATE_OPOUTSTRPORT(pos, port) \
401 SCM_MAKE_VALIDATE (pos, port, OPOUTSTRPORTP)
402
39bcc76e 403#define SCM_VALIDATE_FLUID(pos, fluid) SCM_MAKE_VALIDATE (pos, fluid, FLUIDP)
1bbd0b84 404
39bcc76e 405#define SCM_VALIDATE_KEYWORD(pos, v) SCM_MAKE_VALIDATE (pos, v, KEYWORDP)
1bbd0b84 406
39bcc76e 407#define SCM_VALIDATE_STACK(pos, v) SCM_MAKE_VALIDATE (pos, v, STACKP)
1bbd0b84 408
39bcc76e 409#define SCM_VALIDATE_FRAME(pos, v) SCM_MAKE_VALIDATE (pos, v, FRAMEP)
1bbd0b84 410
39bcc76e 411#define SCM_VALIDATE_RSTATE(pos, v) SCM_MAKE_VALIDATE (pos, v, RSTATEP)
1bbd0b84
GB
412
413#define SCM_VALIDATE_ARRAY(pos,v) \
39bcc76e
MD
414 do { \
415 SCM_ASSERT (SCM_NIMP (v) \
416 && !SCM_FALSEP (scm_array_p (v, SCM_UNDEFINED)), \
417 v, pos, FUNC_NAME); \
418 } while (0)
1bbd0b84 419
39bcc76e 420#define SCM_VALIDATE_VECTOR(pos, v) SCM_MAKE_VALIDATE (pos, v, VECTORP)
1bbd0b84 421
39bcc76e
MD
422#define SCM_VALIDATE_VECTOR_OR_DVECTOR(pos, v) \
423 do { \
424 SCM_ASSERT ((SCM_VECTORP (v) \
425 || (SCM_NIMP (v) && SCM_TYP7 (v) == scm_tc7_dvect)), \
426 v, pos, FUNC_NAME); \
427 } while (0)
368cf54d 428
39bcc76e 429#define SCM_VALIDATE_STRUCT(pos, v) SCM_MAKE_VALIDATE (pos, v, STRUCTP)
1bbd0b84 430
39bcc76e
MD
431#define SCM_VALIDATE_VTABLE(pos, v) \
432 do { \
433 SCM_ASSERT (SCM_NIMP (v) && SCM_NFALSEP (scm_struct_vtable_p (v)), \
434 v, pos, FUNC_NAME); \
435 } while (0)
1bbd0b84 436
39bcc76e
MD
437#define SCM_VALIDATE_VECTOR_LEN(pos, v, len) \
438 do { \
9fd38a3d 439 SCM_ASSERT (SCM_VECTORP (v) && len == SCM_VECTOR_LENGTH (v), v, pos, FUNC_NAME); \
39bcc76e 440 } while (0)
1bbd0b84 441
d1ca2c64
DH
442\f
443
444#if (SCM_DEBUG_DEPRECATED == 0)
445
b3fcac34
DH
446#define SCM_FUNC_NAME (scm_makfrom0str (FUNC_NAME))
447
276dd677
DH
448#define SCM_WTA(pos, scm) \
449 do { scm_wta (scm, (char *) pos, FUNC_NAME); } while (0)
450
451#define RETURN_SCM_WTA(pos, scm) \
452 do { return scm_wta (scm, (char *) pos, FUNC_NAME); } while (0)
453
b3fcac34
DH
454#define SCM_VALIDATE_NUMBER_COPY(pos, z, cvar) \
455 do { \
456 if (SCM_INUMP (z)) \
457 cvar = (double) SCM_INUM (z); \
458 else if (SCM_REALP (z)) \
459 cvar = SCM_REAL_VALUE (z); \
460 else if (SCM_BIGP (z)) \
1be6b49c 461 cvar = scm_i_big2dbl (z); \
b3fcac34
DH
462 else \
463 { \
464 cvar = 0.0; \
465 SCM_WRONG_TYPE_ARG (pos, z); \
466 } \
467 } while (0)
468
469#define SCM_VALIDATE_NUMBER_DEF_COPY(pos, number, def, cvar) \
470 do { \
471 if (SCM_UNBNDP (number)) \
472 cvar = def; \
473 else \
474 SCM_VALIDATE_NUMBER_COPY(pos, number, cvar); \
475 } while (0)
476
d1ca2c64
DH
477#define SCM_VALIDATE_STRINGORSUBSTR SCM_VALIDATE_STRING
478
a6d9e5ab
DH
479#define SCM_VALIDATE_ROSTRING(pos, str) SCM_MAKE_VALIDATE (pos, str, ROSTRINGP)
480
481#define SCM_VALIDATE_ROSTRING_COPY(pos, str, cvar) \
482 do { \
483 SCM_ASSERT (SCM_ROSTRINGP (str), str, pos, FUNC_NAME); \
484 cvar = SCM_ROCHARS (str); \
485 } while (0)
486
487#define SCM_VALIDATE_NULLORROSTRING_COPY(pos, str, cvar) \
488 do { \
489 SCM_ASSERT (SCM_FALSEP (str) || SCM_ROSTRINGP (str), \
490 str, pos, FUNC_NAME); \
491 if (SCM_FALSEP(str)) \
492 cvar = NULL; \
493 else \
494 cvar = SCM_ROCHARS(str); \
495 } while (0)
496
395d8627
DH
497#define SCM_VALIDATE_RWSTRING(pos, str) \
498 do { \
499 SCM_ASSERT (SCM_STRINGP (str), str, pos, FUNC_NAME); \
500 if (!SCM_RWSTRINGP (str)) \
501 scm_misc_error (FUNC_NAME, "argument is a read-only string", str); \
502 } while (0)
503
30ea841d
DH
504#define SCM_VALIDATE_OPDIR(pos, port) SCM_MAKE_VALIDATE (pos, port, OPDIRP)
505
d1ca2c64
DH
506#endif /* SCM_DEBUG_DEPRECATED == 0 */
507
1bbd0b84 508#endif
89e00824
ML
509
510/*
511 Local Variables:
512 c-file-style: "gnu"
513 End:
514*/