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