ruby-changes:61372
From: Koichi <ko1@a...>
Date: Tue, 26 May 2020 03:21:47 +0900 (JST)
Subject: [ruby-changes:61372] 21991e6ca5 (master): Use RUBY_DEBUG instead of NDEBUG
https://git.ruby-lang.org/ruby.git/commit/?id=21991e6ca5 From 21991e6ca59274e41a472b5256bd3245f6596c90 Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> Date: Wed, 20 May 2020 11:38:44 +0900 Subject: Use RUBY_DEBUG instead of NDEBUG Assertions in header files slows down an interpreter, so they should be turned off by default (simple `make`). To enable them, define a macro `RUBY_DEBUG=1` (e.g. `make cppflags=-DRUBY_DEBUG` or use `#define` at the very beggining of the file. Note that even if `NDEBUG=1` is defined, `RUBY_DEBUG=1` enables all assertions. [Feature #16837] related: https://github.com/ruby/ruby/pull/3120 `assert()` lines in MRI *.c is not disabled even if `RUBY_DEBUG=0` and it can be disabled with `NDEBUG=1`. So please consider to use `RUBY_ASSERT()` if you want to disable them when `RUBY_DEBUG=0`. diff --git a/include/ruby/assert.h b/include/ruby/assert.h index a79abea..41ecbd8 100644 --- a/include/ruby/assert.h +++ b/include/ruby/assert.h @@ -31,6 +31,10 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/assert.h#L31 # define RUBY_DEBUG 0 #endif +#if RUBY_DEBUG > 0 && defined(NDEBUG) +#warning NDEBUG is ignored because RUBY_DEBUG>0. +#endif + /* * Pro tip: `!!NDEBUG-1` expands to... * @@ -82,11 +86,12 @@ RBIMPL_SYMBOL_EXPORT_END() https://github.com/ruby/ruby/blob/trunk/include/ruby/assert.h#L86 RUBY_ASSERT_MESG(!(cond) || (expr), mesg)) #endif /* RUBY_DEBUG */ -#define RUBY_ASSERT(expr) RUBY_ASSERT_MESG_WHEN((!RUBY_NDEBUG+0), expr, #expr) +#define RUBY_ASSERT(expr) RUBY_ASSERT_MESG_WHEN(FALSE, expr, #expr) +#define RUBY_ASSERT_NDEBUG(expr) RUBY_ASSERT_MESG_WHEN(RUBY_NDEBUG, expr, #expr) #define RUBY_ASSERT_WHEN(cond, expr) RUBY_ASSERT_MESG_WHEN(cond, expr, #expr) -#define RUBY_ASSERT_ALWAYS(expr) RUBY_ASSERT_MESG_WHEN(TRUE, expr, #expr) +#define RUBY_ASSERT_ALWAYS(expr) RUBY_ASSERT_MESG_WHEN(TRUE, expr, #expr) -#if ! RUBY_NDEBUG +#if RUBY_DEBUG # define RBIMPL_ASSERT_OR_ASSUME(_) RUBY_ASSERT(_) #elif defined(RBIMPL_HAVE___ASSUME) # define RBIMPL_ASSERT_OR_ASSUME(_) RBIMPL_ASSUME(_) diff --git a/include/ruby/internal/arithmetic/char.h b/include/ruby/internal/arithmetic/char.h index 485bbd5..3033639 100644 --- a/include/ruby/internal/arithmetic/char.h +++ b/include/ruby/internal/arithmetic/char.h @@ -37,8 +37,8 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/arithmetic/char.h#L37 #define RB_CHR2FIX RB_CHR2FIX /** @endcond */ -RBIMPL_ATTR_CONST_ON_NDEBUG() -RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14) +RBIMPL_ATTR_CONST_UNLESS_DEBUG() +RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(CXX14) RBIMPL_ATTR_ARTIFICIAL() static inline VALUE RB_CHR2FIX(unsigned char c) diff --git a/include/ruby/internal/arithmetic/long.h b/include/ruby/internal/arithmetic/long.h index c0235b9..aff7d68 100644 --- a/include/ruby/internal/arithmetic/long.h +++ b/include/ruby/internal/arithmetic/long.h @@ -75,8 +75,8 @@ long rb_num2long(VALUE num); https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/arithmetic/long.h#L75 unsigned long rb_num2ulong(VALUE num); RBIMPL_SYMBOL_EXPORT_END() -RBIMPL_ATTR_CONST_ON_NDEBUG() -RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14) +RBIMPL_ATTR_CONST_UNLESS_DEBUG() +RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(CXX14) RBIMPL_ATTR_ARTIFICIAL() static inline VALUE RB_INT2FIX(long i) @@ -110,8 +110,8 @@ rb_long2int_inline(long n) https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/arithmetic/long.h#L110 return i; } -RBIMPL_ATTR_CONST_ON_NDEBUG() -RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14) +RBIMPL_ATTR_CONST_UNLESS_DEBUG() +RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(CXX14) static inline long rbimpl_fix2long_by_idiv(VALUE x) { @@ -128,8 +128,8 @@ rbimpl_fix2long_by_idiv(VALUE x) https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/arithmetic/long.h#L128 return w; } -RBIMPL_ATTR_CONST_ON_NDEBUG() -RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14) +RBIMPL_ATTR_CONST_UNLESS_DEBUG() +RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(CXX14) static inline long rbimpl_fix2long_by_shift(VALUE x) { @@ -153,8 +153,8 @@ rbimpl_right_shift_is_arithmetic_p(void) https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/arithmetic/long.h#L153 return (-1 >> 1) == -1; } -RBIMPL_ATTR_CONST_ON_NDEBUG() -RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14) +RBIMPL_ATTR_CONST_UNLESS_DEBUG() +RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(CXX14) static inline long rb_fix2long(VALUE x) { @@ -166,8 +166,8 @@ rb_fix2long(VALUE x) https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/arithmetic/long.h#L166 } } -RBIMPL_ATTR_CONST_ON_NDEBUG() -RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14) +RBIMPL_ATTR_CONST_UNLESS_DEBUG() +RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(CXX14) static inline unsigned long rb_fix2ulong(VALUE x) { diff --git a/include/ruby/internal/arithmetic/st_data_t.h b/include/ruby/internal/arithmetic/st_data_t.h index 01917ab..93a5ccb 100644 --- a/include/ruby/internal/arithmetic/st_data_t.h +++ b/include/ruby/internal/arithmetic/st_data_t.h @@ -35,8 +35,8 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/arithmetic/st_data_t.h#L35 #define RB_ST2FIX RB_ST2FIX /** @endcond */ -RBIMPL_ATTR_CONST_ON_NDEBUG() -RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14) +RBIMPL_ATTR_CONST_UNLESS_DEBUG() +RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(CXX14) RBIMPL_ATTR_ARTIFICIAL() /* See also [ruby-core:84395] [Bug #14218] [ruby-core:82687] [Bug #13877] */ static inline VALUE diff --git a/include/ruby/internal/attr/const.h b/include/ruby/internal/attr/const.h index ca9baa7..f3068f9 100644 --- a/include/ruby/internal/attr/const.h +++ b/include/ruby/internal/attr/const.h @@ -36,11 +36,11 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/attr/const.h#L36 # define RBIMPL_ATTR_CONST() /* void */ #endif -/** Enables #RBIMPL_ATTR_CONST iff. #RUBY_NDEBUG. */ -#if RUBY_NDEBUG -# define RBIMPL_ATTR_CONST_ON_NDEBUG() RBIMPL_ATTR_CONST() +/** Enables #RBIMPL_ATTR_CONST iff. !RUBY_DEBUG. */ +#if !RUBY_DEBUG +# define RBIMPL_ATTR_CONST_UNLESS_DEBUG() RBIMPL_ATTR_CONST() #else -# define RBIMPL_ATTR_CONST_ON_NDEBUG() /* void */ +# define RBIMPL_ATTR_CONST_UNLESS_DEBUG() /* void */ #endif #endif /* RBIMPL_ATTR_CONST_H */ diff --git a/include/ruby/internal/attr/constexpr.h b/include/ruby/internal/attr/constexpr.h index 0ccd8f2..6d81d34 100644 --- a/include/ruby/internal/attr/constexpr.h +++ b/include/ruby/internal/attr/constexpr.h @@ -75,11 +75,11 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/attr/constexpr.h#L75 # define RBIMPL_ATTR_CONSTEXPR(_) /* void */ #endif -/** Enables #RBIMPL_ATTR_CONSTEXPR iff. #RUBY_NDEBUG. */ -#if RUBY_NDEBUG -# define RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(_) RBIMPL_ATTR_CONSTEXPR(_) +/** Enables #RBIMPL_ATTR_CONSTEXPR iff. !RUBY_DEBUG. */ +#if !RUBY_DEBUG +# define RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(_) RBIMPL_ATTR_CONSTEXPR(_) #else -# define RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(_) /* void */ +# define RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(_) /* void */ #endif #endif /* RBIMPL_ATTR_CONSTEXPR_H */ diff --git a/include/ruby/internal/attr/pure.h b/include/ruby/internal/attr/pure.h index b6aca7b..b27adaa 100644 --- a/include/ruby/internal/attr/pure.h +++ b/include/ruby/internal/attr/pure.h @@ -33,11 +33,11 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/attr/pure.h#L33 # define RBIMPL_ATTR_PURE() /* void */ #endif -/** Enables #RBIMPL_ATTR_PURE iff. #RUBY_NDEBUG. */ -#if RUBY_NDEBUG -# define RBIMPL_ATTR_PURE_ON_NDEBUG() RBIMPL_ATTR_PURE() +/** Enables #RBIMPL_ATTR_PURE iff. !RUBY_DEBUG. */ +#if !RUBY_DEBUG +# define RBIMPL_ATTR_PURE_UNLESS_DEBUG() RBIMPL_ATTR_PURE() #else -# define RBIMPL_ATTR_PURE_ON_NDEBUG() /* void */ +# define RBIMPL_ATTR_PURE_UNLESS_DEBUG() /* void */ #endif #endif /* RBIMPL_ATTR_PURE_H */ diff --git a/include/ruby/internal/core/rarray.h b/include/ruby/internal/core/rarray.h index ea2abe6..a21500e 100644 --- a/include/ruby/internal/core/rarray.h +++ b/include/ruby/internal/core/rarray.h @@ -112,7 +112,7 @@ void rb_ary_detransient(VALUE a); https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/rarray.h#L112 #endif RBIMPL_SYMBOL_EXPORT_END() -RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_PURE_UNLESS_DEBUG() RBIMPL_ATTR_ARTIFICIAL() static inline long RARRAY_EMBED_LEN(VALUE ary) @@ -126,7 +126,7 @@ RARRAY_EMBED_LEN(VALUE ary) https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/rarray.h#L126 return RBIMPL_CAST((long)f); } -RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_PURE_UNLESS_DEBUG() static inline long rb_array_len(VALUE a) { @@ -147,7 +147,7 @@ RARRAY_LENINT(VALUE ary) https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/rarray.h#L147 return rb_long2int(RARRAY_LEN(ary)); } -RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_PURE_UNLESS_DEBUG() RBIMPL_ATTR_ARTIFICIAL() static inline bool RARRAY_TRANSIENT_P(VALUE ary) @@ -161,7 +161,7 @@ RARRAY_TRANSIENT_P(VALUE ary) https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/rarray.h#L161 #endif } -RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_PURE_UNLESS_DEBUG() /* internal function. do not use this function */ static inline const VALUE * rb_array_const_ptr_transient(VALUE a) @@ -177,7 +177,7 @@ rb_array_const_ptr_transient(VALUE a) https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/rarray.h#L177 } #if ! USE_TRANSIENT_HEAP -RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_PURE_UNLESS_DEBUG() #endif /* internal function. do not use this function */ static inline const VALUE * @@ -258,7 +258,7 @@ RARRAY_ASET(VALUE ary, long i, VALUE v) https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/rarray.h#L258 /* RARRAY_AREF is used as a lvalue. Cannot be a function. */ #if 0 -RBIMPL_ATTR_PURE_ON_NDEBUG() +RBIMPL_ATTR_PURE_UNLESS_DEBUG() RBIMPL_ATTR_ARTIFICIAL() static inline VALUE RARRAY_AREF(VALUE ary, long i) diff --git a/include/ruby/internal/core/rbasic.h b/include/ruby/internal/core/rbasic.h index 76333fd..2b578b6 100644 --- a/include/ruby/internal/core/rbasic.h +++ b/include/ruby/i (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/