-
Notifications
You must be signed in to change notification settings - Fork 31
Several read-only methods fail if StringIO is frozen #120
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
Comments
headius
added a commit
to headius/stringio
that referenced
this issue
Feb 20, 2025
headius
added a commit
to headius/stringio
that referenced
this issue
Feb 20, 2025
This was referenced Feb 20, 2025
Good catch! But it seems that $ ruby -e 'File.open("README.md") {|f| f.freeze; f.lineno}'
-e:1:in 'IO#lineno': can't modify frozen File: #<File:README.md> (FrozenError)
from -e:1:in 'block in <main>'
from -e:1:in 'IO.open'
from -e:1:in '<main>' How about discussing this in https://bugs.ruby-lang.org/ not here? |
@kou I will open an issue on ruby-lang! Thanks! |
OK. I'll release a new version with #121. |
Done. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem
While fixing a small regression from my recent StringIO fixes I discovered that a large number of read-only methods will fail if the StringIO is frozen. A few examples:
Cause
This is because the
StringIO
macro callsget_strio
which callsrb_io_taint_check
which callsrb_check_frozen
. TheStringIO
macro is used in almost every method to access the rb_stringio_t data structure.A list of methods I believe should be operable when the StringIO is frozen (in stringio.c definition order):
In addition,
initialize_copy
probably should not require the original StringIO be writable:The data from the original StringIO is unmodified by
initialize_copy
, other than the reference-countingptr->count
(which should not be subject to frozen checks).Origin
I believe most of these cases are caused by this change from 2011 that added frozen checks to StringIO (the class and the macro).
ruby/ruby@d8d9bac
Fix
Assuming we agree these read-only methods should work with a frozen, I'll modify them in the JRuby extension to do the equivalent of
check_strio
which only confirms theptr
has been initialized. Perhaps aStringIOReadOnly
macro would make sense for CRuby.The text was updated successfully, but these errors were encountered: