Ruby: include/ruby/assert.h File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Macros
assert.h File Reference
`#include "ruby/internal/assume.h"`
`#include "ruby/internal/attr/cold.h"`
`#include "ruby/internal/attr/noreturn.h"`
`#include "ruby/internal/cast.h"`
`#include "ruby/internal/dllexport.h"`
`#include "ruby/backward/2/assume.h"`

Go to the source code of this file.

## Macros
#define | RUBY_DEBUG 0
| Define this macro when you want assertions. More...
#define | NDEBUG
| Define this macro when you don't want assertions. More...
#define | RUBY_NDEBUG 1
| This macro is basically the same as NDEBUG. More...
#define | RUBY_ASSERT_FAIL(mesg) rb_assert_failure(__FILE__, __LINE__, RBIMPL_ASSERT_FUNC, mesg)
| Prints the given message, and terminates the entire process abnormally. More...
#define | RUBY_ASSERT_MESG(expr, mesg) (RB_LIKELY(expr) ? RBIMPL_ASSERT_NOTHING : RUBY_ASSERT_FAIL(mesg))
| Asserts that the expression is truthy. More...
#define | RUBY_ASSERT_ALWAYS(expr) RUBY_ASSERT_MESG((expr), #expr)
| A variant of RUBY_ASSERT that does not interface with RUBY_DEBUG. More...
#define | RUBY_ASSERT(expr) RBIMPL_ASSERT_NOTHING
| Asserts that the given expression is truthy iff RUBY_DEBUG is truthy. More...
#define | RUBY_ASSERT_NDEBUG(expr) RBIMPL_ASSERT_NOTHING
| A variant of RUBY_ASSERT that interfaces with NDEBUG instead of RUBY_DEBUG. More...
#define | RUBY_ASSERT_MESG_WHEN(cond, expr, mesg) ((cond) ? RUBY_ASSERT_MESG((expr), (mesg)) : RBIMPL_ASSERT_NOTHING)
| A variant of RUBY_ASSERT that asserts when either RUBY_DEBUG or `cond` parameter is truthy. More...
#define | RUBY_ASSERT_WHEN(cond, expr) RUBY_ASSERT_MESG_WHEN((cond), (expr), #expr)
| A variant of RUBY_ASSERT that asserts when either RUBY_DEBUG or `cond` parameter is truthy. More...
#define | RBIMPL_ASSERT_OR_ASSUME(expr) RBIMPL_ASSERT_NOTHING
| This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG. More...

## Detailed Description

Author
  Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org

Date
  Wed May 18 00:21:44 JST 1994

Copyright
  This file is a part of the programming language Ruby. Permission is hereby granted, to either redistribute and/or modify this file, provided that the conditions mentioned in the file COPYING are met. Consult the file for details.

Warning
  Symbols prefixed with either `RBIMPL` or `rbimpl` are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will.

Note
  To ruby-core: remember that this header can be possibly recursively included from extension libraries written in C++. Do not expect for instance `__VA_ARGS__` is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98.

Definition in file assert.h.

## Macro Definition Documentation

## ◆ NDEBUG

#define NDEBUG

Define this macro when you don't want assertions.

Definition at line 89 of file assert.h.

## ◆ RBIMPL_ASSERT_OR_ASSUME

#define RBIMPL_ASSERT_OR_ASSUME | ( |  | expr | ) | RBIMPL_ASSERT_NOTHING

This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.

Parameters

  expr | What supposedly evaluates to true.

Definition at line 229 of file assert.h.

## ◆ RUBY_ASSERT

#define RUBY_ASSERT | ( |  | expr | ) | RBIMPL_ASSERT_NOTHING

Asserts that the given expression is truthy iff RUBY_DEBUG is truthy.

Parameters

  expr | What supposedly evaluates to true.

Definition at line 177 of file assert.h.

## ◆ RUBY_ASSERT_ALWAYS

#define RUBY_ASSERT_ALWAYS | ( |  | expr | ) | RUBY_ASSERT_MESG((expr), #expr)

A variant of RUBY_ASSERT that does not interface with RUBY_DEBUG.

Parameters

  expr | What supposedly evaluates to true.

Definition at line 167 of file assert.h.

## ◆ RUBY_ASSERT_FAIL

#define RUBY_ASSERT_FAIL | ( |  | mesg | ) | rb_assert_failure(__FILE__, __LINE__, RBIMPL_ASSERT_FUNC, mesg)

Prints the given message, and terminates the entire process abnormally.

Parameters

  mesg | The message to display.

Definition at line 150 of file assert.h.

## ◆ RUBY_ASSERT_MESG

#define RUBY_ASSERT_MESG | ( |  | expr,
|  |  | mesg
| ) |  | (RB_LIKELY(expr) ? RBIMPL_ASSERT_NOTHING : RUBY_ASSERT_FAIL(mesg))

Asserts that the expression is truthy.

If not aborts with the message.

Parameters

  expr | What supposedly evaluates to true.
  mesg | The message to display on failure.

Definition at line 159 of file assert.h.

## ◆ RUBY_ASSERT_MESG_WHEN

#define RUBY_ASSERT_MESG_WHEN | ( |  | cond,
|  |  | expr,
|  |  | mesg
| ) |  | ((cond) ? RUBY_ASSERT_MESG((expr), (mesg)) : RBIMPL_ASSERT_NOTHING)

A variant of RUBY_ASSERT that asserts when either RUBY_DEBUG or `cond` parameter is truthy.

Parameters

  cond | Extra condition that shall hold for assertion to take effect.
  expr | What supposedly evaluates to true.
  mesg | The message to display on failure.

Definition at line 202 of file assert.h.

## ◆ RUBY_ASSERT_NDEBUG

#define RUBY_ASSERT_NDEBUG | ( |  | expr | ) | RBIMPL_ASSERT_NOTHING

A variant of RUBY_ASSERT that interfaces with NDEBUG instead of RUBY_DEBUG.

This almost resembles `assert` C standard macro, except minor implementation details.

Parameters

  expr | What supposedly evaluates to true.

Definition at line 190 of file assert.h.

## ◆ RUBY_ASSERT_WHEN

#define RUBY_ASSERT_WHEN | ( |  | cond,
|  |  | expr
| ) |  | RUBY_ASSERT_MESG_WHEN((cond), (expr), #expr)

A variant of RUBY_ASSERT that asserts when either RUBY_DEBUG or `cond` parameter is truthy.

Parameters

  cond | Extra condition that shall hold for assertion to take effect.
  expr | What supposedly evaluates to true.

Definition at line 213 of file assert.h.

## ◆ RUBY_DEBUG

#define RUBY_DEBUG 0

Define this macro when you want assertions.

Definition at line 87 of file assert.h.

## ◆ RUBY_NDEBUG

#define RUBY_NDEBUG 1

This macro is basically the same as NDEBUG.

Definition at line 91 of file assert.h.