1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

More validate.h devolution

* libguile/validate.h:
* libguile/alist.h (SCM_VALIDATE_ALISTCELL, SCM_VALIDATE_ALISTCELL_COPYSCM)
* libguile/bytevectors.h (SCM_VALIDATE_BYTEVECTOR)
* libguile/chars.h (SCM_VALIDATE_CHAR, SCM_VALIDATE_CHAR_COPY):
* libguile/print.h (SCM_VALIDATE_OPORT_VALUE, SCM_VALIDATE_PRINTSTATE):
* libguile/procs.h (SCM_VALIDATE_THUNK)
* libguile/smob.h (SCM_VALIDATE_SMOB)
* libguile/strings.h (SCM_VALIDATE_STRING): Devolve these macros from
  validate.h.
This commit is contained in:
Andy Wingo 2018-06-18 09:44:35 +02:00
parent be18b50773
commit 8a6f46ee96
8 changed files with 77 additions and 57 deletions

View file

@ -3,7 +3,8 @@
#ifndef SCM_ALIST_H
#define SCM_ALIST_H
/* Copyright (C) 1995,1996,2000, 2006, 2008 Free Software Foundation, Inc.
/* Copyright (C) 1995-1996,2000,2006,2008,2018
* 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
@ -24,6 +25,25 @@
#include "libguile/__scm.h"
#include <libguile/error.h>
#include "libguile/pairs.h"
#define SCM_VALIDATE_ALISTCELL(pos, alist) \
do { \
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_is_pair (alist), alist, pos, FUNC_NAME); \
cvar = SCM_CAR (alist); \
SCM_ASSERT (scm_is_pair (cvar), alist, pos, FUNC_NAME); \
} while (0)

View file

@ -22,6 +22,7 @@
#include "libguile/__scm.h"
#include <libguile/error.h>
#include "libguile/uniform.h"
@ -146,6 +147,10 @@ SCM_API SCM scm_utf32_to_string (SCM, SCM);
/* Hint that is passed to `scm_gc_malloc ()' and friends. */
#define SCM_GC_BYTEVECTOR "bytevector"
#define SCM_VALIDATE_BYTEVECTOR(_pos, _obj) \
SCM_ASSERT_TYPE (SCM_BYTEVECTOR_P (_obj), (_obj), (_pos), \
FUNC_NAME, "bytevector")
SCM_INTERNAL SCM scm_i_make_typed_bytevector (size_t, scm_t_array_element_type);
SCM_INTERNAL SCM scm_c_take_typed_bytevector (signed char *, size_t,
scm_t_array_element_type, SCM);

View file

@ -3,7 +3,8 @@
#ifndef SCM_CHARS_H
#define SCM_CHARS_H
/* Copyright (C) 1995,1996,2000,2001,2004, 2006, 2008, 2009 Free Software Foundation, Inc.
/* Copyright (C) 1995-1996,2000-2001,2004,2006,2008-2009,2018
* 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
@ -24,6 +25,7 @@
#include "libguile/__scm.h"
#include <libguile/error.h>
#ifndef SCM_T_WCHAR_DEFINED
typedef scm_t_int32 scm_t_wchar;
@ -57,6 +59,14 @@ typedef scm_t_int32 scm_t_wchar;
|| ((scm_t_wchar) (c) > SCM_CODEPOINT_SURROGATE_END \
&& (scm_t_wchar) (c) <= SCM_CODEPOINT_MAX))
#define SCM_VALIDATE_CHAR(pos, scm) SCM_MAKE_VALIDATE_MSG (pos, scm, CHARP, "character")
#define SCM_VALIDATE_CHAR_COPY(pos, scm, cvar) \
do { \
SCM_ASSERT (SCM_CHARP (scm), scm, pos, FUNC_NAME); \
cvar = SCM_CHAR (scm); \
} while (0)
SCM_API SCM scm_char_p (SCM x);

View file

@ -3,8 +3,8 @@
#ifndef SCM_PRINT_H
#define SCM_PRINT_H
/* Copyright (C) 1995, 1996, 1998, 2000, 2001, 2003, 2004, 2006, 2008,
* 2010, 2012, 2017 Free Software Foundation, Inc.
/* Copyright (C) 1995-1996,1998,2000-2001,2003-2004,2006,2008,
* 2010,2012,2017-2018 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
@ -27,7 +27,9 @@
#include "libguile/__scm.h"
#include "libguile/chars.h"
#include <libguile/error.h>
#include "libguile/options.h"
/* State information passed around during printing.
@ -53,6 +55,14 @@ do { \
#define SCM_COERCE_OUTPORT(p) \
(SCM_PORT_WITH_PS_P (p) ? SCM_PORT_WITH_PS_PORT (p) : p)
#define SCM_VALIDATE_OPORT_VALUE(pos, port) \
do { \
SCM_ASSERT (scm_valid_oport_value_p (port), port, pos, FUNC_NAME); \
} while (0)
#define SCM_VALIDATE_PRINTSTATE(pos, a) \
SCM_MAKE_VALIDATE_MSG(pos, a, PRINT_STATE_P, "print-state")
#define SCM_PRINT_STATE_LAYOUT "pwuwuwuwuwuwpwuwuwuwpwpw"
typedef struct scm_print_state {
SCM handle; /* Struct handle */

