Ruby 2.7.7p221 (2022-11-24 revision 168ec2b1e5ad0e4688e963d9de019557c78feed9)
assert.h
Go to the documentation of this file.
1#ifndef RUBY_ASSERT_H
2#define RUBY_ASSERT_H
3
4#if defined(__cplusplus)
5extern "C" {
6#if 0
7} /* satisfy cc-mode */
8#endif
9#endif
10
11NORETURN(void rb_assert_failure(const char *, int, const char *, const char *));
12#ifdef RUBY_FUNCTION_NAME_STRING
13# define RUBY_ASSERT_FAIL(expr) \
14 rb_assert_failure(__FILE__, __LINE__, RUBY_FUNCTION_NAME_STRING, expr)
15#else
16# define RUBY_ASSERT_FAIL(expr) \
17 rb_assert_failure(__FILE__, __LINE__, NULL, expr)
18#endif
19#define RUBY_ASSERT_MESG(expr, mesg) \
20 ((expr) ? (void)0 : RUBY_ASSERT_FAIL(mesg))
21#ifdef HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P
22# define RUBY_ASSERT_MESG_WHEN(cond, expr, mesg) \
23 ((RUBY_DEBUG+0) ? RUBY_ASSERT_MESG((expr), mesg) : \
24 __builtin_choose_expr( \
25 __builtin_constant_p(cond), \
26 __builtin_choose_expr(cond, RUBY_ASSERT_MESG(expr, mesg), (void)0), \
27 RUBY_ASSERT_MESG(!(cond) || (expr), mesg)))
28#else
29# define RUBY_ASSERT_MESG_WHEN(cond, expr, mesg) \
30 RUBY_ASSERT_MESG(!((RUBY_DEBUG+0) || (cond)) || (expr), mesg)
31#endif
32#define RUBY_ASSERT(expr) RUBY_ASSERT_MESG_WHEN((!RUBY_NDEBUG+0), expr, #expr)
33#define RUBY_ASSERT_WHEN(cond, expr) RUBY_ASSERT_MESG_WHEN(cond, expr, #expr)
34#define RUBY_ASSERT_ALWAYS(expr) RUBY_ASSERT_MESG_WHEN(TRUE, expr, #expr)
35
36#ifndef RUBY_DEBUG
37# define RUBY_DEBUG 0
38#endif
39#ifndef RUBY_NDEBUG
40# ifdef NDEBUG
41# define RUBY_NDEBUG 1
42# else
43# define RUBY_NDEBUG 0
44# endif
45#endif
46
47#if defined(__cplusplus)
48#if 0
49{ /* satisfy cc-mode */
50#endif
51} /* extern "C" { */
52#endif
53
54#endif
NORETURN(void rb_assert_failure(const char *, int, const char *, const char *))
MJIT_FUNC_EXPORTED void rb_assert_failure(const char *file, int line, const char *name, const char *expr)
Definition: error.c:718