Ruby: include/ruby/internal/core/robject.h Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

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
29#include "ruby/internal/attr/artificial.h"
30#include "ruby/internal/attr/deprecated.h"
31#include "ruby/internal/attr/pure.h"
32#include "ruby/internal/cast.h"
33#include "ruby/internal/fl_type.h"
34#include "ruby/internal/value.h"
35#include "ruby/internal/value_type.h"
36
37#define ROBJECT(obj) RBIMPL_CAST((struct RObject *)(obj))
38#define ROBJECT_EMBED_LEN_MAX ROBJECT_EMBED_LEN_MAX
39#define ROBJECT_EMBED ROBJECT_EMBED
41#define ROBJECT_NUMIV ROBJECT_NUMIV
42#define ROBJECT_IVPTR ROBJECT_IVPTR
43#define ROBJECT_IV_INDEX_TBL ROBJECT_IV_INDEX_TBL
46 enum ruby_robject_flags { ROBJECT_EMBED = RUBY_FL_USER1 };
47
48 enum ruby_robject_consts { ROBJECT_EMBED_LEN_MAX = RBIMPL_EMBED_LEN_MAX_OF(VALUE) };
49
50struct st_table;
51
52 struct RObject {
53 struct RBasic basic;
54 union {
55 struct {
56 uint32_t numiv;
57 VALUE *ivptr;
58 struct st_table *iv_index_tbl; /* shortcut for RCLASS_IV_INDEX_TBL(rb_obj_class(obj)) */
59 } heap;
60 VALUE ary[ROBJECT_EMBED_LEN_MAX];
61 } as;
62};
63
64 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
65 RBIMPL_ATTR_ARTIFICIAL()
66static inline uint32_t
67ROBJECT_NUMIV(VALUE obj)
68{
69 RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT);
70
71 if (RB_FL_ANY_RAW(obj, ROBJECT_EMBED)) {
72 return ROBJECT_EMBED_LEN_MAX;
73 }
74 else {
75 return ROBJECT(obj)->as.heap.numiv;
76 }
77}
78
79 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
80 RBIMPL_ATTR_ARTIFICIAL()
81static inline VALUE *
82ROBJECT_IVPTR(VALUE obj)
83{
84 RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT);
85
86 struct RObject *const ptr = ROBJECT(obj);
87
88 if (RB_FL_ANY_RAW(obj, ROBJECT_EMBED)) {
89 return ptr->as.ary;
90 }
91 else {
92 return ptr->as.heap.ivptr;
93 }
94}
95
96#endif /* RBIMPL_ROBJECT_H */
artificial.h
Defines RBIMPL_ATTR_ARTIFICIAL.
RBIMPL_ATTR_ARTIFICIAL
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
Definition: artificial.h:43
cast.h
Defines RBIMPL_CAST.
ptr
struct RIMemo * ptr
Definition: debug.c:88
deprecated.h
Defines RBIMPL_ATTR_DEPRECATED.
fl_type.h
Defines enum ruby_fl_type.
config.h
Thin wrapper to ruby/config.h.
pure.h
Defines RBIMPL_ATTR_PURE.
RBIMPL_ATTR_PURE_UNLESS_DEBUG
#define RBIMPL_ATTR_PURE_UNLESS_DEBUG()
Enables RBIMPL_ATTR_PURE iff.
Definition: pure.h:38
ROBJECT
#define ROBJECT(obj)
Definition: robject.h:37
ruby_robject_consts
ruby_robject_consts
Definition: robject.h:48
ruby_robject_flags
ruby_robject_flags
Definition: robject.h:46
ROBJECT_EMBED_LEN_MAX
#define ROBJECT_EMBED_LEN_MAX
Definition: robject.h:38
ROBJECT_EMBED
#define ROBJECT_EMBED
Definition: robject.h:39
uint32_t
unsigned int uint32_t
Definition: sha2.h:101
RBasic
Definition: rbasic.h:47
RObject
Definition: robject.h:52
RObject::iv_index_tbl
struct st_table * iv_index_tbl
Definition: robject.h:58
RObject::basic
struct RBasic basic
Definition: robject.h:53
RObject::ivptr
VALUE * ivptr
Definition: robject.h:57
RObject::numiv
uint32_t numiv
Definition: robject.h:56
RObject::as
union RObject::@98 as
st_table
Definition: st.h:79
value.h
Defines VALUE and ID.
VALUE
unsigned long VALUE
Definition: value.h:38
value_type.h
Defines enum ruby_value_type.
RUBY_T_OBJECT
@ RUBY_T_OBJECT
Definition: value_type.h:113