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

Ruby 3.2.5p208 (2024-07-26 revision 31d0f1a2e7dbfb60731d1f05b868e1d578cda493)

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))))
53 enum ruby_rvalue_flags {
55 RVALUE_EMBED_LEN_MAX = RBIMPL_RVALUE_EMBED_LEN_MAX
56};
57
62 struct
63 RUBY_ALIGNAS(SIZEOF_VALUE)
64 RBasic {
65
77 VALUE flags;
78
88 const VALUE klass;
89
90#ifdef __cplusplus
91 public:
92 RBIMPL_ATTR_CONSTEXPR(CXX11)
93 RBIMPL_ATTR_ARTIFICIAL()
94 RBIMPL_ATTR_FORCEINLINE()
95 RBIMPL_ATTR_NOALIAS()
102 RBasic() :
103 flags(RBIMPL_VALUE_NULL),
104 klass(RBIMPL_VALUE_NULL)
105 {
106 }
107#endif
108};
109
110 RBIMPL_SYMBOL_EXPORT_BEGIN()
125 VALUE rb_obj_hide(VALUE obj);
126
140 VALUE rb_obj_reveal(VALUE obj, VALUE klass); /* do not use this API to change klass information */
141 RBIMPL_SYMBOL_EXPORT_END()
142
143 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
144 RBIMPL_ATTR_ARTIFICIAL()
151static inline VALUE
152RBASIC_CLASS(VALUE obj)
153{
154 RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(obj));
155 return RBASIC(obj)->klass;
156}
157
158#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(expr)
This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.
Definition assert.h:229
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:106
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition dllexport.h:97
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:93
rb_obj_hide
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
Definition object.c:84
noalias.h
Defines RBIMPL_ATTR_NOALIAS.
RBIMPL_ATTR_NOALIAS
#define RBIMPL_ATTR_NOALIAS()
Wraps (or simulates) __declspec((noalias))
Definition noalias.h:66
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:152
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
Ruby's object's, base components.
Definition rbasic.h:64
RBasic::klass
const VALUE klass
Class of an object.
Definition rbasic.h:88
RBasic::flags
VALUE flags
Per-object flags.
Definition rbasic.h:77
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