8000 Merge StringIO 3.0.1.2 for Ruby 3.1 by hsbt · Pull Request #10321 · ruby/ruby · GitHub
[go: up one dir, main page]

Skip to content

Merge StringIO 3.0.1.2 for Ruby 3.1 #10321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2024
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
Merge StringIO 3.0.1.2
  • Loading branch information
hsbt committed Apr 15, 2024
commit f143bdd775c8b5007d7e6d1a3bbd0e3969d0e0b0
4 changes: 2 additions & 2 deletions ext/stringio/stringio.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

**********************************************************************/

#define STRINGIO_VERSION "3.0.1"
#define STRINGIO_VERSION "3.0.1.2"

#include "ruby.h"
#include "ruby/io.h"
Expand Down Expand Up @@ -984,7 +984,7 @@ strio_unget_bytes(struct StringIO *ptr, const char *cp, long cl)
len = RSTRING_LEN(str);
rest = pos - len;
if (cl > pos) {
long ex = (rest < 0 ? cl-pos : cl+rest);
long ex = cl - (rest < 0 ? pos : len);
rb_str_modify_expand(str, ex);
rb_str_set_len(str, len + ex);
s = RSTRING_PTR(str);
Expand Down
25 changes: 21 additions & 4 deletions test/stringio/test_stringio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,15 @@ def test_ungetc_padding
assert_equal("b""\0""a", s.string)
end

def test_ungetc_fill
count = 100
s = StringIO.new
s.print 'a' * count
s.ungetc('b' * (count * 5))
assert_equal((count * 5), s.string.size)
assert_match(/\Ab+\z/, s.string)
end

def test_ungetbyte_pos
b = '\\b00010001 \\B00010001 \\b1 \\B1 \\b000100011'
s = StringIO.new( b )
Expand All @@ -784,6 +793,15 @@ def test_ungetbyte_padding
assert_equal("b""\0""a", s.string)
end

def test_ungetbyte_fill
count = 100
s = StringIO.new
s.print 'a' * count
s.ungetbyte('b' * (count * 5))
assert_equal((count * 5), s.string.size)
assert_match(/\Ab+\z/, s.string)
end

def test_frozen
s = StringIO.new
s.freeze
Exp 7C23 and Down Expand Up @@ -827,18 +845,17 @@ def test_new_block_warning
end

def test_overflow
omit if RbConfig::SIZEOF["void*"] > RbConfig::SIZEOF["long"]
return if RbConfig::SIZEOF["void*"] > RbConfig::SIZEOF["long"]
limit = RbConfig::LIMITS["INTPTR_MAX"] - 0x10
assert_separately(%w[-rstringio], "#{<<-"begin;"}\n#{<<-"end;"}")
begin;
limit = #{limit}
ary = []
while true
begin
x = "a"*0x100000
break if [x].pack("p").unpack("i!")[0] < 0
ary << x
omit if ary.size > 100
end
end while ary.size <= 100
s = StringIO.new(x)
s.gets("xxx", limit)
assert_equal(0x100000, s.pos)
Expand Down
0