Repository navigation
Fix the arguments and return values of Zlib::GzipReader's line and byte methods - #3330
Open
hasannadeem wants to merge 1 commit into
Open
hasannadeem wants to merge 1 commit into
hasannadeem wants to merge 1 commit into
Conversation
…te methods GzipReader#gets, #readline, #readlines, #each and #each_line take a nil separator, a lone limit and a nil limit, like IO#gets. #each and #each_line return the reader, and without a block return an Enumerator. #each_byte yields Integers, and #each_byte and #each_char return nil, or an Enumerator without a block. #ungetc also takes an Integer, which it pushes back as a byte.
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.
This PR fixes the arguments and return values of
Zlib::GzipReader's line and byte methods, aszlib.cimplements them.Line methods
gets,readline,readlines,eachandeach_lineall go throughgzreader_gets. LikeIO#gets, it takes anilseparator (read to the end), a lone limit, or anillimit after a separator. The signatures only allowed(?String sep, ?Integer limit):eachandeach_linewere typed as(*untyped) { (String) -> void } -> void. They return the reader, and without a block they return an Enumerator.gzreader_getsscans"11", with no keywords, so there is nochomp:here.gz.gets(chomp: true)raisesTypeError("no implicit conversion of Hash into Integer"), and the signatures don't add it.Byte and char methods
each_byteyields Integers, not Strings.each_byteandeach_charreturnnilwith a block. Without one they return an Enumerator, which the signatures didn't allow.ungetcalso takes an Integer.rb_gzreader_ungetchands a Fixnum toungetbyte, and anything else goes throughStringValue.Not typed
Without a block,
each_line(2)returns an Enumerator over whole lines:RETURN_ENUMERATOR(obj, 0, 0)drops the arguments. So the blockless overload takes no arguments.Checked
test/stdlib/zlib/GzipReader_test.rbpasses on both. With the old signature, the 8 new tests fail.gets(:x),gets(chomp: true)andInteger#upcaseon aneach_bytevalue.rbs -r zlib validatepasses, andrbs annotatemakes no further changes to the file.