mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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`.
This commit is contained in:
parent
b10b37924a
commit
21991e6ca5
Notes:
git
2020-05-26 03:21:52 +09:00
19 changed files with 82 additions and 82 deletions
|
@ -31,6 +31,10 @@
|
|||
# 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()
|
|||
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(_)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue