Ruby 3.5.0dev (2025-02-20 revision 34098b669c0cbc024cd08e686891f1dfe0a10aaf)
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
77struct st_table;
78
83struct RObject {
84
86 struct RBasic basic;
87
89 union {
90
95 struct {
98 } heap;
99
100 /* Embedded instance variables. When an object is small enough, it
101 * uses this area to store the instance variables.
102 *
103 * This is a length 1 array because:
104 * 1. GCC has a bug that does not optimize C flexible array members
105 * (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102452)
106 * 2. Zero length arrays are not supported by all compilers
107 */
108 VALUE ary[1];
109 } as;
110};
111
125static inline VALUE *
127{
128 RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT);
129
130 struct RObject *const ptr = ROBJECT(obj);
131
132 if (RB_FL_ANY_RAW(obj, ROBJECT_EMBED)) {
133 return ptr->as.ary;
134 }
135 else {
136 return ptr->as.heap.ivptr;
137 }
138}
139
140#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: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_IVPTR(VALUE obj)
Queries the instance variables.
Definition robject.h:126
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
union RObject::@50 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