Skip to content
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

Ruby 1.9.3 - StringIO clone method creates new instance but somehow connected with the original instance #3260

Closed
mbrunat opened this issue Aug 18, 2015 · 3 comments

Comments

@mbrunat
Copy link

mbrunat commented Aug 18, 2015

Already posted to Ruby community as https://bugs.ruby-lang.org/issues/11445 but rejected because 1.9 is close.
I don't know whether you have same support range or not so sending here too.

In Ruby 1.9.3 cloned StringIO instance has influence on close state of original instance:

require 'stringio'

sio1 = StringIO.new( 'abc' )
sio2 = sio1.clone

sio2.read
sio1.pos # => 3, expected 0

sio2.close
sio1.closed? # => true, expected false

If File is used instead of StringIO, close state is not shared between instances (position is).

This behaviour has changed in Ruby 2.0.0 (cloned StringIO instance does not close original instance).

It matters what definition for IO clone is, whether to share attributes (e.g. pos) and/or state (closed?) but the later is acting differently in 1.9.3 for StringIO and File.

This is also true for 2.0 until JRuby 1.7.9+

@headius
Copy link
Member

headius commented Aug 18, 2015

Seems like an ok thing to fix, and we're still supporting JRuby 1.7. However changing visible behavior away from MRI is something we generally don't do.

Perhaps you could update to JRuby 9k, which is compatible with Ruby 2.2?

@headius
Copy link
Member

headius commented Aug 18, 2015

Actually it looks like this is half fixed on both 1.7 and 9k. closed? returns false as expected, but the position does appear to be shared.

@headius
Copy link
Member

headius commented Aug 18, 2015

It appears that MRI does not do what you want, even in 2.2. It isolates closed? state but shares pos state.

Both JRuby 1.7.21 and JRuby 9.0.0.0 follow the same behavior.

If you believe the behavior of Ruby 2.2 (sharing pos) is incorrect, you should file a new issue against ruby trunk and make your case there. If they change it, we'll change it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants