Bug #11055 ยป const-visibility-before-autoload-11055.patch
| test/ruby/test_autoload.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
def test_autoload_private_constant_before_autoload
|
||
|
Dir.mktmpdir('autoload') do |tmpdir|
|
||
|
File.write(tmpdir+"/zzz.rb", "#{<<~"begin;"}\n#{<<~'end;'}")
|
||
|
begin;
|
||
|
class AutoloadTest
|
||
|
ZZZ = :ZZZ
|
||
|
end
|
||
|
end;
|
||
|
assert_separately(%W[-I #{tmpdir}], "#{<<-"begin;"}\n#{<<-'end;'}")
|
||
|
bug = '[Bug #11055]'
|
||
|
begin;
|
||
|
class AutoloadTest
|
||
|
autoload :ZZZ, "zzz.rb"
|
||
|
private_constant :ZZZ
|
||
|
ZZZ
|
||
|
end
|
||
|
assert_raise(NameError, bug) {AutoloadTest::ZZZ}
|
||
|
end;
|
||
|
assert_separately(%W[-I #{tmpdir}], "#{<<-"begin;"}\n#{<<-'end;'}")
|
||
|
bug = '[Bug #11055]'
|
||
|
begin;
|
||
|
class AutoloadTest
|
||
|
autoload :ZZZ, "zzz.rb"
|
||
|
private_constant :ZZZ
|
||
|
end
|
||
|
assert_raise(NameError, bug) {AutoloadTest::ZZZ}
|
||
|
end;
|
||
|
end
|
||
|
end
|
||
|
def test_autoload_deprecate_constant_before_autoload
|
||
|
Dir.mktmpdir('autoload') do |tmpdir|
|
||
|
File.write(tmpdir+"/zzz.rb", "#{<<~"begin;"}\n#{<<~'end;'}")
|
||
|
begin;
|
||
|
class AutoloadTest
|
||
|
ZZZ = :ZZZ
|
||
|
end
|
||
|
end;
|
||
|
assert_separately(%W[-I #{tmpdir}], "#{<<-"begin;"}\n#{<<-'end;'}")
|
||
|
bug = '[Bug #11055]'
|
||
|
begin;
|
||
|
class AutoloadTest
|
||
|
autoload :ZZZ, "zzz.rb"
|
||
|
deprecate_constant :ZZZ
|
||
|
end
|
||
|
assert_warning(/ZZZ is deprecated/, bug) {class AutoloadTest; ZZZ; end}
|
||
|
assert_warning(/ZZZ is deprecated/, bug) {AutoloadTest::ZZZ}
|
||
|
end;
|
||
|
assert_separately(%W[-I #{tmpdir}], "#{<<-"begin;"}\n#{<<-'end;'}")
|
||
|
bug = '[Bug #11055]'
|
||
|
begin;
|
||
|
class AutoloadTest
|
||
|
autoload :ZZZ, "zzz.rb"
|
||
|
deprecate_constant :ZZZ
|
||
|
end
|
||
|
assert_warning(/ZZZ is deprecated/, bug) {AutoloadTest::ZZZ}
|
||
|
end;
|
||
|
end
|
||
|
end
|
||
|
def test_autoload_fork
|
||
|
EnvUtil.default_warning do
|
||
|
Tempfile.create(['autoload', '.rb']) {|file|
|
||
| variable.c | ||
|---|---|---|
|
struct autoload_data_i *ele;
|
||
|
struct autoload_const *ac;
|
||
|
struct autoload_state state;
|
||
|
int flag = -1;
|
||
|
rb_const_entry_t *ce;
|
||
|
if (!autoload_defined_p(mod, id)) return Qfalse;
|
||
|
load = check_autoload_required(mod, id, &loading);
|
||
| ... | ... | |
|
src = rb_sourcefile();
|
||
|
if (src && loading && strcmp(src, loading) == 0) return Qfalse;
|
||
|
if ((ce = rb_const_lookup(mod, id))) {
|
||
|
flag = ce->flag & (CONST_DEPRECATED | CONST_VISIBILITY_MASK);
|
||
|
}
|
||
|
/* set ele->state for a marker of autoloading thread */
|
||
|
if (!(ele = get_autoload_data(load, &ac))) {
|
||
|
return Qfalse;
|
||
| ... | ... | |
|
result = rb_ensure(autoload_require, (VALUE)&state,
|
||
|
autoload_reset, (VALUE)&state);
|
||
|
if (flag > 0 && (ce = rb_const_lookup(mod, id))) {
|
||
|
ce->flag |= flag;
|
||
|
}
|
||
|
RB_GC_GUARD(load);
|
||
|
return result;
|
||
|
}
|
||