Ruby: include/ruby/internal/core/rbasic.h Source File

Ruby 3.4.9p82 (2026-03-11 revision 76cca827ab52ab1d346a728f068d5b8da3e2952b)

rbasic.h
Go to the documentation of this file.
1#ifndef RBIMPL_RBASIC_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_RBASIC_H
23#include "ruby/internal/attr/artificial.h"
24#include "ruby/internal/attr/constexpr.h"
25#include "ruby/internal/attr/forceinline.h"
26#include "ruby/internal/attr/noalias.h"
27#include "ruby/internal/attr/pure.h"
28#include "ruby/internal/cast.h"
29#include "ruby/internal/dllexport.h"
30#include "ruby/internal/special_consts.h"
31#include "ruby/internal/value.h"
32#include "ruby/assert.h"
33
40#define RBASIC(obj) RBIMPL_CAST((struct RBasic *)(obj))
42#define RBASIC_CLASS RBASIC_CLASS
43#define RBIMPL_RVALUE_EMBED_LEN_MAX 3
44#define RVALUE_EMBED_LEN_MAX RVALUE_EMBED_LEN_MAX
45#define RBIMPL_EMBED_LEN_MAX_OF(T) \
46 RBIMPL_CAST((int)(sizeof(VALUE[RBIMPL_RVALUE_EMBED_LEN_MAX]) / (sizeof(T))))
48
53 enum ruby_rvalue_flags {
55 RVALUE_EMBED_LEN_MAX = RBIMPL_RVALUE_EMBED_LEN_MAX
56};
57
61 struct
62 RUBY_ALIGNAS(SIZEOF_VALUE)
63 RBasic {
64
75 VALUE flags;
76
86 const VALUE klass;
87
88#ifdef __cplusplus
89 public:
90 RBIMPL_ATTR_CONSTEXPR(CXX11)
91 RBIMPL_ATTR_ARTIFICIAL()
92 RBIMPL_ATTR_FORCEINLINE()
93 RBIMPL_ATTR_NOALIAS()
100 RBasic() :
101 flags(RBIMPL_VALUE_NULL),
102 klass(RBIMPL_VALUE_NULL)
103 {
104 }
105# define RBASIC_INIT RBasic()
106#else
107# define RBASIC_INIT {RBIMPL_VALUE_NULL}
108#endif
109};
110
111 RBIMPL_SYMBOL_EXPORT_BEGIN()
126 VALUE rb_obj_hide(VALUE obj);
127
141 VALUE rb_obj_reveal(VALUE obj, VALUE klass); /* do not use this API to change klass information */
142 RBIMPL_SYMBOL_EXPORT_END()
143
144 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
145 RBIMPL_ATTR_ARTIFICIAL()
152static inline VALUE
153RBASIC_CLASS(VALUE obj)
154{
155 RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(obj));
156 return RBASIC(obj)->klass;
157}
158
159#endif /* RBIMPL_RBASIC_H */
artificial.h
Defines RBIMPL_ATTR_ARTIFICIAL.
RBIMPL_ATTR_ARTIFICIAL
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial)).
Definition artificial.h:43
assert.h
RBIMPL_ASSERT_OR_ASSUME
#define RBIMPL_ASSERT_OR_ASSUME(...)
This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.
Definition assert.h:311
RUBY_ALIGNAS
#define RUBY_ALIGNAS
Wraps (or simulates) alignas.
Definition stdalign.h:27
constexpr.h
RBIMPL_ATTR_CONSTEXPR.
RBIMPL_ATTR_CONSTEXPR
#define RBIMPL_ATTR_CONSTEXPR(_)
Wraps (or simulates) C++11 constexpr.
Definition constexpr.h:74
dllexport.h
Tweaking visibility of C variables/functions.
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition dllexport.h:74
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition dllexport.h:65
forceinline.h
Defines RBIMPL_ATTR_FORCEINLINE.
RBIMPL_ATTR_FORCEINLINE
#define RBIMPL_ATTR_FORCEINLINE()
Wraps (or simulates) __forceinline.
Definition forceinline.h:37
rb_obj_reveal
VALUE rb_obj_reveal(VALUE obj, VALUE klass)
Make a hidden object visible again.
Definition object.c:113
rb_obj_hide
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
Definition object.c:104
noalias.h
Defines RBIMPL_ATTR_NOALIAS.
RBIMPL_ATTR_NOALIAS
#define RBIMPL_ATTR_NOALIAS()
Wraps (or simulates) __declspec((noalias)).
Definition noalias.h:66
inline
#define inline
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Definition defines.h:91
pure.h
Defines RBIMPL_ATTR_PURE.
RBIMPL_ATTR_PURE_UNLESS_DEBUG
#define RBIMPL_ATTR_PURE_UNLESS_DEBUG()
Enables RBIMPL_ATTR_PURE if and only if.
Definition pure.h:38
RBASIC_CLASS
static VALUE RBASIC_CLASS(VALUE obj)
Queries the class of an object.
Definition rbasic.h:153
RBASIC
#define RBASIC(obj)
Convenient casting macro.
Definition rbasic.h:40
ruby_rvalue_flags
ruby_rvalue_flags
This is an enum because GDB wants it (rather than a macro).
Definition rbasic.h:53
RVALUE_EMBED_LEN_MAX
@ RVALUE_EMBED_LEN_MAX
Max possible number of objects that can be embedded.
Definition rbasic.h:55
special_consts.h
Defines enum ruby_special_consts.
RB_SPECIAL_CONST_P
static bool RB_SPECIAL_CONST_P(VALUE obj)
Checks if the given object is of enum ruby_special_consts.
Definition special_consts.h:327
RBasic::klass
const VALUE klass
Class of an object.
Definition rbasic.h:86
RBasic::RBasic
RBasic()
We need to define this explicit constructor because the field klass is const-qualified above,...
Definition rbasic.h:100
RBasic::flags
VALUE flags
Per-object flags.
Definition rbasic.h:75
value.h
Defines VALUE and ID.
RBIMPL_VALUE_NULL
#define RBIMPL_VALUE_NULL
A compile-time constant of type VALUE whose value is 0.
Definition value.h:76
SIZEOF_VALUE
#define SIZEOF_VALUE
Identical to sizeof(VALUE), except it is a macro that can also be used inside of preprocessor directi...
Definition value.h:69
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40