1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2016-01-22 08:33:55 +00:00
parent e5850a80d6
commit 439224a590
12 changed files with 93 additions and 12 deletions

View file

@ -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> Fri Jan 22 00:25:57 2016 NARUSE, Yui <naruse@ruby-lang.org>
* regparse.c (fetch_name_with_level): allow non word characters * regparse.c (fetch_name_with_level): allow non word characters

View file

@ -20,7 +20,7 @@
#ifndef ARRAY_DEBUG #ifndef ARRAY_DEBUG
# define NDEBUG # define NDEBUG
#endif #endif
#include <assert.h> #include "ruby_assert.h"
VALUE rb_cArray; VALUE rb_cArray;

View file

@ -22,7 +22,7 @@
#ifdef HAVE_IEEEFP_H #ifdef HAVE_IEEEFP_H
#include <ieeefp.h> #include <ieeefp.h>
#endif #endif
#include <assert.h> #include "ruby_assert.h"
#if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H) #if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
#define USE_GMP #define USE_GMP

View file

@ -1133,6 +1133,7 @@ array.$(OBJEXT): {$(VPATH)}io.h
array.$(OBJEXT): {$(VPATH)}missing.h array.$(OBJEXT): {$(VPATH)}missing.h
array.$(OBJEXT): {$(VPATH)}oniguruma.h array.$(OBJEXT): {$(VPATH)}oniguruma.h
array.$(OBJEXT): {$(VPATH)}probes.h array.$(OBJEXT): {$(VPATH)}probes.h
array.$(OBJEXT): {$(VPATH)}ruby_assert.h
array.$(OBJEXT): {$(VPATH)}st.h array.$(OBJEXT): {$(VPATH)}st.h
array.$(OBJEXT): {$(VPATH)}subst.h array.$(OBJEXT): {$(VPATH)}subst.h
array.$(OBJEXT): {$(VPATH)}util.h array.$(OBJEXT): {$(VPATH)}util.h
@ -1148,6 +1149,7 @@ bignum.$(OBJEXT): {$(VPATH)}internal.h
bignum.$(OBJEXT): {$(VPATH)}io.h bignum.$(OBJEXT): {$(VPATH)}io.h
bignum.$(OBJEXT): {$(VPATH)}missing.h bignum.$(OBJEXT): {$(VPATH)}missing.h
bignum.$(OBJEXT): {$(VPATH)}oniguruma.h bignum.$(OBJEXT): {$(VPATH)}oniguruma.h
bignum.$(OBJEXT): {$(VPATH)}ruby_assert.h
bignum.$(OBJEXT): {$(VPATH)}st.h bignum.$(OBJEXT): {$(VPATH)}st.h
bignum.$(OBJEXT): {$(VPATH)}subst.h bignum.$(OBJEXT): {$(VPATH)}subst.h
bignum.$(OBJEXT): {$(VPATH)}thread.h bignum.$(OBJEXT): {$(VPATH)}thread.h
@ -1232,6 +1234,7 @@ complex.$(OBJEXT): {$(VPATH)}internal.h
complex.$(OBJEXT): {$(VPATH)}io.h complex.$(OBJEXT): {$(VPATH)}io.h
complex.$(OBJEXT): {$(VPATH)}missing.h complex.$(OBJEXT): {$(VPATH)}missing.h
complex.$(OBJEXT): {$(VPATH)}oniguruma.h complex.$(OBJEXT): {$(VPATH)}oniguruma.h
complex.$(OBJEXT): {$(VPATH)}ruby_assert.h
complex.$(OBJEXT): {$(VPATH)}st.h complex.$(OBJEXT): {$(VPATH)}st.h
complex.$(OBJEXT): {$(VPATH)}subst.h complex.$(OBJEXT): {$(VPATH)}subst.h
cont.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.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)}missing.h
encoding.$(OBJEXT): {$(VPATH)}oniguruma.h encoding.$(OBJEXT): {$(VPATH)}oniguruma.h
encoding.$(OBJEXT): {$(VPATH)}regenc.h encoding.$(OBJEXT): {$(VPATH)}regenc.h
encoding.$(OBJEXT): {$(VPATH)}ruby_assert.h
encoding.$(OBJEXT): {$(VPATH)}st.h encoding.$(OBJEXT): {$(VPATH)}st.h
encoding.$(OBJEXT): {$(VPATH)}subst.h encoding.$(OBJEXT): {$(VPATH)}subst.h
encoding.$(OBJEXT): {$(VPATH)}util.h encoding.$(OBJEXT): {$(VPATH)}util.h
@ -1439,6 +1443,7 @@ error.$(OBJEXT): {$(VPATH)}method.h
error.$(OBJEXT): {$(VPATH)}missing.h error.$(OBJEXT): {$(VPATH)}missing.h
error.$(OBJEXT): {$(VPATH)}node.h error.$(OBJEXT): {$(VPATH)}node.h
error.$(OBJEXT): {$(VPATH)}oniguruma.h error.$(OBJEXT): {$(VPATH)}oniguruma.h
error.$(OBJEXT): {$(VPATH)}ruby_assert.h
error.$(OBJEXT): {$(VPATH)}ruby_atomic.h error.$(OBJEXT): {$(VPATH)}ruby_atomic.h
error.$(OBJEXT): {$(VPATH)}st.h error.$(OBJEXT): {$(VPATH)}st.h
error.$(OBJEXT): {$(VPATH)}subst.h error.$(OBJEXT): {$(VPATH)}subst.h
@ -1525,6 +1530,7 @@ gc.$(OBJEXT): {$(VPATH)}re.h
gc.$(OBJEXT): {$(VPATH)}regenc.h gc.$(OBJEXT): {$(VPATH)}regenc.h
gc.$(OBJEXT): {$(VPATH)}regex.h gc.$(OBJEXT): {$(VPATH)}regex.h
gc.$(OBJEXT): {$(VPATH)}regint.h gc.$(OBJEXT): {$(VPATH)}regint.h
gc.$(OBJEXT): {$(VPATH)}ruby_assert.h
gc.$(OBJEXT): {$(VPATH)}ruby_atomic.h gc.$(OBJEXT): {$(VPATH)}ruby_atomic.h
gc.$(OBJEXT): {$(VPATH)}st.h gc.$(OBJEXT): {$(VPATH)}st.h
gc.$(OBJEXT): {$(VPATH)}subst.h gc.$(OBJEXT): {$(VPATH)}subst.h
@ -1984,6 +1990,7 @@ rational.$(OBJEXT): {$(VPATH)}io.h
rational.$(OBJEXT): {$(VPATH)}missing.h rational.$(OBJEXT): {$(VPATH)}missing.h
rational.$(OBJEXT): {$(VPATH)}oniguruma.h rational.$(OBJEXT): {$(VPATH)}oniguruma.h
rational.$(OBJEXT): {$(VPATH)}rational.c rational.$(OBJEXT): {$(VPATH)}rational.c
rational.$(OBJEXT): {$(VPATH)}ruby_assert.h
rational.$(OBJEXT): {$(VPATH)}st.h rational.$(OBJEXT): {$(VPATH)}st.h
rational.$(OBJEXT): {$(VPATH)}subst.h rational.$(OBJEXT): {$(VPATH)}subst.h
re.$(OBJEXT): $(hdrdir)/ruby/ruby.h re.$(OBJEXT): $(hdrdir)/ruby/ruby.h
@ -2227,6 +2234,7 @@ string.$(OBJEXT): {$(VPATH)}oniguruma.h
string.$(OBJEXT): {$(VPATH)}probes.h string.$(OBJEXT): {$(VPATH)}probes.h
string.$(OBJEXT): {$(VPATH)}re.h string.$(OBJEXT): {$(VPATH)}re.h
string.$(OBJEXT): {$(VPATH)}regex.h string.$(OBJEXT): {$(VPATH)}regex.h
string.$(OBJEXT): {$(VPATH)}ruby_assert.h
string.$(OBJEXT): {$(VPATH)}st.h string.$(OBJEXT): {$(VPATH)}st.h
string.$(OBJEXT): {$(VPATH)}string.c string.$(OBJEXT): {$(VPATH)}string.c
string.$(OBJEXT): {$(VPATH)}subst.h string.$(OBJEXT): {$(VPATH)}subst.h
@ -2271,17 +2279,18 @@ symbol.$(OBJEXT): {$(VPATH)}encoding.h
symbol.$(OBJEXT): {$(VPATH)}gc.h symbol.$(OBJEXT): {$(VPATH)}gc.h
symbol.$(OBJEXT): {$(VPATH)}id.c symbol.$(OBJEXT): {$(VPATH)}id.c
symbol.$(OBJEXT): {$(VPATH)}id.h 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)}intern.h
symbol.$(OBJEXT): {$(VPATH)}internal.h symbol.$(OBJEXT): {$(VPATH)}internal.h
symbol.$(OBJEXT): {$(VPATH)}io.h symbol.$(OBJEXT): {$(VPATH)}io.h
symbol.$(OBJEXT): {$(VPATH)}missing.h symbol.$(OBJEXT): {$(VPATH)}missing.h
symbol.$(OBJEXT): {$(VPATH)}oniguruma.h symbol.$(OBJEXT): {$(VPATH)}oniguruma.h
symbol.$(OBJEXT): {$(VPATH)}probes.h symbol.$(OBJEXT): {$(VPATH)}probes.h
symbol.$(OBJEXT): {$(VPATH)}ruby_assert.h
symbol.$(OBJEXT): {$(VPATH)}st.h symbol.$(OBJEXT): {$(VPATH)}st.h
symbol.$(OBJEXT): {$(VPATH)}subst.h symbol.$(OBJEXT): {$(VPATH)}subst.h
symbol.$(OBJEXT): {$(VPATH)}symbol.c 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)}symbol.h
symbol.$(OBJEXT): {$(VPATH)}vm_opts.h symbol.$(OBJEXT): {$(VPATH)}vm_opts.h
thread.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.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.c
vm.$(OBJEXT): {$(VPATH)}vm.h vm.$(OBJEXT): {$(VPATH)}vm.h
vm.$(OBJEXT): {$(VPATH)}vm.inc vm.$(OBJEXT): {$(VPATH)}vm.inc
vm.$(OBJEXT): {$(VPATH)}vm_call_iseq_optimized.inc
vm.$(OBJEXT): {$(VPATH)}vm_args.c vm.$(OBJEXT): {$(VPATH)}vm_args.c
vm.$(OBJEXT): {$(VPATH)}vm_call_iseq_optimized.inc
vm.$(OBJEXT): {$(VPATH)}vm_core.h vm.$(OBJEXT): {$(VPATH)}vm_core.h
vm.$(OBJEXT): {$(VPATH)}vm_debug.h vm.$(OBJEXT): {$(VPATH)}vm_debug.h
vm.$(OBJEXT): {$(VPATH)}vm_eval.c 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_debug.h
vm_backtrace.$(OBJEXT): {$(VPATH)}vm_opts.h vm_backtrace.$(OBJEXT): {$(VPATH)}vm_opts.h
vm_call.$(OBJEXT): $(top_srcdir)/include/ruby.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_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)/check_type/check_type.h
vm_dump.$(OBJEXT): $(CCAN_DIR)/container_of/container_of.h vm_dump.$(OBJEXT): $(CCAN_DIR)/container_of/container_of.h
vm_dump.$(OBJEXT): $(CCAN_DIR)/list/list.h vm_dump.$(OBJEXT): $(CCAN_DIR)/list/list.h

