error.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #ifndef SCM_ERROR_H
  2. #define SCM_ERROR_H
  3. /* Copyright 1995-1998,2000-2002,2006,2008,2011,2014,2018,2020
  4. Free Software Foundation, Inc.
  5. This file is part of Guile.
  6. Guile is free software: you can redistribute it and/or modify it
  7. under the terms of the GNU Lesser General Public License as published
  8. by the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Guile is distributed in the hope that it will be useful, but WITHOUT
  11. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  13. License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with Guile. If not, see
  16. <https://www.gnu.org/licenses/>. */
  17. #include "libguile/scm.h"
  18. SCM_API SCM scm_system_error_key;
  19. SCM_API SCM scm_num_overflow_key;
  20. SCM_API SCM scm_out_of_range_key;
  21. SCM_API SCM scm_args_number_key;
  22. SCM_API SCM scm_arg_type_key;
  23. SCM_API SCM scm_misc_error_key;
  24. /* Snarfing for docs may override SCM_ASSERT; see snarf.h. */
  25. #ifndef SCM_ASSERT
  26. #define SCM_ASSERT(_cond, _arg, _pos, _subr) \
  27. do { if (SCM_UNLIKELY (!(_cond))) \
  28. scm_wrong_type_arg (_subr, _pos, _arg); } while (0)
  29. #endif
  30. #define SCM_ASSERT_TYPE(_cond, _arg, _pos, _subr, _msg) \
  31. do { if (SCM_UNLIKELY (!(_cond))) \
  32. scm_wrong_type_arg_msg(_subr, _pos, _arg, _msg); } while (0)
  33. SCM_API void scm_error (SCM key, const char *subr, const char *message,
  34. SCM args, SCM rest) SCM_NORETURN;
  35. SCM_API SCM scm_error_scm (SCM key, SCM subr, SCM message,
  36. SCM args, SCM rest) SCM_NORETURN;
  37. SCM_API SCM scm_strerror (SCM err);
  38. SCM_API void scm_syserror (const char *subr) SCM_NORETURN;
  39. SCM_API void scm_syserror_msg (const char *subr, const char *message,
  40. SCM args, int eno) SCM_NORETURN;
  41. SCM_API void scm_num_overflow (const char *subr) SCM_NORETURN;
  42. SCM_API void scm_out_of_range (const char *subr, SCM bad_value)
  43. SCM_NORETURN;
  44. SCM_API void scm_out_of_range_pos (const char *subr, SCM bad_value, SCM pos)
  45. SCM_NORETURN;
  46. SCM_API void scm_wrong_num_args (SCM proc) SCM_NORETURN;
  47. SCM_API void scm_error_num_args_subr (const char* subr) SCM_NORETURN;
  48. SCM_API void scm_wrong_type_arg (const char *subr, int pos,
  49. SCM bad_value) SCM_NORETURN;
  50. SCM_INTERNAL void scm_i_wrong_type_arg_symbol (SCM symbol, int pos,
  51. SCM bad_value) SCM_NORETURN;
  52. SCM_API void scm_wrong_type_arg_msg (const char *subr, int pos,
  53. SCM bad_value, const char *sz) SCM_NORETURN;
  54. SCM_API void scm_misc_error (const char *subr, const char *message,
  55. SCM args) SCM_NORETURN;
  56. SCM_INTERNAL void scm_init_error (void);
  57. #ifndef SCM_MAGIC_SNARFER
  58. /* Let these macros pass through if
  59. we are snarfing; thus we can tell the
  60. difference between the use of an actual
  61. number vs. the use of one of these macros --
  62. actual numbers in SCM_VALIDATE_* and SCM_ASSERT
  63. constructs must match the formal argument name,
  64. but using SCM_ARG* avoids the test */
  65. #define SCM_ARGn 0
  66. #define SCM_ARG1 1
  67. #define SCM_ARG2 2
  68. #define SCM_ARG3 3
  69. #define SCM_ARG4 4
  70. #define SCM_ARG5 5
  71. #define SCM_ARG6 6
  72. #define SCM_ARG7 7
  73. #endif /* SCM_MAGIC_SNARFER */
  74. #define SCM_MAKE_VALIDATE(pos, var, pred) \
  75. do { \
  76. SCM_ASSERT_TYPE (SCM_ ## pred (var), var, pos, FUNC_NAME, #pred); \
  77. } while (0)
  78. #define SCM_I_MAKE_VALIDATE_MSG2(pos, var, pred, msg) \
  79. do { \
  80. SCM_ASSERT_TYPE (pred (var), var, pos, FUNC_NAME, msg); \
  81. } while (0)
  82. #define SCM_MAKE_VALIDATE_MSG(pos, var, pred, msg) \
  83. SCM_I_MAKE_VALIDATE_MSG2 (pos, var, SCM_ ## pred, msg)
  84. #define SCM_SYSERROR do { scm_syserror (FUNC_NAME); } while (0)
  85. #define SCM_SYSERROR_MSG(str, args, val) \
  86. do { scm_syserror_msg (FUNC_NAME, (str), (args), (val)); } while (0)
  87. #define SCM_MISC_ERROR(str, args) \
  88. do { scm_misc_error (FUNC_NAME, str, args); } while (0)
  89. #define SCM_WRONG_NUM_ARGS() \
  90. do { scm_error_num_args_subr (FUNC_NAME); } while (0)
  91. #define SCM_WRONG_TYPE_ARG(pos, obj) \
  92. do { scm_wrong_type_arg (FUNC_NAME, pos, obj); } while (0)
  93. #endif /* SCM_ERROR_H */