aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-27 15:09:47 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-27 15:09:47 +0000
commitd05d66e2acaa67840394b332359d6aa99bcc233a (patch)
treecd8bbc3342e66c1df28ecac97dd047567ab6cbdc
parentf6f85ad68309508e29f30d6cc4b86d0057aac2c0 (diff)
downloadruby-d05d66e2acaa67840394b332359d6aa99bcc233a.tar.gz
* 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
-rw-r--r--ChangeLog4
-rw-r--r--io.c57
-rw-r--r--test/ruby/test_io.rb25
3 files changed, 19 insertions, 67 deletions
diff --git a/ChangeLog b/ChangeLog
index c1a2c71340..891b992471 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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#[]=
diff --git a/io.c b/io.c
index b3ea394c61..08a4e4e859 100644
--- a/io.c
+++ b/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,49 +5552,22 @@ 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)) {
+
+ fd = NUM2INT(fnum);
+ UPDATE_MAXFD(fd);
+ if (NIL_P(mode)) {
#if defined(HAVE_FCNTL) && defined(F_GETFL)
- modenum = fcntl(fd, F_GETFL);
- if (modenum == -1) rb_sys_fail(0);
- flags = rb_io_modenum_flags(modenum);
+ modenum = fcntl(fd, F_GETFL);
+ if (modenum == -1) rb_sys_fail(0);
+ flags = rb_io_modenum_flags(modenum);
#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;
}
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index de1a1526eb..6b2dc3102d 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -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 }