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

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

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
77#if !USE_RVARGC
82 enum ruby_robject_consts {
84 ROBJECT_EMBED_LEN_MAX = RBIMPL_EMBED_LEN_MAX_OF(VALUE)
85};
86#endif
87
88struct st_table;
89
94 struct RObject {
95
97 struct RBasic basic;
98
100 union {
101
106 struct {
108 VALUE *ivptr;
109
118 struct rb_id_table *iv_index_tbl;
119 } heap;
120
121#if USE_RVARGC
122 /* Embedded instance variables. When an object is small enough, it
123 * uses this area to store the instance variables.
124 *
125 * This is a length 1 array because:
126 * 1. GCC has a bug that does not optimize C flexible array members
127 * (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102452)
128 * 2. Zero length arrays are not supported by all compilers
129 */
130 VALUE ary[1];
131#else
136 VALUE ary[ROBJECT_EMBED_LEN_MAX];
137#endif
138 } as;
139};
140
141/* Offsets for YJIT */
142#ifndef __cplusplus
143static const int32_t ROBJECT_OFFSET_AS_HEAP_IVPTR = offsetof(struct RObject, as.heap.ivptr);
144static const int32_t ROBJECT_OFFSET_AS_HEAP_IV_INDEX_TBL = offsetof(struct RObject, as.heap.iv_index_tbl);
145static const int32_t ROBJECT_OFFSET_AS_ARY = offsetof(struct RObject, as.ary);
146#endif
147
148 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
149 RBIMPL_ATTR_ARTIFICIAL()
161static inline VALUE *
162ROBJECT_IVPTR(VALUE obj)
163{
164 RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT);
165
166 struct RObject *const ptr = ROBJECT(obj);
167
168 if (RB_FL_ANY_RAW(obj, ROBJECT_EMBED)) {
169 return ptr->as.ary;
170 }
171 else {
172 return ptr->as.heap.ivptr;
173 }
174}
175
176#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 implenentation detail of RB_FL_ANY().
Definition fl_type.h:550
RUBY_FL_USER1
@ RUBY_FL_USER1
User-defined flag.
Definition fl_type.h:361
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
ruby_robject_consts
ruby_robject_consts
This is an enum because GDB wants it (rather than a macro).
Definition robject.h:82
ROBJECT_EMBED_LEN_MAX
@ ROBJECT_EMBED_LEN_MAX
Max possible number of instance variables that can be embedded.
Definition robject.h:84
ROBJECT_IVPTR
static VALUE * ROBJECT_IVPTR(VALUE obj)
Queries the instance variables.
Definition robject.h:162
RBasic
Ruby's object's, base components.
Definition rbasic.h:64
RObject
Ruby's ordinal objects.
Definition robject.h:94
RObject::basic
struct RBasic basic
Basic part, including flags and class.
Definition robject.h:97
RObject::as
union RObject::@47 as
Object's specific fields.
RObject::ivptr
VALUE * ivptr
Pointer to a C array that holds instance variables.
Definition robject.h:108
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:118
RObject::heap
struct RObject::@47::@48 heap
Object that use separated memory region for instance variables use this pattern.
RObject::ary
VALUE ary[ROBJECT_EMBED_LEN_MAX]
Embedded instance variables.
Definition robject.h:136
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:115