Skip to content

Allow seek when underlying string is frozen #121

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 2 commits into from
Feb 21, 2025
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
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
Loading