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

ruby-changes:34132

From: nagachika <ko1@a...>
Date: Wed, 28 May 2014 23:39:04 +0900 (JST)
Subject: [ruby-changes:34132] nagachika:r46213 (ruby_2_1): merge revision(s) r45646: [Backport #9765]

nagachika	2014-05-28 23:38:54 +0900 (Wed, 28 May 2014)

  New Revision: 46213

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

  Log:
    merge revision(s) r45646: [Backport #9765]
    
    * ext/stringio/stringio.c (strio_putc): fix for non-ascii
      encoding, like as IO#putc.  [ruby-dev:48114] [Bug #9765]

  Modified directories:
    branches/ruby_2_1/
  Modified files:
    branches/ruby_2_1/ChangeLog
    branches/ruby_2_1/ext/stringio/stringio.c
    branches/ruby_2_1/test/stringio/test_stringio.rb
    branches/ruby_2_1/version.h
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 46212)
+++ ruby_2_1/ChangeLog	(revision 46213)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Wed May 28 23:37:32 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/stringio/stringio.c (strio_putc): fix for non-ascii
+	  encoding, like as IO#putc.  [ruby-dev:48114] [Bug #9765]
+
 Wed May 28 01:05:06 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/fileutils.rb (FileUtils#copy_entry): update rdoc about
Index: ruby_2_1/ext/stringio/stringio.c
===================================================================
--- ruby_2_1/ext/stringio/stringio.c	(revision 46212)
+++ ruby_2_1/ext/stringio/stringio.c	(revision 46213)
@@ -1233,17 +1233,17 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ext/stringio/stringio.c#L1233
 strio_putc(VALUE self, VALUE ch)
 {
     struct StringIO *ptr = writable(self);
-    int c = NUM2CHR(ch);
-    long olen;
+    VALUE str;
 
     check_modifiable(ptr);
-    olen = RSTRING_LEN(ptr->string);
-    if (ptr->flags & FMODE_APPEND) {
-	ptr->pos = olen;
+    if (RB_TYPE_P(ch, T_STRING)) {
+	str = rb_str_substr(ch, 0, 1);
     }
-    strio_extend(ptr, ptr->pos, 1);
-    RSTRING_PTR(ptr->string)[ptr->pos++] = c;
-    OBJ_INFECT(ptr->string, self);
+    else {
+	char c = NUM2CHR(ch);
+	str = rb_str_new(&c, 1);
+    }
+    strio_write(self, str);
     return ch;
 }
 
Index: ruby_2_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 46212)
+++ ruby_2_1/version.h	(revision 46213)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.2"
 #define RUBY_RELEASE_DATE "2014-05-28"
-#define RUBY_PATCHLEVEL 112
+#define RUBY_PATCHLEVEL 113
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 5
Index: ruby_2_1/test/stringio/test_stringio.rb
===================================================================
--- ruby_2_1/test/stringio/test_stringio.rb	(revision 46212)
+++ ruby_2_1/test/stringio/test_stringio.rb	(revision 46213)
@@ -419,6 +419,22 @@ class TestStringIO < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/stringio/test_stringio.rb#L419
     assert_equal("foo123", s)
   end
 
+  def test_putc_nonascii
+    s = ""
+    f = StringIO.new(s, "w")
+    f.putc("\u{3042}")
+    f.putc(0x3044)
+    f.close
+    assert_equal("\u{3042}D", s)
+
+    s = "foo"
+    f = StringIO.new(s, "a")
+    f.putc("\u{3042}")
+    f.putc(0x3044)
+    f.close
+    assert_equal("foo\u{3042}D", s)
+  end
+
   def test_read
     f = StringIO.new("\u3042\u3044")
     assert_raise(ArgumentError) { f.read(-1) }

Property changes on: ruby_2_1
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r45646


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

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