Skip to content

Commit 439224a

Browse files
committed
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
1 parent e5850a8 commit 439224a

12 files changed

+93
-12
lines changed

ChangeLog

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Fri Jan 22 17:33:05 2016 Nobuyoshi Nakada <[email protected]>
2+
3+
* error.c (rb_assert_failure): assertion with stack dump.
4+
5+
* ruby_assert.h (RUBY_ASSERT): new header for the assertion.
6+
17
Fri Jan 22 00:25:57 2016 NARUSE, Yui <[email protected]>
28

39
* regparse.c (fetch_name_with_level): allow non word characters

array.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#ifndef ARRAY_DEBUG
2121
# define NDEBUG
2222
#endif
23-
#include <assert.h>
23+
#include "ruby_assert.h"
2424

2525
VALUE rb_cArray;
2626

bignum.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#ifdef HAVE_IEEEFP_H
2323
#include <ieeefp.h>
2424
#endif
25-
#include <assert.h>
25+
#include "ruby_assert.h"
2626

2727
#if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
2828
#define USE_GMP

common.mk

+13-4
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,7 @@ array.$(OBJEXT): {$(VPATH)}io.h
11331133
array.$(OBJEXT): {$(VPATH)}missing.h
11341134
array.$(OBJEXT): {$(VPATH)}oniguruma.h
11351135
array.$(OBJEXT): {$(VPATH)}probes.h
1136+
array.$(OBJEXT): {$(VPATH)}ruby_assert.h
11361137
array.$(OBJEXT): {$(VPATH)}st.h
11371138
array.$(OBJEXT): {$(VPATH)}subst.h
11381139
array.$(OBJEXT): {$(VPATH)}util.h
@@ -1148,6 +1149,7 @@ bignum.$(OBJEXT): {$(VPATH)}internal.h
11481149
bignum.$(OBJEXT): {$(VPATH)}io.h
11491150
bignum.$(OBJEXT): {$(VPATH)}missing.h
11501151
bignum.$(OBJEXT): {$(VPATH)}oniguruma.h
1152+
bignum.$(OBJEXT): {$(VPATH)}ruby_assert.h
11511153
bignum.$(OBJEXT): {$(VPATH)}st.h
11521154
bignum.$(OBJEXT): {$(VPATH)}subst.h
11531155
bignum.$(OBJEXT): {$(VPATH)}thread.h
@@ -1232,6 +1234,7 @@ complex.$(OBJEXT): {$(VPATH)}internal.h
12321234
complex.$(OBJEXT): {$(VPATH)}io.h
12331235
complex.$(OBJEXT): {$(VPATH)}missing.h
12341236
complex.$(OBJEXT): {$(VPATH)}oniguruma.h
1237+
complex.$(OBJEXT): {$(VPATH)}ruby_assert.h
12351238
complex.$(OBJEXT): {$(VPATH)}st.h
12361239
complex.$(OBJEXT): {$(VPATH)}subst.h
12371240
cont.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h
@@ -1389,6 +1392,7 @@ encoding.$(OBJEXT): {$(VPATH)}io.h
13891392
encoding.$(OBJEXT): {$(VPATH)}missing.h
13901393
encoding.$(OBJEXT): {$(VPATH)}oniguruma.h
13911394
encoding.$(OBJEXT): {$(VPATH)}regenc.h
1395+
encoding.$(OBJEXT): {$(VPATH)}ruby_assert.h
13921396
encoding.$(OBJEXT): {$(VPATH)}st.h
13931397
encoding.$(OBJEXT): {$(VPATH)}subst.h
13941398
encoding.$(OBJEXT): {$(VPATH)}util.h
@@ -1439,6 +1443,7 @@ error.$(OBJEXT): {$(VPATH)}method.h
14391443
error.$(OBJEXT): {$(VPATH)}missing.h
14401444
error.$(OBJEXT): {$(VPATH)}node.h
14411445
error.$(OBJEXT): {$(VPATH)}oniguruma.h
1446+
error.$(OBJEXT): {$(VPATH)}ruby_assert.h
14421447
error.$(OBJEXT): {$(VPATH)}ruby_atomic.h
14431448
error.$(OBJEXT): {$(VPATH)}st.h
14441449
error.$(OBJEXT): {$(VPATH)}subst.h
@@ -1525,6 +1530,7 @@ gc.$(OBJEXT): {$(VPATH)}re.h
15251530
gc.$(OBJEXT): {$(VPATH)}regenc.h
15261531
gc.$(OBJEXT): {$(VPATH)}regex.h
15271532
gc.$(OBJEXT): {$(VPATH)}regint.h
1533+
gc.$(OBJEXT): {$(VPATH)}ruby_assert.h
15281534
gc.$(OBJEXT): {$(VPATH)}ruby_atomic.h
15291535
gc.$(OBJEXT): {$(VPATH)}st.h
15301536
gc.$(OBJEXT): {$(VPATH)}subst.h
@@ -1984,6 +1990,7 @@ rational.$(OBJEXT): {$(VPATH)}io.h
19841990
rational.$(OBJEXT): {$(VPATH)}missing.h
19851991
rational.$(OBJEXT): {$(VPATH)}oniguruma.h
19861992
rational.$(OBJEXT): {$(VPATH)}rational.c
1993+
rational.$(OBJEXT): {$(VPATH)}ruby_assert.h
19871994
rational.$(OBJEXT): {$(VPATH)}st.h
19881995
rational.$(OBJEXT): {$(VPATH)}subst.h
19891996
re.$(OBJEXT): $(hdrdir)/ruby/ruby.h
@@ -2227,6 +2234,7 @@ string.$(OBJEXT): {$(VPATH)}oniguruma.h
22272234
string.$(OBJEXT): {$(VPATH)}probes.h
22282235
string.$(OBJEXT): {$(VPATH)}re.h
22292236
string.$(OBJEXT): {$(VPATH)}regex.h
2237+
string.$(OBJEXT): {$(VPATH)}ruby_assert.h
22302238
string.$(OBJEXT): {$(VPATH)}st.h
22312239
string.$(OBJEXT): {$(VPATH)}string.c
22322240
string.$(OBJEXT): {$(VPATH)}subst.h
@@ -2271,17 +2279,18 @@ symbol.$(OBJEXT): {$(VPATH)}encoding.h
22712279
symbol.$(OBJEXT): {$(VPATH)}gc.h
22722280
symbol.$(OBJEXT): {$(VPATH)}id.c
22732281
symbol.$(OBJEXT): {$(VPATH)}id.h
2282+
symbol.$(OBJEXT): {$(VPATH)}id_table.c
2283+
symbol.$(OBJEXT): {$(VPATH)}id_table.h
22742284
symbol.$(OBJEXT): {$(VPATH)}intern.h
22752285
symbol.$(OBJEXT): {$(VPATH)}internal.h
22762286
symbol.$(OBJEXT): {$(VPATH)}io.h
22772287
symbol.$(OBJEXT): {$(VPATH)}missing.h
22782288
symbol.$(OBJEXT): {$(VPATH)}oniguruma.h
22792289
symbol.$(OBJEXT): {$(VPATH)}probes.h
2290+
symbol.$(OBJEXT): {$(VPATH)}ruby_assert.h
22802291
symbol.$(OBJEXT): {$(VPATH)}st.h
22812292
symbol.$(OBJEXT): {$(VPATH)}subst.h
22822293
symbol.$(OBJEXT): {$(VPATH)}symbol.c
2283-
symbol.$(OBJEXT): {$(VPATH)}id_table.c
2284-
symbol.$(OBJEXT): {$(VPATH)}id_table.h
22852294
symbol.$(OBJEXT): {$(VPATH)}symbol.h
22862295
symbol.$(OBJEXT): {$(VPATH)}vm_opts.h
22872296
thread.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h
@@ -2419,8 +2428,8 @@ vm.$(OBJEXT): {$(VPATH)}thread_native.h
24192428
vm.$(OBJEXT): {$(VPATH)}vm.c
24202429
vm.$(OBJEXT): {$(VPATH)}vm.h
24212430
vm.$(OBJEXT): {$(VPATH)}vm.inc
2422-
vm.$(OBJEXT): {$(VPATH)}vm_call_iseq_optimized.inc
24232431
vm.$(OBJEXT): {$(VPATH)}vm_args.c
2432+
vm.$(OBJEXT): {$(VPATH)}vm_call_iseq_optimized.inc
24242433
vm.$(OBJEXT): {$(VPATH)}vm_core.h
24252434
vm.$(OBJEXT): {$(VPATH)}vm_debug.h
24262435
vm.$(OBJEXT): {$(VPATH)}vm_eval.c
@@ -2461,8 +2470,8 @@ vm_backtrace.$(OBJEXT): {$(VPATH)}vm_core.h
24612470
vm_backtrace.$(OBJEXT): {$(VPATH)}vm_debug.h
24622471
vm_backtrace.$(OBJEXT): {$(VPATH)}vm_opts.h
24632472
vm_call.$(OBJEXT): $(top_srcdir)/include/ruby.h
2464-
vm_call.$(OBJEXT): {$(VPATH)}vm_core.h
24652473
vm_call.$(OBJEXT): {$(VPATH)}vm_call_iseq_optimized.inc
2474+
vm_call.$(OBJEXT): {$(VPATH)}vm_core.h
24662475
vm_dump.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h
24672476
vm_dump.$(OBJEXT): $(CCAN_DIR)/container_of/container_of.h
24682477
vm_dump.$(OBJEXT): $(CCAN_DIR)/list/list.h

