Ruby  3.4.0dev (2024-11-05 revision 348a53415339076afc4a02fcd09f3ae36e9c4c61)
Macros | Enumerations | Functions
special_consts.h File Reference

(348a53415339076afc4a02fcd09f3ae36e9c4c61)

Defines enum ruby_special_consts. More...

#include "ruby/internal/attr/artificial.h"
#include "ruby/internal/attr/const.h"
#include "ruby/internal/attr/constexpr.h"
#include "ruby/internal/attr/enum_extensibility.h"
#include "ruby/internal/stdbool.h"
#include "ruby/internal/value.h"
Include dependency graph for special_consts.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define USE_FLONUM   1
 
#define RTEST   RB_TEST
 This is an old name of RB_TEST. More...
 
#define FIXNUM_P   RB_FIXNUM_P
 Old name of RB_FIXNUM_P. More...
 
#define IMMEDIATE_P   RB_IMMEDIATE_P
 Old name of RB_IMMEDIATE_P. More...
 
#define NIL_P   RB_NIL_P
 Old name of RB_NIL_P. More...
 
#define SPECIAL_CONST_P   RB_SPECIAL_CONST_P
 Old name of RB_SPECIAL_CONST_P. More...
 
#define STATIC_SYM_P   RB_STATIC_SYM_P
 Old name of RB_STATIC_SYM_P. More...
 
#define Qfalse   RUBY_Qfalse
 Old name of RUBY_Qfalse. More...
 
#define Qnil   RUBY_Qnil
 Old name of RUBY_Qnil. More...
 
#define Qtrue   RUBY_Qtrue
 Old name of RUBY_Qtrue. More...
 
#define Qundef   RUBY_Qundef
 Old name of RUBY_Qundef. More...
 
#define FIXNUM_FLAG   RUBY_FIXNUM_FLAG
 Old name of RUBY_FIXNUM_FLAG. More...
 
#define FLONUM_FLAG   RUBY_FLONUM_FLAG
 Old name of RUBY_FLONUM_FLAG. More...
 
#define FLONUM_MASK   RUBY_FLONUM_MASK
 Old name of RUBY_FLONUM_MASK. More...
 
#define FLONUM_P   RB_FLONUM_P
 Old name of RB_FLONUM_P. More...
 
#define IMMEDIATE_MASK   RUBY_IMMEDIATE_MASK
 Old name of RUBY_IMMEDIATE_MASK. More...
 
#define SYMBOL_FLAG   RUBY_SYMBOL_FLAG
 Old name of RUBY_SYMBOL_FLAG. More...
 

Enumerations

enum  ruby_special_consts {
  RUBY_Qfalse , RUBY_Qtrue , RUBY_Qnil , RUBY_Qundef ,
  RUBY_IMMEDIATE_MASK , RUBY_FIXNUM_FLAG , RUBY_FLONUM_MASK , RUBY_FLONUM_FLAG ,
  RUBY_SYMBOL_FLAG , RUBY_SPECIAL_SHIFT = 8
}
 special constants - i.e. More...
 

Functions

static bool RB_TEST (VALUE obj)
 Emulates Ruby's "if" statement. More...
 
static bool RB_NIL_P (VALUE obj)
 Checks if the given object is nil. More...
 
static bool RB_UNDEF_P (VALUE obj)
 Checks if the given object is undef. More...
 
static bool RB_NIL_OR_UNDEF_P (VALUE obj)
 Checks if the given object is nil or undef. More...
 
static bool RB_FIXNUM_P (VALUE obj)
 Checks if the given object is a so-called Fixnum. More...
 
static bool RB_STATIC_SYM_P (VALUE obj)
 Checks if the given object is a static symbol. More...
 
static bool RB_FLONUM_P (VALUE obj)
 Checks if the given object is a so-called Flonum. More...
 
static bool RB_IMMEDIATE_P (VALUE obj)
 Checks if the given object is an immediate i.e. More...
 
static bool RB_SPECIAL_CONST_P (VALUE obj)
 Checks if the given object is of enum ruby_special_consts. More...
 
static VALUE rb_special_const_p (VALUE obj)
 Identical to RB_SPECIAL_CONST_P, except it returns a VALUE. More...
 

Detailed Description

Defines enum ruby_special_consts.

Author
Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org
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.
See also
Sasada, K., "A Lightweight Representation of Floating-Point Numbers on Ruby Interpreter", in proceedings of 10th JSSST SIGPPL Workshop on Programming and Programming Languages (PPL2008), pp. 9-16, 2008.

Definition in file special_consts.h.

Macro Definition Documentation

◆ RTEST

#define RTEST   RB_TEST

This is an old name of RB_TEST.

Not sure which name is preferred.

Definition at line 51 of file special_consts.h.

◆ USE_FLONUM

#define USE_FLONUM   1
Warning
Do not touch this macro.
It is an implementation detail.
The value of this macro must match for ruby itself and all extension libraries, otherwise serious memory corruption shall occur.

Definition at line 45 of file special_consts.h.

Enumeration Type Documentation

◆ ruby_special_consts

special constants - i.e.

non-zero and non-fixnum constants

Enumerator
RUBY_Qfalse 
See also
rb_cFalseClass
RUBY_Qtrue 
See also
rb_cTrueClass
RUBY_Qnil 
See also
rb_cNilClass
RUBY_Qundef 

Represents so-called undef.

RUBY_IMMEDIATE_MASK 

