Ruby 3.2.3p157 (2024-01-18 revision 52bb2ac0a6971d0391efa2275f7a66bff319087c)
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
32#include "ruby/internal/cast.h"
34#include "ruby/internal/value.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
84 ROBJECT_EMBED_LEN_MAX = RBIMPL_EMBED_LEN_MAX_OF(VALUE)
85};
86#endif
87
88struct st_table;
89
94struct RObject {
95
97 struct RBasic basic;
98
100 union {
101
106 struct {
109
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
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
161static inline VALUE *
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 */
Defines RBIMPL_ATTR_ARTIFICIAL.
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
Definition artificial.h:43
Defines RBIMPL_ATTR_DEPRECATED.
Defines enum ruby_fl_type.
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
User-defined flag.
Definition fl_type.h:361
Defines RBIMPL_ATTR_PURE.
#define RBIMPL_ATTR_PURE_UNLESS_DEBUG()
Enables RBIMPL_ATTR_PURE if and only if.
Definition pure.h:38
#define ROBJECT(obj)
Convenient casting macro.
Definition robject.h:43
ruby_robject_consts
This is an enum because GDB wants it (rather than a macro).
Definition robject.h:82
@ ROBJECT_EMBED_LEN_MAX
Max possible number of instance variables that can be embedded.
Definition robject.h:84
static VALUE * ROBJECT_IVPTR(VALUE obj)
Queries the instance variables.
Definition robject.h:162
Ruby's object's, base components.
Definition rbasic.h:64
Ruby's ordinal objects.
Definition robject.h:94
struct RObject::@48::@49 heap
Object that use separated memory region for instance variables use this pattern.
struct RBasic basic
Basic part, including flags and class.
Definition robject.h:97
VALUE * ivptr
Pointer to a C array that holds instance variables.
Definition robject.h:108
struct rb_id_table * iv_index_tbl
This is a table that holds instance variable name to index mapping.
Definition robject.h:118
VALUE ary[ROBJECT_EMBED_LEN_MAX]
Embedded instance variables.
Definition robject.h:136
union RObject::@48 as
Object's specific fields.
Definition st.h:79
Defines VALUE and ID.
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40
Defines enum ruby_value_type.
@ RUBY_T_OBJECT
Definition value_type.h:115