[前][次][番号順一覧][スレッド一覧]

ruby-changes:41541

From: nobu <ko1@a...>
Date: Fri, 22 Jan 2016 17:33:12 +0900 (JST)
Subject: [ruby-changes:41541] nobu:r53615 (trunk): RUBY_ASSERT

nobu	2016-01-22 17:33:55 +0900 (Fri, 22 Jan 2016)

  New Revision: 53615

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53615

  Log:
    RUBY_ASSERT
    
    * error.c (rb_assert_failure): assertion with stack dump.
    * ruby_assert.h (RUBY_ASSERT): new header for the assertion.

  Added files:
    trunk/ruby_assert.h
  Modified files:
    trunk/ChangeLog
    trunk/array.c
    trunk/bignum.c
    trunk/common.mk
    trunk/complex.c
    trunk/encoding.c
    trunk/error.c
    trunk/gc.c
    trunk/id_table.c
    trunk/rational.c
    trunk/string.c
Index: rational.c
===================================================================
--- rational.c	(revision 53614)
+++ rational.c	(revision 53615)
@@ -14,7 +14,7 @@ https://github.com/ruby/ruby/blob/trunk/rational.c#L14
 #endif
 
 #define NDEBUG
-#include <assert.h>
+#include "ruby_assert.h"
 
 #if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
 #define USE_GMP
Index: error.c
===================================================================
--- error.c	(revision 53614)
+++ error.c	(revision 53615)
@@ -11,6 +11,7 @@ https://github.com/ruby/ruby/blob/trunk/error.c#L11
 
 #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, https://github.com/ruby/ruby/blob/trunk/error.c#L500
     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",
Index: bignum.c
===================================================================
--- bignum.c	(revision 53614)
+++ bignum.c	(revision 53615)
@@ -22,7 +22,7 @@ https://github.com/ruby/ruby/blob/trunk/bignum.c#L22
 #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
Index: encoding.c
===================================================================
--- encoding.c	(revision 53614)
+++ encoding.c	(revision 53615)
@@ -15,7 +15,7 @@ https://github.com/ruby/ruby/blob/trunk/encoding.c#L15
 #include <ctype.h>
 #include "ruby/util.h"
 
-#include <assert.h>
+#include "ruby_assert.h"
 #ifndef ENC_DEBUG
 #define ENC_DEBUG 0
 #endif
Index: id_table.c
===================================================================
--- id_table.c	(revision 53614)
+++ id_table.c	(revision 53615)
@@ -9,7 +9,7 @@ https://github.com/ruby/ruby/blob/trunk/id_table.c#L9
 #if ID_TABLE_DEBUG == 0
 #define NDEBUG
 #endif
-#include <assert.h>
+#include "ruby_assert.h"
 
 /*
  * st
Index: complex.c
===================================================================
--- complex.c	(revision 53614)
+++ complex.c	(revision 53615)
@@ -14,7 +14,7 @@ https://github.com/ruby/ruby/blob/trunk/complex.c#L14
 #include "internal.h"
 
 #define NDEBUG
-#include <assert.h>
+#include "ruby_assert.h"
 
 #define ZERO INT2FIX(0)
 #define ONE INT2FIX(1)
Index: gc.c
===================================================================
--- gc.c	(revision 53614)
+++ gc.c	(revision 53615)
@@ -32,7 +32,7 @@ https://github.com/ruby/ruby/blob/trunk/gc.c#L32
 #include <stdarg.h>
 #include <setjmp.h>
 #include <sys/types.h>
-#include <assert.h>
+#include "ruby_assert.h"
 
 #undef rb_data_object_wrap
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53614)
+++ ChangeLog	(revision 53615)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jan 22 17:33:05 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* regparse.c (fetch_name_with_level): allow non word characters
Index: ruby_assert.h
===================================================================
--- ruby_assert.h	(revision 0)
+++ ruby_assert.h	(revision 53615)
@@ -0,0 +1,53 @@ https://github.com/ruby/ruby/blob/trunk/ruby_assert.h#L1
+#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

Property changes on: ruby_assert.h
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: array.c
===================================================================
--- array.c	(revision 53614)
+++ array.c	(revision 53615)
@@ -20,7 +20,7 @@ https://github.com/ruby/ruby/blob/trunk/array.c#L20
 #ifndef ARRAY_DEBUG
 # define NDEBUG
 #endif
-#include <assert.h>
+#include "ruby_assert.h"
 
 VALUE rb_cArray;
 
Index: string.c
===================================================================
--- string.c	(revision 53614)
+++ string.c	(revision 53615)
@@ -16,7 +16,7 @@ https://github.com/ruby/ruby/blob/trunk/string.c#L16
 #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)])
Index: common.mk
===================================================================
--- common.mk	(revision 53614)
+++ common.mk	(revision 53615)
@@ -1133,6 +1133,7 @@ array.$(OBJEXT): {$(VPATH)}io.h https://github.com/ruby/ruby/blob/trunk/common.mk#L1133
 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 https://github.com/ruby/ruby/blob/trunk/common.mk#L1149
 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 https://github.com/ruby/ruby/blob/trunk/common.mk#L1234
 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 https://github.com/ruby/ruby/blob/trunk/common.mk#L1392
 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 https://github.com/ruby/ruby/blob/trunk/common.mk#L1443
 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 https://github.com/ruby/ruby/blob/trunk/common.mk#L1530
 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 https://github.com/ruby/ruby/blob/trunk/common.mk#L1990
 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 https://github.com/ruby/ruby/blob/trunk/common.mk#L2234
 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 https://github.com/ruby/ruby/blob/trunk/common.mk#L2279
 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 https://github.com/ruby/ruby/blob/trunk/common.mk#L2428
 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_cor https://github.com/ruby/ruby/blob/trunk/common.mk#L2470
 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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]