Bit mask detecting special consts.

RUBY_FIXNUM_FLAG 

Flag to denote a fixnum.

RUBY_FLONUM_MASK 

Bit mask detecting a flonum.

RUBY_FLONUM_FLAG 

Flag to denote a flonum.

RUBY_SYMBOL_FLAG 

Flag to denote a static symbol.

RUBY_SPECIAL_SHIFT 

Least significant 8 bits are reserved.

Definition at line 84 of file special_consts.h.

Function Documentation

◆ RB_FIXNUM_P()

static bool RB_FIXNUM_P ( VALUE  obj)
inlinestatic

Checks if the given object is a so-called Fixnum.

Parameters
[in]objAn arbitrary ruby object.
Return values
trueobj is a Fixnum.
falseAnything else.
Note
Fixnum was a thing in the 20th century, but it is rather an implementation detail today.

Definition at line 247 of file special_consts.h.

Referenced by rb_class_of(), rb_fiber_scheduler_io_result_apply(), RB_FIX2INT(), RB_FIX2UINT(), rb_fix2ulong(), RB_INT2FIX(), rb_integer_type_p(), rb_num2int_inline(), rb_num2ll_inline(), rb_num2long_inline(), rb_num2short_inline(), rb_num2ull_inline(), and rb_num2ulong_inline().

◆ RB_FLONUM_P()

static bool RB_FLONUM_P ( VALUE  obj)
inlinestatic

Checks if the given object is a so-called Flonum.

Parameters
[in]objAn arbitrary ruby object.
Return values
trueobj is a Flonum.
falseAnything else.
See also
RB_FLOAT_TYPE_P()
Note
These days there are Flonums and non-Flonum floats, just like we once had Fixnum/Bignum back in the old days.

Definition at line 288 of file special_consts.h.

Referenced by rb_class_of(), and RB_FLOAT_TYPE_P().

◆ RB_IMMEDIATE_P()

static bool RB_IMMEDIATE_P ( VALUE  obj)
inlinestatic

Checks if the given object is an immediate i.e.

an object which has no corresponding storage inside of the object space.

Parameters
[in]objAn arbitrary ruby object.
Return values
trueobj is a Flonum.
falseAnything else.
See also
RB_FLOAT_TYPE_P()
Note
The concept of "immediate" is purely C specific.

Definition at line 311 of file special_consts.h.

Referenced by RB_SPECIAL_CONST_P().

◆ RB_NIL_OR_UNDEF_P()

static bool RB_NIL_OR_UNDEF_P ( VALUE  obj)
inlinestatic

Checks if the given object is nil or undef.

Can be used to see if a keyword argument is not given or given nil.

Parameters
[in]objAn arbitrary ruby object.
Return values
trueobj is RUBY_Qnil or RUBY_Qundef.
falseAnything else.

Definition at line 206 of file special_consts.h.

◆ RB_NIL_P()

static bool RB_NIL_P ( VALUE  obj)
inlinestatic

Checks if the given object is nil.

Parameters
[in]objAn arbitrary ruby object.
Return values
trueobj is RUBY_Qnil.
falseAnything else.

Definition at line 173 of file special_consts.h.

◆ RB_SPECIAL_CONST_P()

static bool RB_SPECIAL_CONST_P ( VALUE  obj)
inlinestatic

Checks if the given object is of enum ruby_special_consts.

Parameters
[in]objAn arbitrary ruby object.
Return values
trueobj is a special constant.
falseAnything else.

Definition at line 327 of file special_consts.h.

Referenced by RB_BUILTIN_TYPE(), rb_class_of(), rb_define_const(), RB_DYNAMIC_SYM_P(), RB_FL_ABLE(), RB_FLOAT_TYPE_P(), rb_integer_type_p(), rb_ractor_shareable_p(), rb_special_const_p(), and RBASIC_CLASS().

◆ rb_special_const_p()

static VALUE rb_special_const_p ( VALUE  obj)
inlinestatic

Identical to RB_SPECIAL_CONST_P, except it returns a VALUE.

Parameters
[in]objAn arbitrary ruby object.
Return values
RUBY_Qtrueobj is a special constant.
RUBY_QfalseAnything else.

Definition at line 347 of file special_consts.h.

◆ RB_STATIC_SYM_P()

static bool RB_STATIC_SYM_P ( VALUE  obj)
inlinestatic

Checks if the given object is a static symbol.

Parameters
[in]objAn arbitrary ruby object.
Return values
trueobj is a static symbol
falseAnything else.
See also
RB_DYNAMIC_SYM_P()
RB_SYMBOL_P()
Note
These days there are static and dynamic symbols, just like we once had Fixnum/Bignum back in the old days.

Definition at line 267 of file special_consts.h.

Referenced by rb_class_of(), and RB_SYMBOL_P().

◆ RB_TEST()

static bool RB_TEST ( VALUE  obj)
inlinestatic

Emulates Ruby's "if" statement.

Parameters
[in]objAn arbitrary ruby object.
Return values
falseobj is either RUBY_Qfalse or RUBY_Qnil.
trueAnything else.

Definition at line 138 of file special_consts.h.

◆ RB_UNDEF_P()

static bool RB_UNDEF_P ( VALUE  obj)
inlinestatic

Checks if the given object is undef.

Parameters
[in]objAn arbitrary ruby object.
Return values
trueobj is RUBY_Qundef.
falseAnything else.

Definition at line 189 of file special_consts.h.