/contrib/ntp/include/isc/assertions.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 120 lines · 80 code · 21 blank · 19 comment · 8 complexity · fe459f9e021b73a9c21571bf72f5c9f3 MD5 · raw file

  1. /*
  2. * Copyright (C) 1997-2001 Internet Software Consortium.
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
  9. * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
  10. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  11. * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
  12. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  13. * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  14. * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  15. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. /*
  18. * $Id: assertions.h,v 1.17 2001/07/12 05:58:21 mayer Exp $
  19. */
  20. #ifndef ISC_ASSERTIONS_H
  21. #define ISC_ASSERTIONS_H 1
  22. #include <isc/lang.h>
  23. #include <isc/platform.h>
  24. ISC_LANG_BEGINDECLS
  25. typedef enum {
  26. isc_assertiontype_require,
  27. isc_assertiontype_ensure,
  28. isc_assertiontype_insist,
  29. isc_assertiontype_invariant
  30. } isc_assertiontype_t;
  31. typedef void (*isc_assertioncallback_t)(const char *, int, isc_assertiontype_t,
  32. const char *);
  33. LIBISC_EXTERNAL_DATA extern isc_assertioncallback_t isc_assertion_failed;
  34. void
  35. isc_assertion_setcallback(isc_assertioncallback_t);
  36. const char *
  37. isc_assertion_typetotext(isc_assertiontype_t type);
  38. #ifdef ISC_CHECK_ALL
  39. #define ISC_CHECK_REQUIRE 1
  40. #define ISC_CHECK_ENSURE 1
  41. #define ISC_CHECK_INSIST 1
  42. #define ISC_CHECK_INVARIANT 1
  43. #endif
  44. #ifdef ISC_CHECK_NONE
  45. #define ISC_CHECK_REQUIRE 0
  46. #define ISC_CHECK_ENSURE 0
  47. #define ISC_CHECK_INSIST 0
  48. #define ISC_CHECK_INVARIANT 0
  49. #endif
  50. #ifndef ISC_CHECK_REQUIRE
  51. #define ISC_CHECK_REQUIRE 1
  52. #endif
  53. #ifndef ISC_CHECK_ENSURE
  54. #define ISC_CHECK_ENSURE 1
  55. #endif
  56. #ifndef ISC_CHECK_INSIST
  57. #define ISC_CHECK_INSIST 1
  58. #endif
  59. #ifndef ISC_CHECK_INVARIANT
  60. #define ISC_CHECK_INVARIANT 1
  61. #endif
  62. #if ISC_CHECK_REQUIRE != 0
  63. #define ISC_REQUIRE(cond) \
  64. ((void) ((cond) || \
  65. ((isc_assertion_failed)(__FILE__, __LINE__, \
  66. isc_assertiontype_require, \
  67. #cond), 0)))
  68. #else
  69. #define ISC_REQUIRE(cond) ((void) 0)
  70. #endif /* ISC_CHECK_REQUIRE */
  71. #if ISC_CHECK_ENSURE != 0
  72. #define ISC_ENSURE(cond) \
  73. ((void) ((cond) || \
  74. ((isc_assertion_failed)(__FILE__, __LINE__, \
  75. isc_assertiontype_ensure, \
  76. #cond), 0)))
  77. #else
  78. #define ISC_ENSURE(cond) ((void) 0)
  79. #endif /* ISC_CHECK_ENSURE */
  80. #if ISC_CHECK_INSIST != 0
  81. #define ISC_INSIST(cond) \
  82. ((void) ((cond) || \
  83. ((isc_assertion_failed)(__FILE__, __LINE__, \
  84. isc_assertiontype_insist, \
  85. #cond), 0)))
  86. #else
  87. #define ISC_INSIST(cond) ((void) 0)
  88. #endif /* ISC_CHECK_INSIST */
  89. #if ISC_CHECK_INVARIANT != 0
  90. #define ISC_INVARIANT(cond) \
  91. ((void) ((cond) || \
  92. ((isc_assertion_failed)(__FILE__, __LINE__, \
  93. isc_assertiontype_invariant, \
  94. #cond), 0)))
  95. #else
  96. #define ISC_INVARIANT(cond) ((void) 0)
  97. #endif /* ISC_CHECK_INVARIANT */
  98. ISC_LANG_ENDDECLS
  99. #endif /* ISC_ASSERTIONS_H */