View file

@ -14,7 +14,7 @@
#include "internal.h" #include "internal.h"
#define NDEBUG #define NDEBUG
#include <assert.h> #include "ruby_assert.h"
#define ZERO INT2FIX(0) #define ZERO INT2FIX(0)
#define ONE INT2FIX(1) #define ONE INT2FIX(1)

View file

@ -15,7 +15,7 @@
#include <ctype.h> #include <ctype.h>
#include "ruby/util.h" #include "ruby/util.h"
#include <assert.h> #include "ruby_assert.h"
#ifndef ENC_DEBUG #ifndef ENC_DEBUG
#define ENC_DEBUG 0 #define ENC_DEBUG 0
#endif #endif

13
error.c
View file

@ -11,6 +11,7 @@
#include "internal.h" #include "internal.h"
#include "ruby/st.h" #include "ruby/st.h"
#include "ruby_assert.h"
#include "vm_core.h" #include "vm_core.h"
#include <stdio.h> #include <stdio.h>
@ -499,6 +500,18 @@ rb_compile_bug_str(VALUE file, int line, const char *fmt, ...)
abort(); 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] = { static const char builtin_types[][10] = {
"", /* 0x00, */ "", /* 0x00, */
"Object", "Object",

2
gc.c
View file

@ -32,7 +32,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <setjmp.h> #include <setjmp.h>
#include <sys/types.h> #include <sys/types.h>
#include <assert.h> #include "ruby_assert.h"
#undef rb_data_object_wrap #undef rb_data_object_wrap

View file

@ -9,7 +9,7 @@
#if ID_TABLE_DEBUG == 0 #if ID_TABLE_DEBUG == 0
#define NDEBUG #define NDEBUG
#endif #endif
#include <assert.h> #include "ruby_assert.h"
/* /*
* st * st

View file

@ -14,7 +14,7 @@
#endif #endif
#define NDEBUG #define NDEBUG
#include <assert.h> #include "ruby_assert.h"
#if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H) #if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
#define USE_GMP #define USE_GMP

53
ruby_assert.h Normal file
View file

@ -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

View file

@ -16,7 +16,7 @@
#include "encindex.h" #include "encindex.h"
#include "probes.h" #include "probes.h"
#include "gc.h" #include "gc.h"
#include <assert.h> #include "ruby_assert.h"
#include "id.h" #include "id.h"
#define BEG(no) (regs->beg[(no)]) #define BEG(no) (regs->beg[(no)])