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>
|
Wed Aug 27 23:28:51 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
|
||||||
|
|
||||||
* ext/win32ole/win32ole.c (ole_invoke): WIN32OLE#[] and WIN32OLE#[]=
|
* ext/win32ole/win32ole.c (ole_invoke): WIN32OLE#[] and WIN32OLE#[]=
|
||||||
|
|
57
io.c
57
io.c
|
@ -5541,8 +5541,8 @@ rb_io_stdio_file(rb_io_t *fptr)
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_io_initialize(int argc, VALUE *argv, VALUE io)
|
rb_io_initialize(int argc, VALUE *argv, VALUE io)
|
||||||
{
|
{
|
||||||
VALUE fnum, mode, orig;
|
VALUE fnum, mode;
|
||||||
rb_io_t *fp, *ofp = NULL;
|
rb_io_t *fp;
|
||||||
int fd, flags, modenum = O_RDONLY;
|
int fd, flags, modenum = O_RDONLY;
|
||||||
convconfig_t convconfig;
|
convconfig_t convconfig;
|
||||||
VALUE opt;
|
VALUE opt;
|
||||||
|
@ -5552,49 +5552,22 @@ rb_io_initialize(int argc, VALUE *argv, VALUE io)
|
||||||
opt = pop_last_hash(&argc, &argv);
|
opt = pop_last_hash(&argc, &argv);
|
||||||
rb_scan_args(argc, argv, "11", &fnum, &mode);
|
rb_scan_args(argc, argv, "11", &fnum, &mode);
|
||||||
rb_io_extract_modeenc(&mode, opt, &modenum, &flags, &convconfig);
|
rb_io_extract_modeenc(&mode, opt, &modenum, &flags, &convconfig);
|
||||||
orig = rb_io_check_io(fnum);
|
|
||||||
if (NIL_P(orig)) {
|
fd = NUM2INT(fnum);
|
||||||
fd = NUM2INT(fnum);
|
UPDATE_MAXFD(fd);
|
||||||
UPDATE_MAXFD(fd);
|
if (NIL_P(mode)) {
|
||||||
if (NIL_P(mode)) {
|
|
||||||
#if defined(HAVE_FCNTL) && defined(F_GETFL)
|
#if defined(HAVE_FCNTL) && defined(F_GETFL)
|
||||||
modenum = fcntl(fd, F_GETFL);
|
modenum = fcntl(fd, F_GETFL);
|
||||||
if (modenum == -1) rb_sys_fail(0);
|
if (modenum == -1) rb_sys_fail(0);
|
||||||
flags = rb_io_modenum_flags(modenum);
|
flags = rb_io_modenum_flags(modenum);
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
MakeOpenFile(io, fp);
|
|
||||||
fp->fd = fd;
|
|
||||||
fp->mode = flags;
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
MakeOpenFile(io, fp);
|
||||||
|
fp->fd = fd;
|
||||||
|
fp->mode = flags;
|
||||||
|
fp->encs = convconfig;
|
||||||
|
clear_codeconv(fp);
|
||||||
|
io_check_tty(fp);
|
||||||
|
|
||||||
return io;
|
return io;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1189,31 +1189,6 @@ class TestIO < Test::Unit::TestCase
|
||||||
|
|
||||||
assert_equal("foo\nbar\nbaz\n", File.read(t.path))
|
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)
|
f = open(t.path)
|
||||||
assert_raise(RuntimeError) do
|
assert_raise(RuntimeError) do
|
||||||
f.instance_eval { initialize }
|
f.instance_eval { initialize }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue