27 #include "ruby/internal/cast.h"
61 #if ! defined(RUBY_DEBUG)
62 # define RBIMPL_RUBY_DEBUG 0
63 #elif !!RUBY_DEBUG-1 < 0
64 # define RBIMPL_RUBY_DEBUG 0
66 # define RBIMPL_RUBY_DEBUG 1
75 # define RBIMPL_NDEBUG 1
77 # define RBIMPL_NDEBUG 0
86 #if defined(__DOXYGEN__)
92 # define RUBY_NDEBUG 1
94 #elif (RBIMPL_NDEBUG == 1) && (RBIMPL_RUBY_DEBUG == 0)
97 # define RUBY_NDEBUG 1
100 #elif (RBIMPL_NDEBUG == 0) && (RBIMPL_RUBY_DEBUG == 1)
102 # define RUBY_DEBUG 1
103 # define RUBY_NDEBUG 0
106 #elif (RBIMPL_NDEBUG == 0) && (RBIMPL_RUBY_DEBUG == 0)
108 # define RUBY_DEBUG 0
109 # define RUBY_NDEBUG 1
112 #elif (RBIMPL_NDEBUG == 1) && (RBIMPL_RUBY_DEBUG == 1)
114 # define RUBY_DEBUG 1
115 # define RUBY_NDEBUG 0
118 # if defined(_MSC_VER)
119 # pragma message("NDEBUG is ignored because RUBY_DEBUG>0.")
120 # elif defined(__GNUC__)
121 # pragma GCC warning "NDEBUG is ignored because RUBY_DEBUG>0."
123 # error NDEBUG is ignored because RUBY_DEBUG>0.
127 #undef RBIMPL_RUBY_DEBUG
130 #define RBIMPL_ASSERT_NOTHING RBIMPL_CAST((void)0)
135 void rb_assert_failure(const
char *file,
int line, const
char *name, const
char *expr);
140 void rb_assert_failure_detail(const
char *file,
int line, const
char *name, const
char *expr, const
char *fmt, ...);
143 #ifdef RUBY_FUNCTION_NAME_STRING
144 # define RBIMPL_ASSERT_FUNC RUBY_FUNCTION_NAME_STRING
146 # define RBIMPL_ASSERT_FUNC RBIMPL_CAST((const char *)0)
156 #if defined(HAVE___VA_OPT__)
157 # if RBIMPL_HAS_WARNING("-Wgnu-zero-variadic-macro-arguments")
162 # define RBIMPL_VA_OPT_ARGS(...) __VA_OPT__(,) __VA_ARGS__
164 # define RUBY_ASSERT_FAIL(mesg, ...) \
165 rb_assert_failure##__VA_OPT__(_detail)( \
166 __FILE__, __LINE__, RBIMPL_ASSERT_FUNC, mesg RBIMPL_VA_OPT_ARGS(__VA_ARGS__))
167 #elif !defined(__cplusplus)
168 # define RBIMPL_VA_OPT_ARGS(...)
170 # define RUBY_ASSERT_FAIL(mesg, ...) \
171 rb_assert_failure(__FILE__, __LINE__, RBIMPL_ASSERT_FUNC, mesg)
173 # undef RBIMPL_VA_OPT_ARGS
175 # define RUBY_ASSERT_FAIL(mesg) \
176 rb_assert_failure(__FILE__, __LINE__, RBIMPL_ASSERT_FUNC, mesg)
185 #if defined(RBIMPL_VA_OPT_ARGS)
186 # define RUBY_ASSERT_MESG(expr, ...) \
187 (RB_LIKELY(expr) ? RBIMPL_ASSERT_NOTHING : RUBY_ASSERT_FAIL(__VA_ARGS__))
189 # define RUBY_ASSERT_MESG(expr, mesg) \
190 (RB_LIKELY(expr) ? RBIMPL_ASSERT_NOTHING : RUBY_ASSERT_FAIL(mesg))
198 #if defined(RBIMPL_VA_OPT_ARGS)
199 # define RUBY_ASSERT_ALWAYS(expr, ...) \
200 RUBY_ASSERT_MESG(expr, #expr RBIMPL_VA_OPT_ARGS(__VA_ARGS__))
202 # define RUBY_ASSERT_ALWAYS(expr) RUBY_ASSERT_MESG((expr), #expr)
211 # if defined(RBIMPL_VA_OPT_ARGS)
212 # define RUBY_ASSERT(expr, ...) \
213 RUBY_ASSERT_MESG((expr), #expr RBIMPL_VA_OPT_ARGS(__VA_ARGS__))
215 # define RUBY_ASSERT(expr) RUBY_ASSERT_MESG((expr), #expr)
218 # if defined(RBIMPL_VA_OPT_ARGS)
219 # define RUBY_ASSERT(...) RBIMPL_ASSERT_NOTHING
221 # define RUBY_ASSERT(expr) RBIMPL_ASSERT_NOTHING
235 # if defined(RBIMPL_VA_OPT_ARGS)
236 # define RUBY_ASSERT_NDEBUG(...) RBIMPL_ASSERT_NOTHING
238 # define RUBY_ASSERT_NDEBUG(expr) RBIMPL_ASSERT_NOTHING
241 # if defined(RBIMPL_VA_OPT_ARGS)
242 # define RUBY_ASSERT_NDEBUG(expr, ...) \
243 RUBY_ASSERT_MESG((expr), #expr RBIMPL_VA_OPT_ARGS(__VA_ARGS__))
245 # define RUBY_ASSERT_NDEBUG(expr) RUBY_ASSERT_MESG((expr), #expr)
254 # if defined(RBIMPL_VA_OPT_ARGS)
255 # define RUBY_ASSERT_MESG_WHEN(cond, ...) \
256 RUBY_ASSERT_MESG(__VA_ARGS__)
258 # define RUBY_ASSERT_MESG_WHEN(cond, expr, mesg) RUBY_ASSERT_MESG((expr), (mesg))
261 # if defined(RBIMPL_VA_OPT_ARGS)
262 # define RUBY_ASSERT_MESG_WHEN(cond, expr, ...) \
263 ((cond) ? RUBY_ASSERT_MESG((expr), __VA_ARGS__) : RBIMPL_ASSERT_NOTHING)
265 # define RUBY_ASSERT_MESG_WHEN(cond, expr, mesg) \
266 ((cond) ? RUBY_ASSERT_MESG((expr), (mesg)) : RBIMPL_ASSERT_NOTHING)
277 #if defined(RBIMPL_VA_OPT_ARGS)
278 # define RUBY_ASSERT_WHEN(cond, expr, ...) \
279 RUBY_ASSERT_MESG_WHEN(cond, expr, #expr RBIMPL_VA_OPT_ARGS(__VA_ARGS__))
281 # define RUBY_ASSERT_WHEN(cond, expr) RUBY_ASSERT_MESG_WHEN((cond), (expr), #expr)
291 #define RUBY_ASSERT_BUILTIN_TYPE(obj, type) \
292 RUBY_ASSERT(RB_TYPE_P(obj, type), \
293 "Actual type is %s", rb_builtin_type_name(BUILTIN_TYPE(obj)))
301 # define RBIMPL_ASSERT_OR_ASSUME RUBY_ASSERT_ALWAYS
302 #elif ! defined(RBIMPL_VA_OPT_ARGS)
303 # define RBIMPL_ASSERT_OR_ASSUME(expr) RBIMPL_ASSUME(expr)
304 #elif RBIMPL_COMPILER_BEFORE(Clang, 7, 0, 0)
306 # define RBIMPL_ASSERT_OR_ASSUME(...) RBIMPL_ASSERT_NOTHING
307 #elif defined(RUBY_ASSERT_NOASSUME)
309 # define RBIMPL_ASSERT_OR_ASSUME(...) RBIMPL_ASSERT_NOTHING
310 #elif ! defined(RBIMPL_HAVE___ASSUME)
311 # define RBIMPL_ASSERT_OR_ASSUME(...) RBIMPL_ASSERT_NOTHING
313 # define RBIMPL_ASSERT_OR_ASSUME(expr, ...) RBIMPL_ASSUME(expr)
Defines ASSUME / RB_LIKELY / UNREACHABLE.
Defines RBIMPL_ATTR_COLD.
#define RBIMPL_ATTR_COLD()
Wraps (or simulates) __attribute__((cold))
Tweaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
RBIMPL_ATTR_NORETURN() void rb_eof_error(void)
Utility function to raise rb_eEOFError.
Defines RBIMPL_ASSUME / RBIMPL_UNREACHABLE.
Defines RBIMPL_ATTR_NORETURN.
#define RBIMPL_WARNING_IGNORED(flag)
Suppresses a warning.