(https://github.com/ruby/stringio/pull/77)
Followup of #79
`rb_str_resize()` was changed by b0b9f7201a .
```c
rb_str_resize(string, shorter) // clear ENC_CODERANGE in some case
rb_str_resize(string, longer) // does not clear ENC_CODERANGE anymore
```
```c
// rb_str_resize in string.c
if (slen > len && ENC_CODERANGE(str) != ENC_CODERANGE_7BIT) {
ENC_CODERANGE_CLEAR(str);
}
```
I think this change is based on an assumption that appending null bytes
will not change flag `ascii_only?`.
`strio_extend()` will make the string longer if needed, and update the
flags correctly for appending null bytes.
Before `memmove()`, we need to `rb_str_modify()` because updated flags are not
updated for `memmove()`.
https://github.com/ruby/stringio/commit/b31a538576
Both for being closer to real IOs and also because it's a convenient API
in multithreaded scenarios.
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
Try to mirror IO behavior, where chomp takes out the entire paragraph
separators between entries, but does not chomp a single line separator
at the end of the string.
Partially Fixes [Bug #18768]
https://github.com/ruby/stringio/commit/a83ddbb7f0
Previously, this could result in an infinite loop. Always update
the e pointer in this case, setting w when chomping so the chomped
data is not included in the output.
Fixes [Bug #18769]
https://github.com/ruby/stringio/commit/4bf64d5130
FrozenError will be used instead of RuntimeError for exceptions
raised when there is an attempt to modify a frozen object. The
reason for this change is to differentiate exceptions related
to frozen objects from generic exceptions such as those generated
by Kernel#raise without an exception class.
From: Jeremy Evans <code@jeremyevans.net>
Signed-off-by: Urabe Shyouhei <shyouhei@ruby-lang.org>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/stringio/stringio.c (strio_write_m): make StringIO#write
accept multiple arguments, as well as IO#write.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60377 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/stringio/stringio.c (strio_gets): should return string with
the external encoding, at empty chomped result .
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59582 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/stringio/stringio.c (strio_gets): should return string with
the external encoding, at empty result.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59581 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/stringio/stringio.c (strio_read): should return string with
the external encoding, at EOF too.
[ruby-core:82349] [Bug #13806]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59578 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* test/stringio/test_stringio.rb (test_read): add assertions
of return value of read with a buffer string.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/stringio/stringio.c (strio_ungetc): raise RangeError instead
of TypeError at too big value, as well as IO#ungetc.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/stringio/stringio.c (strio_ungetc): check if the character
code is valid in the encoding. reported by Ahmad Sherif
(ahmadsherif) at https://hackerone.com/reports/209593.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/stringio/stringio.c (strio_getline): chomp CR not only LF,
as well as String#chomp.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/stringio/stringio.c (strio_seek): Avoid signed integer overflow.
It's not harmful in practice here, but is still undefined behavior.
* ext/stringio/stringio.c (strio_extend): Check that the new length does
not exceed LONG_MAX. This fixes the invalid write on the overflow.
* test/stringio/test_stringio.rb (test_write_integer_overflow): Add a
test case for the above fix in strio_extend().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56253 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* test/stringio/test_stringio.rb (test_overflow): reduce maximum
retry count to get rid of timeout on some platforms.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* test/stringio/test_stringio.rb (test_overflow): could occur only
on sizeof(long) >= sizeof(void*).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* test/stringio/test_stringio.rb (test_overflow): refine the
conditinon, try to allocate strings until the buffer is located
in higher half address.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/stringio/stringio.c (strio_s_new): warn if a block is given,
as well as IO.new.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This should match the behavior of IO#binmode as far
as treating content as ASCII-8BIT (binary).
* ext/stringio/stringio.c (strio_binmode): implement to set encoding
* test/stringio/test_stringio.rb (test_binmode): new test
[ruby-core:72699] [Bug #11945]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53435 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/stringio/stringio.c (strio_set_encoding): add StringIO's own
encoding and separate it from the buffer string to override the
encoding of string when reading. [ruby-core:72189] [Bug #11827]
note that setting the encoding of its buffer string may cause
unpredictable behavior.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* ext/stringio/stringio.c (strio_ungetbyte): pad with \000 when
the current position is after the end.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e