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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8940e37210
commit
4a3c049cd1
@ -1,3 +1,9 @@
|
||||
Fri Sep 28 10:40:51 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* 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@ruby-lang.org>
|
||||
|
||||
* eval.c (rb_overlay_module, rb_mod_refine): accept a module as the
|
||||
|
16
io.c
16
io.c
@ -6365,7 +6365,17 @@ rb_io_reopen(int argc, VALUE *argv, VALUE file)
|
||||
}
|
||||
|
||||
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_reopen(int argc, VALUE *argv, VALUE file)
|
||||
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;
|
||||
}
|
||||
|
@ -1713,6 +1713,25 @@ End
|
||||
}
|
||||
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 }
|
||||
|
Loading…
x
Reference in New Issue
Block a user