Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions io.c
Original file line number Diff line number Diff line change
Expand Up @@ -4900,7 +4900,7 @@ static VALUE
rb_io_each_codepoint(VALUE io)
{
rb_io_t *fptr;
rb_encoding *enc;
rb_encoding *enc, *read_enc;
unsigned int c;
int r, n;

Expand All @@ -4914,12 +4914,13 @@ rb_io_each_codepoint(VALUE io)
r = 1; /* no invalid char yet */
for (;;) {
make_readconv(fptr, 0);
read_enc = io_read_encoding(fptr);
for (;;) {
if (fptr->cbuf.len) {
if (fptr->encs.enc)
if (read_enc)
r = rb_enc_precise_mbclen(fptr->cbuf.ptr+fptr->cbuf.off,
fptr->cbuf.ptr+fptr->cbuf.off+fptr->cbuf.len,
fptr->encs.enc);
read_enc);
else
r = ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(1);
if (!MBCLEN_NEEDMORE_P(r))
Expand All @@ -4931,21 +4932,21 @@ rb_io_each_codepoint(VALUE io)
if (more_char(fptr) == MORE_CHAR_FINISHED) {
clear_readconv(fptr);
if (!MBCLEN_CHARFOUND_P(r)) {
enc = fptr->encs.enc;
enc = read_enc;
goto invalid;
}
return io;
}
}
if (MBCLEN_INVALID_P(r)) {
enc = fptr->encs.enc;
enc = read_enc;
goto invalid;
}
n = MBCLEN_CHARFOUND_LEN(r);
if (fptr->encs.enc) {
if (read_enc) {
c = rb_enc_codepoint(fptr->cbuf.ptr+fptr->cbuf.off,
fptr->cbuf.ptr+fptr->cbuf.off+fptr->cbuf.len,
fptr->encs.enc);
read_enc);
}
else {
c = (unsigned char)fptr->cbuf.ptr[fptr->cbuf.off];
Expand Down
13 changes: 13 additions & 0 deletions test/ruby/test_io_m17n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2806,4 +2806,17 @@ def test_each_codepoint_need_more
flunk failure.join("\n---\n")
end
end

def test_each_codepoint_encoding_with_ungetc
File.open(File::NULL, "rt:utf-8") do |f|
f.ungetc(%Q[\u{3042}\u{3044}\u{3046}])
assert_equal [0x3042, 0x3044, 0x3046], f.each_codepoint.to_a
end
File.open(File::NULL, "rt:us-ascii") do |f|
f.ungetc(%Q[\u{3042}\u{3044}\u{3046}])
assert_raise(ArgumentError) do
f.each_codepoint.to_a
end
end
end
end
2 changes: 1 addition & 1 deletion test/rubygems/test_gem_package_tar_header_ractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ def test_encode_in_ractor
assert_headers_equal header_bytes, new_header_bytes
RUBY
end
end
end unless RUBY_PLATFORM.match?(/mingw|mswin/)
1 change: 0 additions & 1 deletion tool/lib/core_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ def assert_separately(args, file = nil, line = nil, src, ignore_stderr: nil, **o
# Run Ractor-related test without influencing the main test suite
def assert_ractor(src, args: [], require: nil, require_relative: nil, file: nil, line: nil, ignore_stderr: nil, **opt)
omit unless defined?(Ractor)
omit if windows?

# https://bugs.ruby-lang.org/issues/21262
shim_value = "class Ractor; alias value take; end" unless Ractor.method_defined?(:value)
Expand Down
6 changes: 5 additions & 1 deletion tool/sync_default_gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ def lib((upstream, branch), gemspec_in_subdir: false)
])
end

# Note: tool/auto_review_pr.rb also depends on this constant.
# Note: tool/auto_review_pr.rb also depends on these constants.
NO_UPSTREAM = [
"lib/unicode_normalize", # not to match with "lib/un"
]
REPOSITORIES = {
"io-console": repo("ruby/io-console", [
["ext/io/console", "ext/io/console"],
Expand Down Expand Up @@ -295,6 +298,7 @@ def lib((upstream, branch), gemspec_in_subdir: false)

class << Repository
def find_upstream(file)
return if NO_UPSTREAM.any? {|dst| file.start_with?(dst) }
REPOSITORIES.find do |repo_name, repository|
if repository.mappings.any? {|_src, dst| file.start_with?(dst) }
break repo_name
Expand Down
15 changes: 15 additions & 0 deletions tool/test/test_sync_default_gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,5 +346,20 @@ def test_squash_merge
assert_equal("[ruby/#@target] Merge commit", subject, out)
assert_includes(body, "Commit in branch", out)
end

def test_no_upstream_file
group = SyncDefaultGems::Repository.group(%w[
lib/un.rb
lib/unicode_normalize/normalize.rb
lib/unicode_normalize/tables.rb
lib/net/https.rb
])
expected = {
"un" => %w[lib/un.rb],
"net-http" => %w[lib/net/https.rb],
nil => %w[lib/unicode_normalize/normalize.rb lib/unicode_normalize/tables.rb],
}
assert_equal(expected, group)
end
end if /darwin|linux/ =~ RUBY_PLATFORM
end