fixed encoding table

This reduces global lock acquiring for reading.
https://bugs.ruby-lang.org/issues/18949
This commit is contained in:
Koichi Sasada 2022-12-15 17:53:55 +09:00
parent 15b60bb1a4
commit ae19ac5b5b
Notes: git 2022-12-16 01:04:55 +00:00
4 changed files with 61 additions and 115 deletions

View file

@ -69,7 +69,7 @@ class TestEncoding < Test::Unit::TestCase
def test_extra_encoding
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
200.times {|i|
100.times {|i|
EnvUtil.suppress_warning { Encoding::UTF_8.replicate("dummy#{i}") }
}
e = Encoding.list.last
@ -160,4 +160,18 @@ class TestEncoding < Test::Unit::TestCase
end
end;
end
def test_exceed_encoding_table_size
assert_separately(%w[--disable=gems], "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
begin
enc = Encoding::UTF_8
1_000.times{|i| EnvUtil.suppress_warning{ enc.replicate("R_#{i}") } } # now 256 entries
rescue EncodingError => e
assert_match(/too many encoding/, e.message)
else
assert false
end
end;
end
end