summaryrefslogtreecommitdiff
path: root/ruby_assert.h
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-22 08:33:55 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-22 08:33:55 (GMT)
commit439224a5904411b288e441096e21a41244ddd1d6 (patch)
treea471f6b0e76c590f04579e62d1834c915b9eb322 /ruby_assert.h
parente5850a80d69531be3c62468b7c88d91f30b0490b (diff)
RUBY_ASSERT
* error.c (rb_assert_failure): assertion with stack dump. * ruby_assert.h (RUBY_ASSERT): new header for the assertion. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53615 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby_assert.h')
-rw-r--r--ruby_assert.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/ruby_assert.h b/ruby_assert.h
new file mode 100644
index 0000000..8f603b5
--- /dev/null
+++ b/ruby_assert.h
@@ -0,0 +1,53 @@
+#ifndef RUBY_ASSERT_H
+#define RUBY_ASSERT_H
+
+#include "ruby/ruby.h"
+
+#if defined(__cplusplus)
+extern "C" {
+#if 0
+} /* satisfy cc-mode */
+#endif
+#endif
+
+NORETURN(void rb_assert_failure(const char *, int, const char *, const char *));
+#ifdef RUBY_FUNCTION_NAME_STRING
+# define RUBY_ASSERT_FAIL(expr) \
+ rb_assert_failure(__FILE__, __LINE__, RUBY_FUNCTION_NAME_STRING, expr)
+#else
+# define RUBY_ASSERT_FAIL(expr) \
+ rb_assert_failure(__FILE__, __LINE__, NULL, expr)
+#endif
+#define RUBY_ASSERT_MESG(expr, mesg) \
+ ((expr) ? (void)0 : RUBY_ASSERT_FAIL(mesg))
+#ifdef HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P
+# define RUBY_ASSERT_MESG_WHEN(cond, expr, mesg) \
+ __builtin_choose_expr( \
+ __builtin_constant_p(cond), \
+ __builtin_choose_expr(cond, RUBY_ASSERT_MESG(expr, mesg), (void)0), \
+ RUBY_ASSERT_MESG(!(cond) || (expr), mesg))
+#else
+# define RUBY_ASSERT_MESG_WHEN(cond, expr, mesg) \
+ RUBY_ASSERT_MESG(!(cond) || (expr), mesg)
+#endif
+#define RUBY_ASSERT(expr) RUBY_ASSERT_MESG_WHEN(!RUBY_NDEBUG+0, expr, #expr)
+
+#undef assert
+#define assert RUBY_ASSERT
+
+#ifndef RUBY_NDEBUG
+# ifdef NDEBUG
+# define RUBY_NDEBUG 1
+# else
+# define RUBY_NDEBUG 0
+# endif
+#endif
+
+#if defined(__cplusplus)
+#if 0
+{ /* satisfy cc-mode */
+#endif
+} /* extern "C" { */
+#endif
+
+#endif