Skip to content

Commit 0bd310a

Browse files
committed
Hold VM lock when iterating over global_enc_table.names
This st_table can be inserted into at runtime when autoloading encodings.
1 parent 6f5a722 commit 0bd310a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

encoding.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,10 @@ enc_names(VALUE self)
13661366

13671367
args[0] = (VALUE)rb_to_encoding_index(self);
13681368
args[1] = rb_ary_new2(0);
1369-
st_foreach(global_enc_table.names, enc_names_i, (st_data_t)args);
1369+
1370+
GLOBAL_ENC_TABLE_LOCKING(enc_table) {
1371+
st_foreach(enc_table->names, enc_names_i, (st_data_t)args);
1372+
}
13701373
return args[1];
13711374
}
13721375

@@ -1873,8 +1876,11 @@ rb_enc_name_list_i(st_data_t name, st_data_t idx, st_data_t arg)
18731876
static VALUE
18741877
rb_enc_name_list(VALUE klass)
18751878
{
1876-
VALUE ary = rb_ary_new2(global_enc_table.names->num_entries);
1877-
st_foreach(global_enc_table.names, rb_enc_name_list_i, (st_data_t)ary);
1879+
VALUE ary;
1880+
GLOBAL_ENC_TABLE_LOCKING(enc_table) {
1881+
ary = rb_ary_new2(enc_table->names->num_entries);
1882+
st_foreach(enc_table->names, rb_enc_name_list_i, (st_data_t)ary);
1883+
}
18781884
return ary;
18791885
}
18801886

@@ -1920,7 +1926,9 @@ rb_enc_aliases(VALUE klass)
19201926
aliases[0] = rb_hash_new();
19211927
aliases[1] = rb_ary_new();
19221928

1923-
st_foreach(global_enc_table.names, rb_enc_aliases_enc_i, (st_data_t)aliases);
1929+
GLOBAL_ENC_TABLE_LOCKING(enc_table) {
1930+
st_foreach(enc_table->names, rb_enc_aliases_enc_i, (st_data_t)aliases);
1931+
}
19241932

19251933
return aliases[0];
19261934
}
@@ -2022,5 +2030,7 @@ Init_encodings(void)
20222030
void
20232031
rb_enc_foreach_name(int (*func)(st_data_t name, st_data_t idx, st_data_t arg), st_data_t arg)
20242032
{
2025-
st_foreach(global_enc_table.names, func, arg);
2033+
GLOBAL_ENC_TABLE_LOCKING(enc_table) {
2034+
st_foreach(enc_table->names, func, arg);
2035+
}
20262036
}

0 commit comments

Comments
 (0)