[前][次][番号順一覧][スレッド一覧]

ruby-changes:26577

From: glass <ko1@a...>
Date: Thu, 27 Dec 2012 20:43:13 +0900 (JST)
Subject: [ruby-changes:26577] glass:r38628 (trunk): * ext/stringio/stringio.c (strio_ungetc): raise IOError instead of RuntimeError

glass	2012-12-27 20:43:02 +0900 (Thu, 27 Dec 2012)

  New Revision: 38628

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38628

  Log:
    * ext/stringio/stringio.c (strio_ungetc): raise IOError instead of RuntimeError
      if the string is frozen.
      [Bug #7231] [ruby-core:48530]
    
    * ext/stringio/stringio.c (strio_ungetbyte): ditto.
    
    * test/stringio/test_stringio.rb: a test for above.

  Modified files:
    trunk/ChangeLog
    trunk/ext/stringio/stringio.c
    trunk/test/stringio/test_stringio.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38627)
+++ ChangeLog	(revision 38628)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Dec 27 20:11:29 2012  Masaki Matsushita  <glass.saga@g...>
+
+	* ext/stringio/stringio.c (strio_ungetc): raise IOError instead of RuntimeError
+	  if the string is frozen.
+	  [Bug #7231] [ruby-core:48530]
+
+	* ext/stringio/stringio.c (strio_ungetbyte): ditto.
+
+	* test/stringio/test_stringio.rb: a test for above.
+
 Wed Dec 26 23:55:18 2012  Keiju Ishitsuka  <keiju@i...>
 
 	* lib/irb/context.rb: fix IRB::Inspector#keys_with_inspector [Bug #7598]
Index: ext/stringio/stringio.c
===================================================================
--- ext/stringio/stringio.c	(revision 38627)
+++ ext/stringio/stringio.c	(revision 38628)
@@ -737,6 +737,7 @@ strio_ungetc(VALUE self, VALUE c) https://github.com/ruby/ruby/blob/trunk/ext/stringio/stringio.c#L737
     rb_encoding *enc, *enc2;
 
     if (NIL_P(c)) return Qnil;
+    check_modifiable(ptr);
     if (FIXNUM_P(c)) {
 	int cc = FIX2INT(c);
 	char buf[16];
@@ -801,6 +802,7 @@ strio_ungetbyte(VALUE self, VALUE c) https://github.com/ruby/ruby/blob/trunk/ext/stringio/stringio.c#L802
 	cl = RSTRING_LEN(c);
 	if (cl == 0) return Qnil;
     }
+    check_modifiable(ptr);
     rb_str_modify(str);
     if (cl > pos) {
 	char *s;
Index: test/stringio/test_stringio.rb
===================================================================
--- test/stringio/test_stringio.rb	(revision 38627)
+++ test/stringio/test_stringio.rb	(revision 38628)
@@ -504,6 +504,14 @@ class TestStringIO < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/stringio/test_stringio.rb#L504
     assert_raise(RuntimeError, bug) {s.reopen("")}
   end
 
+  def test_frozen_string
+    s = StringIO.new("".freeze)
+    bug = '[ruby-core:48530]'
+    assert_raise(IOError, bug) {s.write("foo")}
+    assert_raise(IOError, bug) {s.ungetc("a")}
+    assert_raise(IOError, bug) {s.ungetbyte("a")}
+  end
+
   def test_readlines_limit_0
     assert_raise(ArgumentError, "[ruby-dev:43392]") { StringIO.new.readlines(0) }
   end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]