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

Ruby 3.4.8p72 (2025-12-17 revision 995b59f66677d44767ce9faac6957e5543617ff9)

robject.h
Go to the documentation of this file.
1#ifndef RBIMPL_ROBJECT_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_ROBJECT_H
23#include "ruby/internal/config.h"
24
25#ifdef HAVE_STDINT_H
26# include <stdint.h>
27#endif
28
29#include "ruby/internal/attr/artificial.h"
30#include "ruby/internal/attr/deprecated.h"
31#include "ruby/internal/attr/pure.h"
32#include "ruby/internal/cast.h"
33#include "ruby/internal/fl_type.h"
34#include "ruby/internal/value.h"
35#include "ruby/internal/value_type.h"
36
43#define ROBJECT(obj) RBIMPL_CAST((struct RObject *)(obj))
45#define ROBJECT_EMBED_LEN_MAX ROBJECT_EMBED_LEN_MAX
46#define ROBJECT_EMBED ROBJECT_EMBED
47#define ROBJECT_IV_CAPACITY ROBJECT_IV_CAPACITY
48#define ROBJECT_IVPTR ROBJECT_IVPTR
56enum ruby_robject_flags {
74 ROBJECT_EMBED = RUBY_FL_USER1
75};
76
77struct st_table;
78
83 struct RObject {
84
86 struct RBasic basic;
87
89 union {
90
95 struct {
97 VALUE *ivptr;
98
107 struct rb_id_table *iv_index_tbl;
108 } heap;
109
110 /* Embedded instance variables. When an object is small enough, it
111 * uses this area to store the instance variables.
112 *
113 * This is a length 1 array because:
114 * 1. GCC has a bug that does not optimize C flexible array members
115 * (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102452)
116 * 2. Zero length arrays are not supported by all compilers
117 */
118 VALUE ary[1];
119 } as;
120};
121
122 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
123 RBIMPL_ATTR_ARTIFICIAL()
135static inline VALUE *
136ROBJECT_IVPTR(VALUE obj)
137{
138 RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT);
139
140 struct RObject *const ptr = ROBJECT(obj);
141
142 if (RB_FL_ANY_RAW(obj, ROBJECT_EMBED)) {
143 return ptr->as.ary;
144 }
145 else {
146 return ptr->as.heap.ivptr;
147 }
148}
149
150#endif /* RBIMPL_ROBJECT_H */
artificial.h
Defines RBIMPL_ATTR_ARTIFICIAL.
RBIMPL_ATTR_ARTIFICIAL
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
Definition artificial.h:43
deprecated.h
Defines RBIMPL_ATTR_DEPRECATED.
fl_type.h
Defines enum ruby_fl_type.
RB_FL_ANY_RAW
static bool RB_FL_ANY_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_ANY().
Definition fl_type.h:518
RUBY_FL_USER1
@ RUBY_FL_USER1
User-defined flag.
Definition fl_type.h:329
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
ROBJECT
#define ROBJECT(obj)
Convenient casting macro.
Definition robject.h:43
ROBJECT_IVPTR
static VALUE * ROBJECT_IVPTR(VALUE obj)
Queries the instance variables.
Definition robject.h:136
RBasic
Ruby object's base components.
Definition rbasic.h:63
RObject
Ruby's ordinal objects.
Definition robject.h:83
RObject::basic
struct RBasic basic
Basic part, including flags and class.
Definition robject.h:86
RObject::ivptr
VALUE * ivptr
Pointer to a C array that holds instance variables.
Definition robject.h:97
RObject::iv_index_tbl
struct rb_id_table * iv_index_tbl
This is a table that holds instance variable name to index mapping.
Definition robject.h:107
RObject::as
union RObject::@50 as
Object's specific fields.
rb_id_table
Definition id_table.c:41
st_table
Definition st.h:79
value.h
Defines VALUE and ID.
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40
value_type.h
Defines enum ruby_value_type.
RUBY_T_OBJECT
@ RUBY_T_OBJECT
Definition value_type.h:116