Project

General

Profile

Bug #7231

StringIO inconsistently raises IOError or RuntimeError if the string is frozen

Added by Brian Shirai over 3 years ago. Updated about 3 years ago.

Status:
Closed
Priority:
Normal
ruby -v:
ruby 1.9.3p286 (2012-10-12 revision 37165) [x86_64-darwin10.8.0]
Backport:
2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
[ruby-core:48530]

Description

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
'
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
'
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
'

Thanks,
Brian

patch.diff Magnifier (1.21 KB) Masaki Matsushita, 12/25/2012 12:01 PM

Associated revisions

Revision 38628
Added by glass about 3 years ago

  • ext/stringio/stringio.c (strio_ungetc): raise IOError instead of RuntimeError
    if the string is frozen.
    [Bug #7231]

  • ext/stringio/stringio.c (strio_ungetbyte): ditto.

  • test/stringio/test_stringio.rb: a test for above.

Revision 38628
Added by glass about 3 years ago

  • ext/stringio/stringio.c (strio_ungetc): raise IOError instead of RuntimeError
    if the string is frozen.
    [Bug #7231]

  • ext/stringio/stringio.c (strio_ungetbyte): ditto.

  • test/stringio/test_stringio.rb: a test for above.

History

#1 [ruby-core:48935] Updated by Yusuke Endoh over 3 years ago

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

--
Yusuke Endoh mame@tsg.ne.jp

#2 [ruby-core:51058] Updated by Usaku NAKAMURA about 3 years ago

  • Category set to ext
  • Status changed from Open to Assigned
  • Assignee set to Nobuyoshi Nakada
  • Target version set to 2.0.0

#3 [ruby-core:51121] Updated by Masaki Matsushita about 3 years ago

How about the patch?

#4 Updated by Anonymous about 3 years ago

  • % Done changed from 0 to 100
  • Status changed from Assigned to Closed

This issue was solved with changeset r38628.
Brian, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • ext/stringio/stringio.c (strio_ungetc): raise IOError instead of RuntimeError
    if the string is frozen.
    [Bug #7231]

  • ext/stringio/stringio.c (strio_ungetbyte): ditto.

  • test/stringio/test_stringio.rb: a test for above.

Also available in: Atom PDF