Skip to content

Commit 6338386

Browse files
committed
Get rid of generic_fields_tbl
1 parent e7480d8 commit 6338386

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

variable.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,24 +1185,23 @@ IVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(ID id)
11851185
rb_raise(rb_eRactorIsolationError, "can not access class variables from non-main Ractors"); \
11861186
}
11871187

1188-
static inline struct st_table *
1189-
generic_fields_tbl(VALUE obj, ID id, bool force_check_ractor)
1188+
static inline void
1189+
ivar_ractor_check(VALUE obj, ID id)
11901190
{
1191-
ASSERT_vm_locking();
1192-
1193-
if ((force_check_ractor || LIKELY(rb_is_instance_id(id)) /* not internal ID */ ) &&
1191+
if (LIKELY(rb_is_instance_id(id)) /* not internal ID */ &&
11941192
!RB_OBJ_FROZEN_RAW(obj) &&
11951193
UNLIKELY(!rb_ractor_main_p()) &&
11961194
UNLIKELY(rb_ractor_shareable_p(obj))) {
11971195

11981196
rb_raise(rb_eRactorIsolationError, "can not access instance variables of shareable objects from non-main Ractors");
11991197
}
1200-
return generic_fields_tbl_;
12011198
}
12021199

12031200
static inline struct st_table *
12041201
generic_fields_tbl_no_ractor_check(void)
12051202
{
1203+
ASSERT_vm_locking();
1204+
12061205
return generic_fields_tbl_;
12071206
}
12081207

@@ -1213,13 +1212,14 @@ rb_generic_fields_tbl_get(void)
12131212
}
12141213

12151214
VALUE
1216-
rb_obj_fields(VALUE obj, ID id)
1215+
rb_obj_fields(VALUE obj, ID field_name)
12171216
{
1217+
ivar_ractor_check(obj, field_name);
1218+
12181219
VALUE fields_obj = 0;
12191220
if (rb_obj_exivar_p(obj)) {
12201221
RB_VM_LOCKING() {
1221-
st_table *tbl = generic_fields_tbl(obj, id, false);
1222-
if (!st_lookup(tbl, (st_data_t)obj, (st_data_t *)&fields_obj)) {
1222+
if (!st_lookup(generic_fields_tbl_, (st_data_t)obj, (st_data_t *)&fields_obj)) {
12231223
rb_bug("Object is missing entry in generic_fields_tbl");
12241224
}
12251225
}
@@ -1242,14 +1242,15 @@ rb_free_generic_ivar(VALUE obj)
12421242
void
12431243
rb_obj_set_fields(VALUE obj, VALUE fields_obj, ID field_name, VALUE original_fields_obj)
12441244
{
1245+
ivar_ractor_check(obj, field_name);
1246+
12451247
RUBY_ASSERT(!fields_obj || IMEMO_TYPE_P(fields_obj, imemo_fields));
12461248
RUBY_ASSERT(!original_fields_obj || IMEMO_TYPE_P(original_fields_obj, imemo_fields));
12471249

12481250
if (fields_obj != original_fields_obj) {
12491251
if (fields_obj) {
12501252
RB_VM_LOCKING() {
1251-
st_table *tbl = generic_fields_tbl(obj, field_name, false);
1252-
st_insert(tbl, (st_data_t)obj, (st_data_t)fields_obj);
1253+
st_insert(generic_fields_tbl_, (st_data_t)obj, (st_data_t)fields_obj);
12531254
}
12541255

12551256
RB_OBJ_WRITTEN(obj, original_fields_obj, fields_obj);

0 commit comments

Comments
 (0)