mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
symbol.c: enforce intern_str
is always called with a lock
Add missing locks in `rb_intern_str`, `rb_id_attrset` and `rb_intern3`.
This commit is contained in:
parent
517c106709
commit
1f976509a5
1 changed files with 42 additions and 15 deletions
57
symbol.c
57
symbol.c
|
@ -173,8 +173,21 @@ rb_id_attrset(ID id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* make new symbol and ID */
|
bool error = false;
|
||||||
if (!(str = lookup_id_str(id))) {
|
GLOBAL_SYMBOLS_LOCKING(symbols) {
|
||||||
|
/* make new symbol and ID */
|
||||||
|
if ((str = lookup_id_str(id))) {
|
||||||
|
str = rb_str_dup(str);
|
||||||
|
rb_str_cat(str, "=", 1);
|
||||||
|
sym = lookup_str_sym(str);
|
||||||
|
id = sym ? rb_sym2id(sym) : intern_str(str, 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
RBIMPL_ATTR_NONSTRING_ARRAY() static const char id_types[][8] = {
|
RBIMPL_ATTR_NONSTRING_ARRAY() static const char id_types[][8] = {
|
||||||
"local",
|
"local",
|
||||||
"instance",
|
"instance",
|
||||||
|
@ -188,10 +201,7 @@ rb_id_attrset(ID id)
|
||||||
rb_name_error(id, "cannot make anonymous %.*s ID %"PRIxVALUE" attrset",
|
rb_name_error(id, "cannot make anonymous %.*s ID %"PRIxVALUE" attrset",
|
||||||
(int)sizeof(id_types[0]), id_types[scope], (VALUE)id);
|
(int)sizeof(id_types[0]), id_types[scope], (VALUE)id);
|
||||||
}
|
}
|
||||||
str = rb_str_dup(str);
|
|
||||||
rb_str_cat(str, "=", 1);
|
|
||||||
sym = lookup_str_sym(str);
|
|
||||||
id = sym ? rb_sym2id(sym) : intern_str(str, 1);
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -765,10 +775,20 @@ rb_intern3(const char *name, long len, rb_encoding *enc)
|
||||||
struct RString fake_str;
|
struct RString fake_str;
|
||||||
VALUE str = rb_setup_fake_str(&fake_str, name, len, enc);
|
VALUE str = rb_setup_fake_str(&fake_str, name, len, enc);
|
||||||
OBJ_FREEZE(str);
|
OBJ_FREEZE(str);
|
||||||
sym = lookup_str_sym(str);
|
ID id;
|
||||||
if (sym) return rb_sym2id(sym);
|
|
||||||
str = rb_enc_str_new(name, len, enc); /* make true string */
|
GLOBAL_SYMBOLS_LOCKING(symbols) {
|
||||||
return intern_str(str, 1);
|
sym = lookup_str_sym(str);
|
||||||
|
if (sym) {
|
||||||
|
id = rb_sym2id(sym);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
str = rb_enc_str_new(name, len, enc); /* make true string */
|
||||||
|
id = intern_str(str, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ID
|
static ID
|
||||||
|
@ -801,6 +821,8 @@ next_id_base(void)
|
||||||
static ID
|
static ID
|
||||||
intern_str(VALUE str, int mutable)
|
intern_str(VALUE str, int mutable)
|
||||||
{
|
{
|
||||||
|
ASSERT_vm_locking();
|
||||||
|
|
||||||
ID id;
|
ID id;
|
||||||
ID nid;
|
ID nid;
|
||||||
|
|
||||||
|
@ -836,13 +858,18 @@ rb_intern(const char *name)
|
||||||
ID
|
ID
|
||||||
rb_intern_str(VALUE str)
|
rb_intern_str(VALUE str)
|
||||||
{
|
{
|
||||||
VALUE sym = lookup_str_sym(str);
|
ID id;
|
||||||
|
GLOBAL_SYMBOLS_LOCKING(symbols) {
|
||||||
if (sym) {
|
VALUE sym = lookup_str_sym(str);
|
||||||
return SYM2ID(sym);
|
if (sym) {
|
||||||
|
id = SYM2ID(sym);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
id = intern_str(str, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return intern_str(str, 0);
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue