ruby-changes:14138
From: yugui <ko1@a...>
Date: Fri, 27 Nov 2009 11:55:59 +0900 (JST)
Subject: [ruby-changes:14138] Ruby:r25952 (ruby_1_9_1): merges r25127 from trunk into ruby_1_9_1.
yugui 2009-11-27 11:55:41 +0900 (Fri, 27 Nov 2009) New Revision: 25952 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25952 Log: merges r25127 from trunk into ruby_1_9_1. -- * stringio/stringio.c (strio_read): set ASCII-8BIT encoding when length argument is given. Modified files: branches/ruby_1_9_1/ChangeLog branches/ruby_1_9_1/ext/stringio/stringio.c branches/ruby_1_9_1/test/stringio/test_stringio.rb branches/ruby_1_9_1/version.h Index: ruby_1_9_1/ChangeLog =================================================================== --- ruby_1_9_1/ChangeLog (revision 25951) +++ ruby_1_9_1/ChangeLog (revision 25952) @@ -1,3 +1,8 @@ +Mon Sep 28 10:06:38 2009 NARUSE, Yui <naruse@r...> + + * stringio/stringio.c (strio_read): set ASCII-8BIT encoding + when length argument is given. + Sun Sep 27 13:06:43 2009 Tanaka Akira <akr@f...> * lib/pp.rb (PP:ObjectMixin#pretty_print): delegates has no inspect Index: ruby_1_9_1/ext/stringio/stringio.c =================================================================== --- ruby_1_9_1/ext/stringio/stringio.c (revision 25951) +++ ruby_1_9_1/ext/stringio/stringio.c (revision 25952) @@ -1137,7 +1137,7 @@ { struct StringIO *ptr = readable(StringIO(self)); VALUE str = Qnil; - long len, olen; + long len; switch (argc) { case 2: @@ -1146,7 +1146,7 @@ rb_str_modify(str); case 1: if (!NIL_P(argv[0])) { - len = olen = NUM2LONG(argv[0]); + len = NUM2LONG(argv[0]); if (len < 0) { rb_raise(rb_eArgError, "negative length %ld given", len); } @@ -1158,7 +1158,6 @@ } /* fall through */ case 0: - olen = -1; len = RSTRING_LEN(ptr->string); if (len <= ptr->pos) { if (NIL_P(str)) { @@ -1178,6 +1177,7 @@ } if (NIL_P(str)) { str = strio_substr(ptr, ptr->pos, len); + if (argc > 0) rb_enc_associate(str, rb_ascii8bit_encoding()); } else { long rest = RSTRING_LEN(ptr->string) - ptr->pos; Index: ruby_1_9_1/version.h =================================================================== --- ruby_1_9_1/version.h (revision 25951) +++ ruby_1_9_1/version.h (revision 25952) @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.1" -#define RUBY_PATCHLEVEL 353 +#define RUBY_PATCHLEVEL 354 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1 Index: ruby_1_9_1/test/stringio/test_stringio.rb =================================================================== --- ruby_1_9_1/test/stringio/test_stringio.rb (revision 25951) +++ ruby_1_9_1/test/stringio/test_stringio.rb (revision 25952) @@ -384,9 +384,12 @@ end def test_read - f = StringIO.new("1234") + f = StringIO.new("\u3042\u3044") assert_raise(ArgumentError) { f.read(-1) } assert_raise(ArgumentError) { f.read(1, 2, 3) } + assert_equal("\u3042\u3044", f.read) + f.rewind + assert_equal("\u3042\u3044".force_encoding(Encoding::ASCII_8BIT), f.read(f.size)) end def test_size -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/