mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* io.c (rb_io_initialize): don't accept IO object. [ruby-dev:35895]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18883 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f6f85ad683
commit
d05d66e2ac
3 changed files with 19 additions and 67 deletions
|
@ -1,3 +1,7 @@
|
|||
Thu Aug 28 00:07:59 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* io.c (rb_io_initialize): don't accept IO object. [ruby-dev:35895]
|
||||
|
||||
Wed Aug 27 23:28:51 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
|
||||
|
||||
* ext/win32ole/win32ole.c (ole_invoke): WIN32OLE#[] and WIN32OLE#[]=
|
||||
|
|
33
io.c
33
io.c
|
@ -5541,8 +5541,8 @@ rb_io_stdio_file(rb_io_t *fptr)
|
|||
static VALUE
|
||||
rb_io_initialize(int argc, VALUE *argv, VALUE io)
|
||||
{
|
||||
VALUE fnum, mode, orig;
|
||||
rb_io_t *fp, *ofp = NULL;
|
||||
VALUE fnum, mode;
|
||||
rb_io_t *fp;
|
||||
int fd, flags, modenum = O_RDONLY;
|
||||
convconfig_t convconfig;
|
||||
VALUE opt;
|
||||
|
@ -5552,8 +5552,7 @@ rb_io_initialize(int argc, VALUE *argv, VALUE io)
|
|||
opt = pop_last_hash(&argc, &argv);
|
||||
rb_scan_args(argc, argv, "11", &fnum, &mode);
|
||||
rb_io_extract_modeenc(&mode, opt, &modenum, &flags, &convconfig);
|
||||
orig = rb_io_check_io(fnum);
|
||||
if (NIL_P(orig)) {
|
||||
|
||||
fd = NUM2INT(fnum);
|
||||
UPDATE_MAXFD(fd);
|
||||
if (NIL_P(mode)) {
|
||||
|
@ -5569,32 +5568,6 @@ rb_io_initialize(int argc, VALUE *argv, VALUE io)
|
|||
fp->encs = convconfig;
|
||||
clear_codeconv(fp);
|
||||
io_check_tty(fp);
|
||||
}
|
||||
else if (RFILE(io)->fptr) {
|
||||
rb_raise(rb_eRuntimeError, "reinitializing IO");
|
||||
}
|
||||
else {
|
||||
GetOpenFile(orig, ofp);
|
||||
if (ofp->refcnt == LONG_MAX) {
|
||||
VALUE s = rb_inspect(orig);
|
||||
rb_raise(rb_eIOError, "too many shared IO for %s", StringValueCStr(s));
|
||||
}
|
||||
if (!NIL_P(mode)) {
|
||||
if ((ofp->mode ^ flags) & (FMODE_READWRITE|FMODE_BINMODE)) {
|
||||
if (TYPE(mode) != T_STRING) {
|
||||
rb_raise(rb_eArgError, "incompatible mode 0x%x", modenum);
|
||||
}
|
||||
else {
|
||||
rb_raise(rb_eArgError, "incompatible mode \"%s\"", RSTRING_PTR(mode));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (convconfig.enc || convconfig.enc2) {
|
||||
rb_raise(rb_eArgError, "encoding specified for shared IO");
|
||||
}
|
||||
ofp->refcnt++;
|
||||
RFILE(io)->fptr = ofp;
|
||||
}
|
||||
|
||||
return io;
|
||||
}
|
||||
|
|
|
@ -1189,31 +1189,6 @@ class TestIO < Test::Unit::TestCase
|
|||
|
||||
assert_equal("foo\nbar\nbaz\n", File.read(t.path))
|
||||
|
||||
with_pipe do |r, w|
|
||||
assert_raise(RuntimeError) do
|
||||
o = Object.new
|
||||
class << o; self; end.instance_eval do
|
||||
define_method(:to_io) { r }
|
||||
end
|
||||
w.instance_eval { initialize(o) }
|
||||
end
|
||||
end
|
||||
|
||||
pipe(proc do |w|
|
||||
w = IO.new(w)
|
||||
w.puts "foo"
|
||||
w.puts "bar"
|
||||
w.puts "baz"
|
||||
w.close
|
||||
end, proc do |r|
|
||||
r = IO.new(r)
|
||||
assert_equal("foo\nbar\nbaz\n", r.read)
|
||||
end)
|
||||
|
||||
with_pipe do |r, w|
|
||||
assert_raise(ArgumentError) { IO.new(r, "r+") }
|
||||
end
|
||||
|
||||
f = open(t.path)
|
||||
assert_raise(RuntimeError) do
|
||||
f.instance_eval { initialize }
|
||||
|
|
Loading…
Add table
Reference in a new issue