call const_added
after autoload
When calling `const_added` while process in `autoload`, it can cause synchronization issue because of a thread swithcing. http://ci.rvm.jp/logfiles/brlog.trunk.20220407-152213#L489 ``` 1) Module#autoload (concurrently) raises a LoadError in each thread if the file does not exist ERROR NameError: uninitialized constant ModuleSpecs::Autoload::FileDoesNotExist ModuleSpecs::Autoload::FileDoesNotExist ^^^^^^^^^^^^^^^^^^ /tmp/ruby/v3/src/trunk/spec/ruby/core/module/autoload_spec.rb:965:in `block (5 levels) in <top (required)>' ```
This commit is contained in:
parent
798e21637f
commit
c77a31df5e
Notes:
git
2022-04-08 21:30:52 +09:00
17
variable.c
17
variable.c
@ -2239,6 +2239,9 @@ rb_autoload(VALUE mod, ID id, const char *file)
|
|||||||
rb_autoload_str(mod, id, rb_fstring_cstr(file));
|
rb_autoload_str(mod, id, rb_fstring_cstr(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void const_set(VALUE klass, ID id, VALUE val);
|
||||||
|
static void const_added(VALUE klass, ID const_name);
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_autoload_str(VALUE mod, ID id, VALUE file)
|
rb_autoload_str(VALUE mod, ID id, VALUE file)
|
||||||
{
|
{
|
||||||
@ -2263,7 +2266,7 @@ rb_autoload_str(VALUE mod, ID id, VALUE file)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_const_set(mod, id, Qundef);
|
const_set(mod, id, Qundef);
|
||||||
tbl = RCLASS_IV_TBL(mod);
|
tbl = RCLASS_IV_TBL(mod);
|
||||||
if (tbl && st_lookup(tbl, (st_data_t)autoload, &av)) {
|
if (tbl && st_lookup(tbl, (st_data_t)autoload, &av)) {
|
||||||
tbl = check_autoload_table((VALUE)av);
|
tbl = check_autoload_table((VALUE)av);
|
||||||
@ -2307,6 +2310,8 @@ rb_autoload_str(VALUE mod, ID id, VALUE file)
|
|||||||
ccan_list_add_tail(&ele->constants, &ac->cnode);
|
ccan_list_add_tail(&ele->constants, &ac->cnode);
|
||||||
st_insert(tbl, (st_data_t)id, (st_data_t)acv);
|
st_insert(tbl, (st_data_t)id, (st_data_t)acv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const_added(mod, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -3111,8 +3116,8 @@ const_added(VALUE klass, ID const_name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
rb_const_set(VALUE klass, ID id, VALUE val)
|
const_set(VALUE klass, ID id, VALUE val)
|
||||||
{
|
{
|
||||||
rb_const_entry_t *ce;
|
rb_const_entry_t *ce;
|
||||||
|
|
||||||
@ -3175,6 +3180,12 @@ rb_const_set(VALUE klass, ID id, VALUE val)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
rb_const_set(VALUE klass, ID id, VALUE val)
|
||||||
|
{
|
||||||
|
const_set(klass, id, val);
|
||||||
const_added(klass, id);
|
const_added(klass, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user