Ruby  3.1.4p223 (2023-03-30 revision HEAD)
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"
33 #include "ruby/internal/fl_type.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_NUMIV ROBJECT_NUMIV
48 #define ROBJECT_IVPTR ROBJECT_IVPTR
49 #define ROBJECT_IV_INDEX_TBL ROBJECT_IV_INDEX_TBL
57 enum ruby_robject_flags {
75  ROBJECT_EMBED = RUBY_FL_USER1
76 };
77 
84  ROBJECT_EMBED_LEN_MAX = RBIMPL_EMBED_LEN_MAX_OF(VALUE)
85 };
86 
87 struct st_table;
88 
93 struct RObject {
94 
96  struct RBasic basic;
97 
99  union {
100 
105  struct {
106 
111  uint32_t numiv;
112 
115 
125  } heap;
126 
132  } as;
133 };
134 
144 static inline uint32_t
146 {
147  RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT);
148 
149  if (RB_FL_ANY_RAW(obj, ROBJECT_EMBED)) {
150  return ROBJECT_EMBED_LEN_MAX;
151  }
152  else {
153  return ROBJECT(obj)->as.heap.numiv;
154  }
155 }
156 
170 static inline VALUE *
172 {
173  RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT);
174 
175  struct RObject *const ptr = ROBJECT(obj);
176 
177  if (RB_FL_ANY_RAW(obj, ROBJECT_EMBED)) {
178  return ptr->as.ary;
179  }
180  else {
181  return ptr->as.heap.ivptr;
182  }
183 }
184 
185 #endif /* RBIMPL_ROBJECT_H */
Defines RBIMPL_ATTR_ARTIFICIAL.
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
Definition: artificial.h:41
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:556
@ 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
static VALUE * ROBJECT_IVPTR(VALUE obj)
Queries the instance variables.
Definition: robject.h:171
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 uint32_t ROBJECT_NUMIV(VALUE obj)
Queries the number of instance variables.
Definition: robject.h:145
Ruby's object's, base components.
Definition: rbasic.h:64
Ruby's ordinal objects.
Definition: robject.h:93
struct st_table * iv_index_tbl
This is a table that holds instance variable name to index mapping.
Definition: robject.h:124
struct RObject::@45::@46 heap
Object that use separated memory region for instance variables use this pattern.
union RObject::@45 as
Object's specific fields.
struct RBasic basic
Basic part, including flags and class.
Definition: robject.h:96
VALUE * ivptr
Pointer to a C array that holds instance variables.
Definition: robject.h:114
uint32_t numiv
Number of instance variables.
Definition: robject.h:111
VALUE ary[ROBJECT_EMBED_LEN_MAX]
Embedded instance variables.
Definition: robject.h:131
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