Ruby 3.4.4p34 (2025-05-14 revision a38531fd3f617bf734ef7d6c595325f69985ea1d)
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
50
56enum ruby_robject_flags {
74 ROBJECT_EMBED = RUBY_FL_USER1
75};
76
77struct st_table;
78
83struct RObject {
84
86 struct RBasic basic;
87
89 union {
90
95 struct {
98
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
135static inline VALUE *
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 */
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 implementation detail of RB_FL_ANY().
Definition fl_type.h:518
@ RUBY_FL_USER1
User-defined flag.
Definition fl_type.h:329
#define inline
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Definition defines.h:88
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:136
Ruby object's base components.
Definition rbasic.h:63
Ruby's ordinal objects.
Definition robject.h:83
struct RBasic basic
Basic part, including flags and class.
Definition robject.h:86
VALUE * ivptr
Pointer to a C array that holds instance variables.
Definition robject.h:97
struct rb_id_table * iv_index_tbl
This is a table that holds instance variable name to index mapping.
Definition robject.h:107
union RObject::@210145204263252121304200074116325373231002256127 as
Object's specific fields.
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:116