Repository navigation
Return a String from ARGF.getc and ARGF.readchar when reading files - #10033
Merged
Merged
Conversation
taxor03
force-pushed
the
fix-argf-getc
branch
from
November 11, 2026 06:33
0a38d8d to
236adcc
Compare
taxor03
force-pushed
the
fix-argf-getc
branch
from
November 11, 2026 07:03
236adcc to
0c0fe5f
Compare
headius
approved these changes
Nov 11, 2026
headius
left a comment
Member
There was a problem hiding this comment.
Likely never updated since Ruby 1.8 returned Fixnum from these methods.
Member
|
Looks like I botched the merge to master. looking into it. |
headius
added a commit
that referenced
this pull request
Nov 12, 2026
This was merged prematurely in #10033 and needs additional work to pass. Removing here temporarily.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #10032.
When the current file was a
File,RubyArgsFile#getccalledgetbyteon it, soARGF.getcandARGF.readcharreturned Integers (one per byte) instead of one-character Strings. Other inputs, like$stdin, already went throughgetc. CRuby'sargf_getcandargf_readcharcallrb_io_getcon the file, so this now callsRubyIO#getc.each_byteandeach_charwere built on the samegetc, so they change too:each_bytenow callsgetbyte. It yielded one-character Strings, not Integers, when reading$stdin.each_charnow yields whatgetcreturns. It joined bytes into characters using the runtime's KCode setting (binary by default), not the stream's encoding. For a file it splitéinto"\xC3"and"\xA9", and for$stdinit dropped bytes.With a file or
$stdincontaining"hé\n":ARGF.getc(file)104"h"ARGF.each_char.to_a(file)["h", "\xC3", "\xA9", "\n"]["h", "é", "\n"]ARGF.each_char.to_a($stdin)["h", "\xC3", "\n"]["h", "é", "\n"]ARGF.each_byte.to_a($stdin)["h", "é", "\n"][104, 195, 169, 10]ARGF.each_byteon files andARGF.getcon$stdinalready worked and are unchanged. CRuby'sargf_each_byteandargf_each_charcalleach_byteandeach_charon each file instead. I kept the loops overgetbyteandgetc, because they already handleARGF.skipinside the block the way CRuby does. With this changeTestArgf#test_skip_in_each_charpasses, so its exclude is removed.The existing specs only used ASCII files and built the result with
String#<<, which also accepts an Integer. This adds a small UTF-8 fixture and examples forgetcandreadchar(sharedgetc.rb) andeach_char, plus$stdinexamples foreach_byteandeach_char. The multibyte examples callset_encodingso they don't depend on the default external encoding. The 5 new examples fail before this change and pass after it.spec/ruby/core/argfpasses on CRuby 4.0.9, 3.4.12 and 3.3.13, withLANG=C.UTF-8andLANG=C.Tested with
spec/ruby/core/argf(also with-Xjit.threshold=0),spec/ruby/core/io,test/mri/ruby/test_argf.rband the fast RubySpec suite. No new failures.