ruby-changes:19752
From: yugui <ko1@a...>
Date: Mon, 30 May 2011 07:53:48 +0900 (JST)
Subject: [ruby-changes:19752] yugui:r31797 (ruby_1_9_2): merges r31248 from trunk into ruby_1_9_2.
yugui 2011-05-30 07:49:19 +0900 (Mon, 30 May 2011) New Revision: 31797 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31797 Log: merges r31248 from trunk into ruby_1_9_2. -- * ext/stringio/stringio.c (strio_getline): check whether str is a string when str and lim are given. https://twitter.com/watson1978/status/56225052152168449 Modified files: branches/ruby_1_9_2/ChangeLog branches/ruby_1_9_2/ext/stringio/stringio.c branches/ruby_1_9_2/test/stringio/test_stringio.rb branches/ruby_1_9_2/version.h Index: ruby_1_9_2/ChangeLog =================================================================== --- ruby_1_9_2/ChangeLog (revision 31796) +++ ruby_1_9_2/ChangeLog (revision 31797) @@ -1,3 +1,9 @@ +Fri Apr 8 16:01:56 2011 NARUSE, Yui <naruse@r...> + + * ext/stringio/stringio.c (strio_getline): check whether str is + a string when str and lim are given. + https://twitter.com/watson1978/status/56225052152168449 + Wed Apr 6 15:12:40 2011 NARUSE, Yui <naruse@r...> * ext/openssl/ossl_pkey_dh.c (ossl_dh_initialize): Index: ruby_1_9_2/ext/stringio/stringio.c =================================================================== --- ruby_1_9_2/ext/stringio/stringio.c (revision 31796) +++ ruby_1_9_2/ext/stringio/stringio.c (revision 31797) @@ -919,18 +919,17 @@ { const char *s, *e, *p; long n, limit = 0; - VALUE str; + VALUE str, lim; - if (argc == 0) { + rb_scan_args(argc, argv, "02", &str, &lim); + switch (argc) { + case 0: str = rb_rs; - } - else { - VALUE lim, tmp; + break; - rb_scan_args(argc, argv, "11", &str, &lim); - if (!NIL_P(lim)) limit = NUM2LONG(lim); - else if (!NIL_P(str) && TYPE(str) != T_STRING) { - tmp = rb_check_string_type(str); + case 1: + if (!NIL_P(str) && TYPE(str) != T_STRING) { + VALUE tmp = rb_check_string_type(str); if (NIL_P(tmp)) { limit = NUM2LONG(str); if (limit == 0) return rb_str_new(0,0); @@ -940,9 +939,12 @@ str = tmp; } } - else if (!NIL_P(str)) { - StringValue(str); - } + break; + + case 2: + if (!NIL_P(str)) StringValue(str); + limit = NUM2LONG(lim); + break; } if (ptr->pos >= (n = RSTRING_LEN(ptr->string))) { Index: ruby_1_9_2/version.h =================================================================== --- ruby_1_9_2/version.h (revision 31796) +++ ruby_1_9_2/version.h (revision 31797) @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.2" -#define RUBY_PATCHLEVEL 224 +#define RUBY_PATCHLEVEL 225 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1 Index: ruby_1_9_2/test/stringio/test_stringio.rb =================================================================== --- ruby_1_9_2/test/stringio/test_stringio.rb (revision 31796) +++ ruby_1_9_2/test/stringio/test_stringio.rb (revision 31797) @@ -51,6 +51,8 @@ assert_equal("abc\n", StringIO.new("abc\n\ndef\n").gets) assert_equal("abc\n\ndef\n", StringIO.new("abc\n\ndef\n").gets(nil)) assert_equal("abc\n\n", StringIO.new("abc\n\ndef\n").gets("")) + assert_raise(TypeError){StringIO.new("").gets(1, 1)} + assert_raise(TypeError){StringIO.new("").gets(nil, nil)} end def test_readlines -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/