Skip to content

Commit 65b144b

Browse files
karesheadius
authored andcommitted
fix: (jruby) failing to clean buffer's code-range
same bug as: jruby/jruby#9035
1 parent 10e991e commit 65b144b

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

ext/java/org/jruby/ext/stringio/StringIO.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,19 +1067,19 @@ public IRubyObject putc(ThreadContext context, IRubyObject ch) {
10671067

10681068
public static final ByteList NEWLINE = ByteList.create("\n");
10691069

1070-
@JRubyMethod(name = "read")
1070+
@JRubyMethod(name = "read") // strio.read()
10711071
public IRubyObject read(ThreadContext context) {
10721072
return readCommon(context, 0, null, null);
10731073
}
10741074

1075-
@JRubyMethod(name = "read")
1076-
public IRubyObject read(ThreadContext context, IRubyObject arg0) {
1077-
return readCommon(context, 1, arg0, null);
1075+
@JRubyMethod(name = "read") // // strio.read([length)
1076+
public IRubyObject read(ThreadContext context, IRubyObject length) {
1077+
return readCommon(context, 1, length, null);
10781078
}
10791079

1080-
@JRubyMethod(name = "read")
1081-
public IRubyObject read(ThreadContext context, IRubyObject arg0, IRubyObject arg1) {
1082-
return readCommon(context, 2, arg0, arg1);
1080+
@JRubyMethod(name = "read") // strio.read(length, outbuf)
1081+
public IRubyObject read(ThreadContext context, IRubyObject length, IRubyObject outbuf) {
1082+
return readCommon(context, 2, length, outbuf);
10831083
}
10841084

10851085
@SuppressWarnings("fallthrough")
@@ -1102,7 +1102,7 @@ private IRubyObject readCommon(ThreadContext context, int argc, IRubyObject arg0
11021102
str = arg1;
11031103
if (!str.isNil()) {
11041104
str = str.convertToString();
1105-
((RubyString) str).modify();
1105+
modifyString((RubyString) str);
11061106
}
11071107
case 1:
11081108
if (!arg0.isNil()) {
@@ -1198,7 +1198,7 @@ private RubyString preadCommon(ThreadContext context, int argc, IRubyObject arg0
11981198
str = arg2;
11991199
if (!str.isNil()) {
12001200
str = str.convertToString();
1201-
((RubyString) str).modify();
1201+
modifyString((RubyString) str);
12021202
}
12031203
case 2:
12041204
len = RubyNumeric.fix2int(arg0);

test/stringio/test_stringio.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,20 @@ def test_coderange_after_overwrite
10641064
assert_predicate(s.string, :ascii_only?)
10651065
end
10661066

1067+
def test_coderange_after_read_into_buffer
1068+
s = StringIO.new("01234567890".b)
1069+
1070+
buf = "¿Cómo estás? Ça va bien?"
1071+
assert_not_predicate(buf, :ascii_only?)
1072+
1073+
assert_predicate(s.string, :ascii_only?)
1074+
1075+
s.read(10, buf)
1076+
1077+
assert_predicate(buf, :ascii_only?)
1078+
assert_equal '0123456789', buf
1079+
end
1080+
10671081
require "objspace"
10681082
if ObjectSpace.respond_to?(:dump) && ObjectSpace.dump(eval(%{"test"})).include?('"chilled":true') # Ruby 3.4+ chilled strings
10691083
def test_chilled_string

0 commit comments

Comments
 (0)