Ruby  2.5.0dev(2017-10-22revision60238)
ruby_assert.h
Go to the documentation of this file.
1 #ifndef RUBY_ASSERT_H
2 #define RUBY_ASSERT_H
3 
4 #include "ruby/ruby.h"
5 
6 #if defined(__cplusplus)
7 extern "C" {
8 #if 0
9 } /* satisfy cc-mode */
10 #endif
11 #endif
12 
13 NORETURN(void rb_assert_failure(const char *, int, const char *, const char *));
14 #ifdef RUBY_FUNCTION_NAME_STRING
15 # define RUBY_ASSERT_FAIL(expr) \
16  rb_assert_failure(__FILE__, __LINE__, RUBY_FUNCTION_NAME_STRING, expr)
17 #else
18 # define RUBY_ASSERT_FAIL(expr) \
19  rb_assert_failure(__FILE__, __LINE__, NULL, expr)
20 #endif
21 #define RUBY_ASSERT_MESG(expr, mesg) \
22  ((expr) ? (void)0 : RUBY_ASSERT_FAIL(mesg))
23 #ifdef HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P
24 # define RUBY_ASSERT_MESG_WHEN(cond, expr, mesg) \
25  __builtin_choose_expr( \
26  __builtin_constant_p(cond), \
27  __builtin_choose_expr(cond, RUBY_ASSERT_MESG(expr, mesg), (void)0), \
28  RUBY_ASSERT_MESG(!(cond) || (expr), mesg))
29 #else
30 # define RUBY_ASSERT_MESG_WHEN(cond, expr, mesg) \
31  RUBY_ASSERT_MESG(!(cond) || (expr), mesg)
32 #endif
33 #define RUBY_ASSERT(expr) RUBY_ASSERT_MESG_WHEN(!RUBY_NDEBUG+0, expr, #expr)
34 #define RUBY_ASSERT_WHEN(cond, expr) RUBY_ASSERT_MESG_WHEN(cond, expr, #expr)
35 
36 #undef assert
37 #define assert RUBY_ASSERT
38 
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 *))
void rb_assert_failure(const char *file, int line, const char *name, const char *expr)
Definition: error.c:603