ruby-changes:24989
From: nobu <ko1@a...>
Date: Fri, 28 Sep 2012 10:41:08 +0900 (JST)
Subject: [ruby-changes:24989] nobu:r37041 (trunk): io.c: IO#reopen int mode
nobu 2012-09-28 10:40:56 +0900 (Fri, 28 Sep 2012) New Revision: 37041 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37041 Log: io.c: IO#reopen int mode * io.c (rb_io_reopen): accept File::Constants as well as mode string. based on the patch by Glass_saga (Masaki Matsushita) in [ruby-core:47694]. [Feature #7067] Modified files: trunk/ChangeLog trunk/io.c trunk/test/ruby/test_io.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 37040) +++ ChangeLog (revision 37041) @@ -1,3 +1,9 @@ +Fri Sep 28 10:40:51 2012 Nobuyoshi Nakada <nobu@r...> + + * io.c (rb_io_reopen): accept File::Constants as well as mode string. + based on the patch by Glass_saga (Masaki Matsushita) in + [ruby-core:47694]. [Feature #7067] + Thu Sep 27 18:36:51 2012 Shugo Maeda <shugo@r...> * eval.c (rb_overlay_module, rb_mod_refine): accept a module as the Index: io.c =================================================================== --- io.c (revision 37040) +++ io.c (revision 37041) @@ -6365,7 +6365,17 @@ } if (!NIL_P(nmode)) { - int fmode = rb_io_modestr_fmode(StringValueCStr(nmode)); + VALUE intmode = rb_check_to_int(nmode); + int fmode; + + if (!NIL_P(intmode)) { + oflags = NUM2INT(intmode); + fmode = rb_io_oflags_fmode(oflags); + } + else { + fmode = rb_io_modestr_fmode(StringValueCStr(nmode)); + } + if (IS_PREP_STDIO(fptr) && ((fptr->mode & FMODE_READWRITE) & (fmode & FMODE_READWRITE)) != (fptr->mode & FMODE_READWRITE)) { @@ -6375,7 +6385,9 @@ rb_io_fmode_modestr(fmode)); } fptr->mode = fmode; - rb_io_mode_enc(fptr, StringValueCStr(nmode)); + if (NIL_P(intmode)) { + rb_io_mode_enc(fptr, StringValueCStr(nmode)); + } fptr->encs.ecflags = 0; fptr->encs.ecopts = Qnil; } Index: test/ruby/test_io.rb =================================================================== --- test/ruby/test_io.rb (revision 37040) +++ test/ruby/test_io.rb (revision 37041) @@ -1713,6 +1713,25 @@ } end + def test_reopen_mode + feature7067 = '[ruby-core:47694]' + make_tempfile {|t| + open(__FILE__) do |f| + assert_nothing_raised { + f.reopen(t.path, "r") + assert_equal("foo\n", f.gets) + } + end + + open(__FILE__) do |f| + assert_nothing_raised(feature7067) { + f.reopen(t.path, File::RDONLY) + assert_equal("foo\n", f.gets) + } + end + } + end + def test_foreach a = [] IO.foreach("|" + EnvUtil.rubybin + " -e 'puts :foo; puts :bar; puts :baz'") {|x| a << x } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/