View file

@ -4,7 +4,7 @@
#define SCM_PROCS_H
/* Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2006, 2008, 2009,
* 2012, 2013 Free Software Foundation, Inc.
* 2012, 2013, 2018 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
@ -25,9 +25,15 @@
#include "libguile/__scm.h"
#include <libguile/error.h>
#define SCM_VALIDATE_THUNK(pos, thunk) \
do { \
SCM_ASSERT (scm_is_true (scm_thunk_p (thunk)), thunk, pos, FUNC_NAME); \
} while (0)
SCM_API SCM scm_procedure_p (SCM obj);
SCM_API SCM scm_thunk_p (SCM obj);
SCM_API SCM scm_procedure_with_setter_p (SCM obj);

View file

@ -3,8 +3,8 @@
#ifndef SCM_SMOB_H
#define SCM_SMOB_H
/* Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2004, 2006, 2009,
* 2010, 2011, 2012, 2015 Free Software Foundation, Inc.
/* Copyright (C) 1995-1996,1998-2001,2004,2006,2009-2012,2015,2018
* 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
@ -25,6 +25,7 @@
#include "libguile/__scm.h"
#include <libguile/error.h>
#include "libguile/print.h"
@ -54,6 +55,12 @@ typedef struct scm_smob_descriptor
#define SCM_SMOB_DESCRIPTOR(x) (scm_smobs[SCM_SMOBNUM (x)])
#define SCM_SMOB_APPLICABLE_P(x) (SCM_SMOB_DESCRIPTOR (x).apply)
#define SCM_VALIDATE_SMOB(pos, obj, type) \
do { \
SCM_ASSERT (SCM_SMOB_PREDICATE (scm_tc16_ ## type, obj), \
obj, pos, FUNC_NAME); \
} while (0)
/* Maximum number of SMOB types. */
#define SCM_I_MAX_SMOB_TYPE_COUNT 256

View file

@ -3,8 +3,8 @@
#ifndef SCM_STRINGS_H
#define SCM_STRINGS_H
/* Copyright (C) 1995-1998, 2000, 2001, 2004-2006, 2008-2011, 2013,
* 2015-2016 Free Software Foundation, Inc.
/* Copyright (C) 1995-1998,2000-2001,2004-2006,2008-2011,2013,
* 2015-2016,2018 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
@ -25,6 +25,7 @@
#include "libguile/__scm.h"
#include <libguile/error.h>
@ -247,6 +248,15 @@ SCM_API SCM scm_sys_stringbuf_hist (void);
#endif
#define SCM_VALIDATE_STRING(pos, str) \
do { \
SCM_ASSERT_TYPE (scm_is_string (str), str, pos, FUNC_NAME, "string"); \
} while (0)
SCM_INTERNAL void scm_init_strings (void);

View file

@ -31,54 +31,6 @@
#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) \
do { \
SCM_ASSERT (SCM_CHARP (scm), scm, pos, FUNC_NAME); \
cvar = SCM_CHAR (scm); \
} while (0)
#define SCM_VALIDATE_STRING(pos, str) \
do { \
SCM_ASSERT_TYPE (scm_is_string (str), str, pos, FUNC_NAME, "string"); \
} while (0)
#define SCM_VALIDATE_ALISTCELL(pos, alist) \
do { \
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_is_pair (alist), alist, pos, FUNC_NAME); \
cvar = SCM_CAR (alist); \
SCM_ASSERT (scm_is_pair (cvar), alist, pos, FUNC_NAME); \
} while (0)
#define SCM_VALIDATE_OPORT_VALUE(pos, port) \
do { \
SCM_ASSERT (scm_valid_oport_value_p (port), port, pos, FUNC_NAME); \
} while (0)
#define SCM_VALIDATE_PRINTSTATE(pos, a) SCM_MAKE_VALIDATE_MSG(pos, a, PRINT_STATE_P, "print-state")
#define SCM_VALIDATE_SMOB(pos, obj, type) \
do { \
SCM_ASSERT (SCM_SMOB_PREDICATE (scm_tc16_ ## type, obj), \
obj, pos, FUNC_NAME); \
} while (0)
#define SCM_VALIDATE_THUNK(pos, thunk) \
do { \
SCM_ASSERT (scm_is_true (scm_thunk_p (thunk)), thunk, pos, FUNC_NAME); \
} while (0)
#define SCM_VALIDATE_SYMBOL(pos, str) \
do { \
SCM_ASSERT_TYPE (scm_is_symbol (str), str, pos, FUNC_NAME, "symbol"); \