#ifndef SCM_VALIDATE_H
#define SCM_VALIDATE_H
-/* Copyright (C) 1999,2000,2001, 2002, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 1999, 2000, 2001, 2002, 2004, 2006, 2007, 2009,
+ * 2012 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3 of
+ * the License, or (at your option) any later version.
*
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
*/
/* Written by Greg J. Badros <gjb@cs.washington.edu>, Dec-1999 */
#define SCM_NUM2ULONG_LONG_DEF(pos, arg, def) \
(SCM_UNBNDP (arg) ? def : scm_to_ulong_long (arg))
-#define SCM_NUM2FLOAT(pos, arg) \
- (scm_num2float (arg, pos, FUNC_NAME))
+#define SCM_NUM2FLOAT(pos, arg) ((float) scm_to_double (arg))
-#define SCM_NUM2DOUBLE(pos, arg) \
- (scm_num2double (arg, pos, FUNC_NAME))
+#define SCM_NUM2DOUBLE(pos, arg) (scm_to_double (arg))
#define SCM_OUT_OF_RANGE(pos, arg) \
do { scm_out_of_range_pos (FUNC_NAME, arg, scm_from_int (pos)); } while (0)
-#define SCM_ASSERT_RANGE(pos, arg, f) \
- do { if (!(f)) scm_out_of_range_pos (FUNC_NAME, arg, scm_from_int (pos)); } while (0)
+#define SCM_ASSERT_RANGE(pos, arg, f) \
+ do { if (SCM_UNLIKELY (!(f))) \
+ scm_out_of_range_pos (FUNC_NAME, arg, scm_from_int (pos)); } \
+ while (0)
#define SCM_MUST_MALLOC_TYPE(type) \
((type *) scm_must_malloc (sizeof (type), FUNC_NAME))
SCM_ASSERT_TYPE (SCM_ ## pred (var), var, pos, FUNC_NAME, #pred); \
} while (0)
-#define SCM_MAKE_VALIDATE_MSG(pos, var, pred, msg) \
+#define SCM_I_MAKE_VALIDATE_MSG2(pos, var, pred, msg) \
do { \
- SCM_ASSERT_TYPE (SCM_ ## pred (var), var, pos, FUNC_NAME, msg); \
+ SCM_ASSERT_TYPE (pred (var), var, pos, FUNC_NAME, msg); \
} while (0)
+#define SCM_MAKE_VALIDATE_MSG(pos, var, pred, msg) \
+ SCM_I_MAKE_VALIDATE_MSG2 (pos, var, SCM_ ## pred, msg)
+
+
\f
#define SCM_VALIDATE_REST_ARGUMENT(x) \
cvar = scm_to_bool (flag); \
} while (0)
+#define SCM_VALIDATE_BYTEVECTOR(_pos, _obj) \
+ SCM_ASSERT_TYPE (SCM_BYTEVECTOR_P (_obj), (_obj), (_pos), \
+ FUNC_NAME, "bytevector")
+
#define SCM_VALIDATE_CHAR(pos, scm) SCM_MAKE_VALIDATE_MSG (pos, scm, CHARP, "character")
#define SCM_VALIDATE_CHAR_COPY(pos, scm, cvar) \
} \
} while (0)
-#define SCM_VALIDATE_NULL(pos, scm) SCM_MAKE_VALIDATE_MSG (pos, scm, NULLP, "null")
+#define SCM_VALIDATE_NULL(pos, scm) \
+ SCM_I_MAKE_VALIDATE_MSG2 (pos, scm, scm_is_null, "empty list")
-#define SCM_VALIDATE_NULL_OR_NIL(pos, scm) SCM_MAKE_VALIDATE_MSG (pos, scm, NULL_OR_NIL_P, "null")
+#define SCM_VALIDATE_NULL_OR_NIL(pos, scm) \
+ SCM_MAKE_VALIDATE_MSG (pos, scm, NULL_OR_NIL_P, "empty list")
-#define SCM_VALIDATE_CONS(pos, scm) SCM_MAKE_VALIDATE_MSG (pos, scm, CONSP, "pair")
+#define SCM_VALIDATE_CONS(pos, scm) \
+ SCM_I_MAKE_VALIDATE_MSG2 (pos, scm, scm_is_pair, "pair")
#define SCM_VALIDATE_LIST(pos, lst) \
do { \
#define SCM_VALIDATE_ALISTCELL(pos, alist) \
do { \
- SCM_ASSERT (SCM_CONSP (alist) && SCM_CONSP (SCM_CAR (alist)), \
+ SCM_ASSERT (scm_is_pair (alist) && scm_is_pair (SCM_CAR (alist)), \
alist, pos, FUNC_NAME); \
} while (0)
#define SCM_VALIDATE_ALISTCELL_COPYSCM(pos, alist, cvar) \
do { \
- SCM_ASSERT (SCM_CONSP (alist), alist, pos, FUNC_NAME); \
+ SCM_ASSERT (scm_is_pair (alist), alist, pos, FUNC_NAME); \
cvar = SCM_CAR (alist); \
- SCM_ASSERT (SCM_CONSP (cvar), alist, pos, FUNC_NAME); \
+ SCM_ASSERT (scm_is_pair (cvar), alist, pos, FUNC_NAME); \
} while (0)
#define SCM_VALIDATE_OPORT_VALUE(pos, port) \
#define SCM_VALIDATE_SMOB(pos, obj, type) \
do { \
- SCM_ASSERT (SCM_TYP16_PREDICATE (scm_tc16_ ## type, obj), \
+ SCM_ASSERT (SCM_SMOB_PREDICATE (scm_tc16_ ## type, obj), \
obj, pos, FUNC_NAME); \
} while (0)
#define SCM_VALIDATE_VARIABLE(pos, var) SCM_MAKE_VALIDATE_MSG (pos, var, VARIABLEP, "variable")
-#define SCM_VALIDATE_MEMOIZED(pos, obj) SCM_MAKE_VALIDATE_MSG (pos, obj, MEMOIZEDP, "memoized code")
-
-#define SCM_VALIDATE_CLOSURE(pos, obj) SCM_MAKE_VALIDATE_MSG (pos, obj, CLOSUREP, "closure")
+#define SCM_VALIDATE_MEMOIZED(pos, obj) SCM_MAKE_VALIDATE_MSG (pos, obj, MEMOIZED_P, "memoized code")
#define SCM_VALIDATE_PROC(pos, proc) \
do { \
#define SCM_VALIDATE_NULLORCONS(pos, env) \
do { \
- SCM_ASSERT (SCM_NULLP (env) || SCM_CONSP (env), env, pos, FUNC_NAME); \
+ SCM_ASSERT (scm_is_null (env) || scm_is_pair (env), env, pos, FUNC_NAME); \
} while (0)
#define SCM_VALIDATE_HOOK(pos, a) SCM_MAKE_VALIDATE_MSG (pos, a, HOOKP, "hook")
#define SCM_VALIDATE_OPOUTSTRPORT(pos, port) \
SCM_MAKE_VALIDATE_MSG (pos, port, OPOUTSTRPORTP, "open output string port")
-#define SCM_VALIDATE_FLUID(pos, fluid) SCM_MAKE_VALIDATE_MSG (pos, fluid, FLUIDP, "fluid")
+#define SCM_VALIDATE_FLUID(pos, fluid) \
+ SCM_I_MAKE_VALIDATE_MSG2 (pos, fluid, scm_is_fluid, "fluid")
#define SCM_VALIDATE_KEYWORD(pos, v) SCM_MAKE_VALIDATE_MSG (pos, v, KEYWORDP, "keyword")
v, pos, FUNC_NAME); \
} while (0)
-#define SCM_VALIDATE_VECTOR(pos, v) SCM_MAKE_VALIDATE_MSG (pos, v, VECTORP, "vector")
+#define SCM_VALIDATE_VECTOR(pos, v) \
+ do { \
+ SCM_ASSERT (scm_is_simple_vector (v), v, pos, FUNC_NAME); \
+ } while (0)
#define SCM_VALIDATE_VECTOR_OR_DVECTOR(pos, v) \
do { \
- SCM_ASSERT ((SCM_VECTORP (v) \
- || (!SCM_IMP (v) && SCM_TYP7 (v) == scm_tc7_dvect)), \
+ SCM_ASSERT ((scm_is_simple_vector (v) \
+ || (scm_is_true (scm_f64vector_p (v)))), \
v, pos, FUNC_NAME); \
} while (0)
#define SCM_VALIDATE_VTABLE(pos, v) \
do { \
- SCM_ASSERT (!SCM_IMP (v) && scm_is_true (scm_struct_vtable_p (v)), \
- v, pos, FUNC_NAME); \
+ SCM_ASSERT (scm_is_true (scm_struct_vtable_p (v)), v, pos, FUNC_NAME); \
} while (0)
#define SCM_VALIDATE_VECTOR_LEN(pos, v, len) \
do { \
- SCM_ASSERT (SCM_VECTORP (v) && len == SCM_VECTOR_LENGTH (v), v, pos, FUNC_NAME); \
+ SCM_ASSERT (scm_is_vector (v) && len == scm_c_vector_length (v), v, pos, FUNC_NAME); \
} while (0)