Ruby 3.5.0dev (2025-08-30 revision 01a57bd6cde82ad58f938d075f569d57048d8a60)
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_HEAP ROBJECT_HEAP
47#define ROBJECT_FIELDS_CAPACITY ROBJECT_FIELDS_CAPACITY
48#define ROBJECT_FIELDS ROBJECT_FIELDS
56enum ruby_robject_flags {
76 ROBJECT_HEAP = RUBY_FL_USER4
77};
78
79struct st_table;
80
85struct RObject {
86
88 struct RBasic basic;
89
91 union {
92
97 struct {
100 } heap;
101
102 /* Embedded instance variables. When an object is small enough, it
103 * uses this area to store the instance variables.
104 *
105 * This is a length 1 array because:
106 * 1. GCC has a bug that does not optimize C flexible array members
107 * (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102452)
108 * 2. Zero length arrays are not supported by all compilers
109 */
110 VALUE ary[1];
111 } as;
112};
113
127static inline VALUE *
129{
130 RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT);
131
132 struct RObject *const ptr = ROBJECT(obj);
133
134 if (RB_UNLIKELY(RB_FL_ANY_RAW(obj, ROBJECT_HEAP))) {
135 return ptr->as.heap.fields;
136 }
137 else {
138 return ptr->as.ary;
139 }
140}
141
142#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:512
@ RUBY_FL_USER4
User-defined flag.
Definition fl_type.h:328
#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
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_FIELDS(VALUE obj)
Queries the instance variables.
Definition robject.h:128
Ruby object's base components.
Definition rbasic.h:69
Ruby's ordinal objects.
Definition robject.h:85
VALUE * fields
Pointer to a C array that holds instance variables.
Definition robject.h:99
struct RBasic basic
Basic part, including flags and class.
Definition robject.h:88
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:116