Ruby: include/ruby/internal/rgengc.h Source File

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

rgengc.h
Go to the documentation of this file.
1#ifndef RBIMPL_RGENGC_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_RGENGC_H
27#include "ruby/internal/attr/artificial.h"
28#include "ruby/internal/attr/pure.h"
29#include "ruby/internal/dllexport.h"
30#include "ruby/internal/special_consts.h"
31#include "ruby/internal/stdbool.h"
32#include "ruby/internal/value.h"
33#include "ruby/assert.h"
34#include "ruby/backward/2/attributes.h"
35
36#undef USE_RGENGC
37#define USE_RGENGC 1
38
39#ifndef USE_RINCGC
40# define USE_RINCGC 1
41#endif
42
43#ifndef USE_RGENGC_LOGGING_WB_UNPROTECT
44# define USE_RGENGC_LOGGING_WB_UNPROTECT 0
45#endif
46
47#ifndef RGENGC_WB_PROTECTED_ARRAY
48# define RGENGC_WB_PROTECTED_ARRAY 1
49#endif
50
51#ifndef RGENGC_WB_PROTECTED_HASH
52# define RGENGC_WB_PROTECTED_HASH 1
53#endif
54
55#ifndef RGENGC_WB_PROTECTED_STRUCT
56# define RGENGC_WB_PROTECTED_STRUCT 1
57#endif
58
59#ifndef RGENGC_WB_PROTECTED_STRING
60# define RGENGC_WB_PROTECTED_STRING 1
61#endif
62
63#ifndef RGENGC_WB_PROTECTED_OBJECT
64# define RGENGC_WB_PROTECTED_OBJECT 1
65#endif
66
67#ifndef RGENGC_WB_PROTECTED_REGEXP
68# define RGENGC_WB_PROTECTED_REGEXP 1
69#endif
70
71#ifndef RGENGC_WB_PROTECTED_CLASS
72# define RGENGC_WB_PROTECTED_CLASS 1
73#endif
74
75#ifndef RGENGC_WB_PROTECTED_FLOAT
76# define RGENGC_WB_PROTECTED_FLOAT 1
77#endif
78
79#ifndef RGENGC_WB_PROTECTED_COMPLEX
80# define RGENGC_WB_PROTECTED_COMPLEX 1
81#endif
82
83#ifndef RGENGC_WB_PROTECTED_RATIONAL
84# define RGENGC_WB_PROTECTED_RATIONAL 1
85#endif
86
87#ifndef RGENGC_WB_PROTECTED_BIGNUM
88# define RGENGC_WB_PROTECTED_BIGNUM 1
89#endif
90
91#ifndef RGENGC_WB_PROTECTED_NODE_CREF
92# define RGENGC_WB_PROTECTED_NODE_CREF 1
93#endif
94
107#define RB_OBJ_WRITE(a, slot, b) \
108 RBIMPL_CAST(rb_obj_write((VALUE)(a), (VALUE *)(slot), (VALUE)(b), __FILE__, __LINE__))
114#define RB_OBJ_WRITTEN(a, oldv, b) \
115 RBIMPL_CAST(rb_obj_written((VALUE)(a), (VALUE)(oldv), (VALUE)(b), __FILE__, __LINE__))
118#define OBJ_PROMOTED_RAW RB_OBJ_PROMOTED_RAW
119#define OBJ_PROMOTED RB_OBJ_PROMOTED
120#define OBJ_WB_UNPROTECT RB_OBJ_WB_UNPROTECT
121
122#define RB_OBJ_WB_UNPROTECT(x) rb_obj_wb_unprotect(x, __FILE__, __LINE__)
123#define RB_OBJ_WB_UNPROTECT_FOR(type, obj) \
124 (RGENGC_WB_PROTECTED_##type ? OBJ_WB_UNPROTECT(obj) : obj)
125#define RGENGC_LOGGING_WB_UNPROTECT rb_gc_unprotect_logging
126
128#define RB_OBJ_PROMOTED_RAW RB_OBJ_PROMOTED_RAW
129#define RB_OBJ_PROMOTED RB_OBJ_PROMOTED
132 RBIMPL_SYMBOL_EXPORT_BEGIN()
133void rb_gc_writebarrier(VALUE a, VALUE b);
134void rb_gc_writebarrier_unprotect(VALUE obj);
135#if USE_RGENGC_LOGGING_WB_UNPROTECT
136void rb_gc_unprotect_logging(void *objptr, const char *filename, int line);
137#endif
138 RBIMPL_SYMBOL_EXPORT_END()
139
140 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
141 RBIMPL_ATTR_ARTIFICIAL()
142static inline bool
143RB_OBJ_PROMOTED_RAW(VALUE obj)
144{
145 RBIMPL_ASSERT_OR_ASSUME(RB_FL_ABLE(obj));
146 return RB_FL_ANY_RAW(obj, RUBY_FL_PROMOTED);
147}
148
149 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
150 RBIMPL_ATTR_ARTIFICIAL()
151static inline bool
152RB_OBJ_PROMOTED(VALUE obj)
153{
154 if (! RB_FL_ABLE(obj)) {
155 return false;
156 }
157 else {
158 return RB_OBJ_PROMOTED_RAW(obj);
159 }
160}
161
162static inline VALUE
163rb_obj_wb_unprotect(VALUE x, RB_UNUSED_VAR(const char *filename), RB_UNUSED_VAR(int line))
164{
165#if USE_RGENGC_LOGGING_WB_UNPROTECT
166 RGENGC_LOGGING_WB_UNPROTECT(RBIMPL_CAST((void *)x), filename, line);
167#endif
168 rb_gc_writebarrier_unprotect(x);
169 return x;
170}
171
172static inline VALUE
173rb_obj_written(VALUE a, RB_UNUSED_VAR(VALUE oldv), VALUE b, RB_UNUSED_VAR(const char *filename), RB_UNUSED_VAR(int line))
174{
175#if USE_RGENGC_LOGGING_WB_UNPROTECT
176 RGENGC_LOGGING_OBJ_WRITTEN(a, oldv, b, filename, line);
177#endif
178
179 if (!RB_SPECIAL_CONST_P(b)) {
180 rb_gc_writebarrier(a, b);
181 }
182
183 return a;
184}
185
186static inline VALUE
187rb_obj_write(VALUE a, VALUE *slot, VALUE b, RB_UNUSED_VAR(const char *filename), RB_UNUSED_VAR(int line))
188{
189#ifdef RGENGC_LOGGING_WRITE
190 RGENGC_LOGGING_WRITE(a, slot, b, filename, line);
191#endif
192
193 *slot = b;
194
195 rb_obj_written(a, RUBY_Qundef /* ignore `oldv' now */, b, filename, line);
196 return a;
197}
198
199#endif /* RBIMPL_RGENGC_H */
artificial.h
Defines RBIMPL_ATTR_ARTIFICIAL.
RBIMPL_ATTR_ARTIFICIAL
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
Definition: artificial.h:43
assert.h
RBIMPL_ASSERT_OR_ASSUME
#define RBIMPL_ASSERT_OR_ASSUME(expr)
This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.
Definition: assert.h:229
attributes.h
Various attribute-related macros.
RB_UNUSED_VAR
#define RB_UNUSED_VAR(x)
Definition: attributes.h:168
dllexport.h
Tewaking visibility of C variables/functions.
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:86
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:77
RUBY_FL_PROMOTED
@ RUBY_FL_PROMOTED
Definition: fl_type.h:166
rb_gc_unprotect_logging
void rb_gc_unprotect_logging(void *objptr, const char *filename, int line)
Definition: gc.c:7848
filename
const char * filename
Definition: ioapi.h:137
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
rb_gc_writebarrier_unprotect
void rb_gc_writebarrier_unprotect(VALUE obj)
Definition: gc.c:7777
rb_gc_writebarrier
void rb_gc_writebarrier(VALUE a, VALUE b)
Definition: gc.c:7750
RGENGC_LOGGING_WB_UNPROTECT
#define RGENGC_LOGGING_WB_UNPROTECT
Definition: rgengc.h:125
special_consts.h
Defines enum ruby_special_consts.
RUBY_Qundef
@ RUBY_Qundef
Definition: special_consts.h:90
stdbool.h
C99 shim for <stdbool.h>
value.h
Defines VALUE and ID.
VALUE
unsigned long VALUE
Definition: value.h:38