Skip to content

Commit

Permalink
Allow seek when underlying string is frozen (#121)
Browse files Browse the repository at this point in the history
Fixes #119. Adds a test for this expectation.
  • Loading branch information
headius authored Feb 21, 2025
1 parent 3f56884 commit 3f90fe4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 2 additions & 4 deletions ext/java/org/jruby/ext/stringio/StringIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -1356,8 +1356,6 @@ public IRubyObject seek(ThreadContext context, IRubyObject arg0, IRubyObject arg
}

private RubyFixnum seekCommon(ThreadContext context, int argc, IRubyObject arg0, IRubyObject arg1) {
checkModifiable();

Ruby runtime = context.runtime;

IRubyObject whence = context.nil;
Expand All @@ -1367,10 +1365,10 @@ private RubyFixnum seekCommon(ThreadContext context, int argc, IRubyObject arg0,
whence = arg1;
}

checkOpen();

StringIOData ptr = this.getPtr();

checkOpen();

boolean locked = lock(context, ptr);
try {
switch (whence.isNil() ? 0 : RubyNumeric.num2int(whence)) {
Expand Down
5 changes: 5 additions & 0 deletions test/stringio/test_stringio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,11 @@ def test_seek
f.close unless f.closed?
end

def test_seek_frozen_string
f = StringIO.new(-"1234")
assert_equal(0, f.seek(1))
end

def test_each_byte
f = StringIO.new("1234")
a = []
Expand Down

0 comments on commit 3f90fe4

Please sign in to comment.