aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-22 08:33:55 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-22 08:33:55 +0000
commit4c3697bd51c2ba45b84dd8046c32b1bde26fdcb0 (patch)
treea471f6b0e76c590f04579e62d1834c915b9eb322
parent332c24dbe9cbf9cfbe20b39027268dfc53a29c0a (diff)
downloadruby-4c3697bd51c2ba45b84dd8046c32b1bde26fdcb0.tar.gz
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
-rw-r--r--ChangeLog6
-rw-r--r--array.c2
-rw-r--r--bignum.c2
-rw-r--r--common.mk17
-rw-r--r--complex.c2
-rw-r--r--encoding.c2
-rw-r--r--error.c13
-rw-r--r--gc.c2
-rw-r--r--id_table.c2
-rw-r--r--rational.c2
-rw-r--r--ruby_assert.h53
-rw-r--r--string.c2
12 files changed, 93 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index d86197f6a7..5dc9aa2f78 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Jan 22 17:33:05 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * error.c (rb_assert_failure): assertion with stack dump.
+
+ * ruby_assert.h (RUBY_ASSERT): new header for the assertion.
+
Fri Jan 22 00:25:57 2016 NARUSE, Yui <naruse@ruby-lang.org>
* regparse.c (fetch_name_with_level): allow non word characters
diff --git a/array.c b/array.c
index e31f67467f..050e3a39ce 100644
--- a/array.c
+++ b/array.c
@@ -20,7 +20,7 @@
#ifndef ARRAY_DEBUG
# define NDEBUG
#endif
-#include <assert.h>
+#include "ruby_assert.h"
VALUE rb_cArray;
diff --git a/bignum.c b/bignum.c
index cdb84c600d..afd264adec 100644
--- a/bignum.c
+++ b/bignum.c
@@ -22,7 +22,7 @@
#ifdef HAVE_IEEEFP_H
#include <ieeefp.h>
#endif
-#include <assert.h>
+#include "ruby_assert.h"
#if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
#define USE_GMP
diff --git a/common.mk b/common.mk
index e871a5163d..e8a1c425bd 100644
--- a/common.mk
+++ b/common.mk
@@ -1133,6 +1133,7 @@ array.$(OBJEXT): {$(VPATH)}io.h
array.$(OBJEXT): {$(VPATH)}missing.h
array.$(OBJEXT): {$(VPATH)}oniguruma.h
array.$(OBJEXT): {$(VPATH)}probes.h
+array.$(OBJEXT): {$(VPATH)}ruby_assert.h
array.$(OBJEXT): {$(VPATH)}st.h
array.$(OBJEXT): {$(VPATH)}subst.h
array.$(OBJEXT): {$(VPATH)}util.h
@@ -1148,6 +1149,7 @@ bignum.$(OBJEXT): {$(VPATH)}internal.h
bignum.$(OBJEXT): {$(VPATH)}io.h
bignum.$(OBJEXT): {$(VPATH)}missing.h
bignum.$(OBJEXT): {$(VPATH)}oniguruma.h
+bignum.$(OBJEXT): {$(VPATH)}ruby_assert.h
bignum.$(OBJEXT): {$(VPATH)}st.h
bignum.$(OBJEXT): {$(VPATH)}subst.h
bignum.$(OBJEXT): {$(VPATH)}thread.h
@@ -1232,6 +1234,7 @@ complex.$(OBJEXT): {$(VPATH)}internal.h
complex.$(OBJEXT): {$(VPATH)}io.h
complex.$(OBJEXT): {$(VPATH)}missing.h
complex.$(OBJEXT): {$(VPATH)}oniguruma.h
+complex.$(OBJEXT): {$(VPATH)}ruby_assert.h
complex.$(OBJEXT): {$(VPATH)}st.h
complex.$(OBJEXT): {$(VPATH)}subst.h
cont.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h
@@ -1389,6 +1392,7 @@ encoding.$(OBJEXT): {$(VPATH)}io.h
encoding.$(OBJEXT): {$(VPATH)}missing.h
encoding.$(OBJEXT): {$(VPATH)}oniguruma.h
encoding.$(OBJEXT): {$(VPATH)}regenc.h
+encoding.$(OBJEXT): {$(VPATH)}ruby_assert.h
encoding.$(OBJEXT): {$(VPATH)}st.h
encoding.$(OBJEXT): {$(VPATH)}subst.h
encoding.$(OBJEXT): {$(VPATH)}util.h
@@ -1439,6 +1443,7 @@ error.$(OBJEXT): {$(VPATH)}method.h
error.$(OBJEXT): {$(VPATH)}missing.h
error.$(OBJEXT): {$(VPATH)}node.h
error.$(OBJEXT): {$(VPATH)}oniguruma.h
+error.$(OBJEXT): {$(VPATH)}ruby_assert.h
error.$(OBJEXT): {$(VPATH)}ruby_atomic.h
error.$(OBJEXT): {$(VPATH)}st.h
error.$(OBJEXT): {$(VPATH)}subst.h
@@ -1525,6 +1530,7 @@ gc.$(OBJEXT): {$(VPATH)}re.h
gc.$(OBJEXT): {$(VPATH)}regenc.h
gc.$(OBJEXT): {$(VPATH)}regex.h
gc.$(OBJEXT): {$(VPATH)}regint.h
+gc.$(OBJEXT): {$(VPATH)}ruby_assert.h
gc.$(OBJEXT): {$(VPATH)}ruby_atomic.h
gc.$(OBJEXT): {$(VPATH)}st.h
gc.$(OBJEXT): {$(VPATH)}subst.h
@@ -1984,6 +1990,7 @@ rational.$(OBJEXT): {$(VPATH)}io.h
rational.$(OBJEXT): {$(VPATH)}missing.h
rational.$(OBJEXT): {$(VPATH)}oniguruma.h
rational.$(OBJEXT): {$(VPATH)}rational.c
+rational.$(OBJEXT): {$(VPATH)}ruby_assert.h
rational.$(OBJEXT): {$(VPATH)}st.h
rational.$(OBJEXT): {$(VPATH)}subst.h
re.$(OBJEXT): $(hdrdir)/ruby/ruby.h
@@ -2227,6 +2234,7 @@ string.$(OBJEXT): {$(VPATH)}oniguruma.h
string.$(OBJEXT): {$(VPATH)}probes.h
string.$(OBJEXT): {$(VPATH)}re.h
string.$(OBJEXT): {$(VPATH)}regex.h
+string.$(OBJEXT): {$(VPATH)}ruby_assert.h
string.$(OBJEXT): {$(VPATH)}st.h
string.$(OBJEXT): {$(VPATH)}string.c
string.$(OBJEXT): {$(VPATH)}subst.h
@@ -2271,17 +2279,18 @@ symbol.$(OBJEXT): {$(VPATH)}encoding.h
symbol.$(OBJEXT): {$(VPATH)}gc.h
symbol.$(OBJEXT): {$(VPATH)}id.c
symbol.$(OBJEXT): {$(VPATH)}id.h
+symbol.$(OBJEXT): {$(VPATH)}id_table.c
+symbol.$(OBJEXT): {$(VPATH)}id_table.h
symbol.$(OBJEXT): {$(VPATH)}intern.h
symbol.$(OBJEXT): {$(VPATH)}internal.h
symbol.$(OBJEXT): {$(VPATH)}io.h
symbol.$(OBJEXT): {$(VPATH)}missing.h
symbol.$(OBJEXT): {$(VPATH)}oniguruma.h
symbol.$(OBJEXT): {$(VPATH)}probes.h
+symbol.$(OBJEXT): {$(VPATH)}ruby_assert.h
symbol.$(OBJEXT): {$(VPATH)}st.h
symbol.$(OBJEXT): {$(VPATH)}subst.h
symbol.$(OBJEXT): {$(VPATH)}symbol.c
-symbol.$(OBJEXT): {$(VPATH)}id_table.c
-symbol.$(OBJEXT): {$(VPATH)}id_table.h
symbol.$(OBJEXT): {$(VPATH)}symbol.h
symbol.$(OBJEXT): {$(VPATH)}vm_opts.h
thread.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h
@@ -2419,8 +2428,8 @@ vm.$(OBJEXT): {$(VPATH)}thread_native.h
vm.$(OBJEXT): {$(VPATH)}vm.c
vm.$(OBJEXT): {$(VPATH)}vm.h
vm.$(OBJEXT): {$(VPATH)}vm.inc
-vm.$(OBJEXT): {$(VPATH)}vm_call_iseq_optimized.inc
vm.$(OBJEXT): {$(VPATH)}vm_args.c
+vm.$(OBJEXT): {$(VPATH)}vm_call_iseq_optimized.inc
vm.$(OBJEXT): {$(VPATH)}vm_core.h
vm.$(OBJEXT): {$(VPATH)}vm_debug.h
vm.$(OBJEXT): {$(VPATH)}vm_eval.c
@@ -2461,8 +2470,8 @@ vm_backtrace.$(OBJEXT): {$(VPATH)}vm_core.h
vm_backtrace.$(OBJEXT): {$(VPATH)}vm_debug.h
vm_backtrace.$(OBJEXT): {$(VPATH)}vm_opts.h
vm_call.$(OBJEXT): $(top_srcdir)/include/ruby.h
-vm_call.$(OBJEXT): {$(VPATH)}vm_core.h
vm_call.$(OBJEXT): {$(VPATH)}vm_call_iseq_optimized.inc
+vm_call.$(OBJEXT): {$(VPATH)}vm_core.h
vm_dump.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h
vm_dump.$(OBJEXT): $(CCAN_DIR)/container_of/container_of.h
vm_dump.$(OBJEXT): $(CCAN_DIR)/list/list.h
diff --git a/complex.c b/complex.c
index ec52beaf0a..fc2cd0e783 100644
--- a/complex.c
+++ b/complex.c
@@ -14,7 +14,7 @@
#include "internal.h"
#define NDEBUG
-#include <assert.h>
+#include "ruby_assert.h"
#define ZERO INT2FIX(0)
#define ONE INT2FIX(1)
diff --git a/encoding.c b/encoding.c
index b030f21875..ed710a9dfb 100644
--- a/encoding.c
+++ b/encoding.c
@@ -15,7 +15,7 @@
#include <ctype.h>
#include "ruby/util.h"
-#include <assert.h>
+#include "ruby_assert.h"
#ifndef ENC_DEBUG
#define ENC_DEBUG 0
#endif
diff --git a/error.c b/error.c
index a86485d558..f88c19a328 100644
--- a/error.c
+++ b/error.c
@@ -11,6 +11,7 @@
#include "internal.h"
#include "ruby/st.h"
+#include "ruby_assert.h"
#include "vm_core.h"
#include <stdio.h>
@@ -499,6 +500,18 @@ rb_compile_bug_str(VALUE file, int line, const char *fmt, ...)
abort();
}
+void
+rb_assert_failure(const char *file, int line, const char *name, const char *expr)
+{
+ FILE *out = stderr;
+ fprintf(out, "Assertion Failed: %s:%d:", file, line);
+ if (name) fprintf(out, "%s:", name);
+ fprintf(out, "%s\n%s\n\n", expr, ruby_description);
+ rb_vm_bugreport(NULL);
+ bug_report_end(out);
+ die();
+}
+
static const char builtin_types[][10] = {
"", /* 0x00, */
"Object",
diff --git a/gc.c b/gc.c
index 874cb981b3..f75a489ba5 100644
--- a/gc.c
+++ b/gc.c
@@ -32,7 +32,7 @@
#include <stdarg.h>
#include <setjmp.h>
#include <sys/types.h>
-#include <assert.h>
+#include "ruby_assert.h"
#undef rb_data_object_wrap
diff --git a/id_table.c b/id_table.c
index 13adf6babb..324abf15f1 100644
--- a/id_table.c
+++ b/id_table.c
@@ -9,7 +9,7 @@
#if ID_TABLE_DEBUG == 0
#define NDEBUG
#endif
-#include <assert.h>
+#include "ruby_assert.h"
/*
* st
diff --git a/rational.c b/rational.c
index 0f3167a7e0..2359f0e3b5 100644
--- a/rational.c
+++ b/rational.c
@@ -14,7 +14,7 @@
#endif
#define NDEBUG
-#include <assert.h>
+#include "ruby_assert.h"
#if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
#define USE_GMP
diff --git a/ruby_assert.h b/ruby_assert.h
new file mode 100644
index 0000000000..8f603b56e9
--- /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
diff --git a/string.c b/string.c
index 24d1c709a9..b499fa2674 100644
--- a/string.c
+++ b/string.c
@@ -16,7 +16,7 @@
#include "encindex.h"
#include "probes.h"
#include "gc.h"
-#include <assert.h>
+#include "ruby_assert.h"
#include "id.h"
#define BEG(no) (regs->beg[(no)])