Forum: Ruby-core [ruby-trunk - Bug #7231][Open] StringIO inconsistently raises IOError or RuntimeError if the string

Posted by Brian Ford (brixen)
on 2012-10-28 20:05
(Received via mailing list)
Issue #7231 has been reported by brixen (Brian Ford).

----------------------------------------
Bug #7231: StringIO inconsistently raises IOError or RuntimeError if the 
string is frozen
https://bugs.ruby-lang.org/issues/7231

Author: brixen (Brian Ford)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 1.9.3p286 (2012-10-12 revision 37165) 
[x86_64-darwin10.8.0]


StringIO#ungetc, #ungetbyte raise RuntimeError if the data string is 
frozen. StringIO#write raises IOError.

Why?

1.9.3p286 :001 > require 'stringio'
 => true
1.9.3p286 :002 > s = StringIO.new x = "abc"
 => #<StringIO:0x00000101020038>
1.9.3p286 :003 > x.freeze
 => "abc"
1.9.3p286 :004 > s.ungetbyte 0x42
RuntimeError: can't modify frozen String
  from (irb):4:in `ungetbyte'
  from (irb):4
  from /Users/brian/.rvm/rubies/ruby-1.9.3-p286/bin/irb:16:in `<main>'
1.9.3p286 :005 > s.ungetc "w"
RuntimeError: can't modify frozen String
  from (irb):5:in `ungetc'
  from (irb):5
  from /Users/brian/.rvm/rubies/ruby-1.9.3-p286/bin/irb:16:in `<main>'
1.9.3p286 :006 > s.write "d"
IOError: not modifiable string
  from (irb):6:in `write'
  from (irb):6
  from /Users/brian/.rvm/rubies/ruby-1.9.3-p286/bin/irb:16:in `<main>'

Thanks,
Brian
Posted by mame (Yusuke Endoh) (Guest)
on 2012-11-05 16:25
(Received via mailing list)
Issue #7231 has been updated by mame (Yusuke Endoh).


Indeed.  I think that it should raise IOError constantly.  Any opinion?
Anyone could create a patch, please?

--
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Bug #7231: StringIO inconsistently raises IOError or RuntimeError if the 
string is frozen
https://bugs.ruby-lang.org/issues/7231#change-32439

Author: brixen (Brian Ford)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 1.9.3p286 (2012-10-12 revision 37165) 
[x86_64-darwin10.8.0]


StringIO#ungetc, #ungetbyte raise RuntimeError if the data string is 
frozen. StringIO#write raises IOError.

Why?

1.9.3p286 :001 > require 'stringio'
 => true
1.9.3p286 :002 > s = StringIO.new x = "abc"
 => #<StringIO:0x00000101020038>
1.9.3p286 :003 > x.freeze
 => "abc"
1.9.3p286 :004 > s.ungetbyte 0x42
RuntimeError: can't modify frozen String
  from (irb):4:in `ungetbyte'
  from (irb):4
  from /Users/brian/.rvm/rubies/ruby-1.9.3-p286/bin/irb:16:in `<main>'
1.9.3p286 :005 > s.ungetc "w"
RuntimeError: can't modify frozen String
  from (irb):5:in `ungetc'
  from (irb):5
  from /Users/brian/.rvm/rubies/ruby-1.9.3-p286/bin/irb:16:in `<main>'
1.9.3p286 :006 > s.write "d"
IOError: not modifiable string
  from (irb):6:in `write'
  from (irb):6
  from /Users/brian/.rvm/rubies/ruby-1.9.3-p286/bin/irb:16:in `<main>'

Thanks,
Brian
Posted by usa (Usaku NAKAMURA) (Guest)
on 2012-12-21 14:54
(Received via mailing list)
Issue #7231 has been updated by usa (Usaku NAKAMURA).

Category set to ext
Status changed from Open to Assigned
Assignee set to nobu (Nobuyoshi Nakada)
Target version set to 2.0.0


----------------------------------------
Bug #7231: StringIO inconsistently raises IOError or RuntimeError if the 
string is frozen
https://bugs.ruby-lang.org/issues/7231#change-34970

Author: brixen (Brian Ford)
Status: Assigned
Priority: Normal
Assignee: nobu (Nobuyoshi Nakada)
Category: ext
Target version: 2.0.0
ruby -v: ruby 1.9.3p286 (2012-10-12 revision 37165) 
[x86_64-darwin10.8.0]


StringIO#ungetc, #ungetbyte raise RuntimeError if the data string is 
frozen. StringIO#write raises IOError.

Why?

1.9.3p286 :001 > require 'stringio'
 => true
1.9.3p286 :002 > s = StringIO.new x = "abc"
 => #<StringIO:0x00000101020038>
1.9.3p286 :003 > x.freeze
 => "abc"
1.9.3p286 :004 > s.ungetbyte 0x42
RuntimeError: can't modify frozen String
  from (irb):4:in `ungetbyte'
  from (irb):4
  from /Users/brian/.rvm/rubies/ruby-1.9.3-p286/bin/irb:16:in `<main>'
1.9.3p286 :005 > s.ungetc "w"
RuntimeError: can't modify frozen String
  from (irb):5:in `ungetc'
  from (irb):5
  from /Users/brian/.rvm/rubies/ruby-1.9.3-p286/bin/irb:16:in `<main>'
1.9.3p286 :006 > s.write "d"
IOError: not modifiable string
  from (irb):6:in `write'
  from (irb):6
  from /Users/brian/.rvm/rubies/ruby-1.9.3-p286/bin/irb:16:in `<main>'

Thanks,
Brian
Posted by Glass_saga (Masaki Matsushita) (Guest)
on 2012-12-25 04:01
(Received via mailing list)
Issue #7231 has been updated by Glass_saga (Masaki Matsushita).

File patch.diff added

How about the patch?
----------------------------------------
Bug #7231: StringIO inconsistently raises IOError or RuntimeError if the 
string is frozen
https://bugs.ruby-lang.org/issues/7231#change-35053

Author: brixen (Brian Ford)
Status: Assigned
Priority: Normal
Assignee: nobu (Nobuyoshi Nakada)
Category: ext
Target version: 2.0.0
ruby -v: ruby 1.9.3p286 (2012-10-12 revision 37165) 
[x86_64-darwin10.8.0]


StringIO#ungetc, #ungetbyte raise RuntimeError if the data string is 
frozen. StringIO#write raises IOError.

Why?

1.9.3p286 :001 > require 'stringio'
 => true
1.9.3p286 :002 > s = StringIO.new x = "abc"
 => #<StringIO:0x00000101020038>
1.9.3p286 :003 > x.freeze
 => "abc"
1.9.3p286 :004 > s.ungetbyte 0x42
RuntimeError: can't modify frozen String
  from (irb):4:in `ungetbyte'
  from (irb):4
  from /Users/brian/.rvm/rubies/ruby-1.9.3-p286/bin/irb:16:in `<main>'
1.9.3p286 :005 > s.ungetc "w"
RuntimeError: can't modify frozen String
  from (irb):5:in `ungetc'
  from (irb):5
  from /Users/brian/.rvm/rubies/ruby-1.9.3-p286/bin/irb:16:in `<main>'
1.9.3p286 :006 > s.write "d"
IOError: not modifiable string
  from (irb):6:in `write'
  from (irb):6
  from /Users/brian/.rvm/rubies/ruby-1.9.3-p286/bin/irb:16:in `<main>'

Thanks,
Brian
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.