complex.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "internal.h"
1515

1616
#define NDEBUG
17-
#include <assert.h>
17+
#include "ruby_assert.h"
1818

1919
#define ZERO INT2FIX(0)
2020
#define ONE INT2FIX(1)

encoding.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <ctype.h>
1616
#include "ruby/util.h"
1717

18-
#include <assert.h>
18+
#include "ruby_assert.h"
1919
#ifndef ENC_DEBUG
2020
#define ENC_DEBUG 0
2121
#endif

error.c

+13
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "internal.h"
1313
#include "ruby/st.h"
14+
#include "ruby_assert.h"
1415
#include "vm_core.h"
1516

1617
#include <stdio.h>
@@ -499,6 +500,18 @@ rb_compile_bug_str(VALUE file, int line, const char *fmt, ...)
499500
abort();
500501
}
501502

503+
void
504+
rb_assert_failure(const char *file, int line, const char *name, const char *expr)
505+
{
506+
FILE *out = stderr;
507+
fprintf(out, "Assertion Failed: %s:%d:", file, line);
508+
if (name) fprintf(out, "%s:", name);
509+
fprintf(out, "%s\n%s\n\n", expr, ruby_description);
510+
rb_vm_bugreport(NULL);
511+
bug_report_end(out);
512+
die();
513+
}
514+
502515
static const char builtin_types[][10] = {
503516
"", /* 0x00, */
504517
"Object",

gc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include <stdarg.h>
3333
#include <setjmp.h>
3434
#include <sys/types.h>
35-
#include <assert.h>
35+
#include "ruby_assert.h"
3636

3737
#undef rb_data_object_wrap
3838

id_table.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#if ID_TABLE_DEBUG == 0
1010
#define NDEBUG
1111
#endif
12-
#include <assert.h>
12+
#include "ruby_assert.h"
1313

1414
/*
1515
* st

rational.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#endif
1515

1616
#define NDEBUG
17-
#include <assert.h>
17+
#include "ruby_assert.h"
1818

1919
#if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
2020
#define USE_GMP

ruby_assert.h

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
35+
#undef assert
36+
#define assert RUBY_ASSERT
37+
38+
#ifndef RUBY_NDEBUG
39+
# ifdef NDEBUG
40+
# define RUBY_NDEBUG 1
41+
# else
42+
# define RUBY_NDEBUG 0
43+
# endif
44+
#endif
45+
46+
#if defined(__cplusplus)
47+
#if 0
48+
{ /* satisfy cc-mode */
49+
#endif
50+
} /* extern "C" { */
51+
#endif
52+
53+
#endif

string.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "encindex.h"
1717
#include "probes.h"
1818
#include "gc.h"
19-
#include <assert.h>
19+
#include "ruby_assert.h"
2020
#include "id.h"
2121

2222
#define BEG(no) (regs->beg[(no)])

0 commit comments

Comments
 (0)