io.c: try to_io first
* io.c (copy_stream_body): try to_io conversion before read, readpartial, and write methods. [ruby-dev:49008] [Bug #11199] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52750 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
012368007f
commit
7d92e5cf73
@ -1,3 +1,8 @@
|
|||||||
|
Wed Nov 25 21:23:39 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* io.c (copy_stream_body): try to_io conversion before read,
|
||||||
|
readpartial, and write methods. [ruby-dev:49008] [Bug #11199]
|
||||||
|
|
||||||
Wed Nov 25 10:55:21 2015 Shugo Maeda <shugo@ruby-lang.org>
|
Wed Nov 25 10:55:21 2015 Shugo Maeda <shugo@ruby-lang.org>
|
||||||
|
|
||||||
* io.c (argf_getpartial): should not resize str if the second
|
* io.c (argf_getpartial): should not resize str if the second
|
||||||
|
75
io.c
75
io.c
@ -10573,54 +10573,57 @@ copy_stream_body(VALUE arg)
|
|||||||
|
|
||||||
stp->total = 0;
|
stp->total = 0;
|
||||||
|
|
||||||
if (src_io == argf) {
|
if (src_io == argf ||
|
||||||
src_fd = -1;
|
!(RB_TYPE_P(src_io, T_FILE) ||
|
||||||
}
|
RB_TYPE_P(src_io, T_STRING) ||
|
||||||
else if (RB_TYPE_P(src_io, T_FILE)) {
|
rb_respond_to(src_io, rb_intern("to_path")))) {
|
||||||
goto io_src;
|
|
||||||
}
|
|
||||||
else if (!RB_TYPE_P(src_io, T_STRING) &&
|
|
||||||
(rb_respond_to(src_io, id_read) ||
|
|
||||||
rb_respond_to(src_io, id_readpartial))) {
|
|
||||||
src_fd = -1;
|
src_fd = -1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VALUE args[2];
|
VALUE tmp_io = rb_io_check_io(src_io);
|
||||||
FilePathValue(src_io);
|
if (!NIL_P(tmp_io)) {
|
||||||
args[0] = src_io;
|
src_io = tmp_io;
|
||||||
args[1] = INT2NUM(O_RDONLY|common_oflags);
|
}
|
||||||
src_io = rb_class_new_instance(2, args, rb_cFile);
|
else if (!RB_TYPE_P(src_io, T_FILE)) {
|
||||||
stp->src = src_io;
|
VALUE args[2];
|
||||||
stp->close_src = 1;
|
FilePathValue(src_io);
|
||||||
io_src:
|
args[0] = src_io;
|
||||||
|
args[1] = INT2NUM(O_RDONLY|common_oflags);
|
||||||
|
src_io = rb_class_new_instance(2, args, rb_cFile);
|
||||||
|
stp->src = src_io;
|
||||||
|
stp->close_src = 1;
|
||||||
|
}
|
||||||
GetOpenFile(src_io, src_fptr);
|
GetOpenFile(src_io, src_fptr);
|
||||||
rb_io_check_byte_readable(src_fptr);
|
rb_io_check_byte_readable(src_fptr);
|
||||||
src_fd = src_fptr->fd;
|
src_fd = src_fptr->fd;
|
||||||
}
|
}
|
||||||
stp->src_fd = src_fd;
|
stp->src_fd = src_fd;
|
||||||
|
|
||||||
if (dst_io == argf) {
|
if (dst_io == argf ||
|
||||||
dst_fd = -1;
|
!(RB_TYPE_P(dst_io, T_FILE) ||
|
||||||
}
|
RB_TYPE_P(dst_io, T_STRING) ||
|
||||||
else if (RB_TYPE_P(dst_io, T_FILE)) {
|
rb_respond_to(dst_io, rb_intern("to_path")))) {
|
||||||
dst_io = GetWriteIO(dst_io);
|
|
||||||
stp->dst = dst_io;
|
|
||||||
goto io_dst;
|
|
||||||
}
|
|
||||||
else if (!RB_TYPE_P(dst_io, T_STRING) &&
|
|
||||||
rb_respond_to(dst_io, id_write)) {
|
|
||||||
dst_fd = -1;
|
dst_fd = -1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VALUE args[3];
|
VALUE tmp_io = rb_io_check_io(dst_io);
|
||||||
FilePathValue(dst_io);
|
if (!NIL_P(tmp_io)) {
|
||||||
args[0] = dst_io;
|
dst_io = tmp_io;
|
||||||
args[1] = INT2NUM(O_WRONLY|O_CREAT|O_TRUNC|common_oflags);
|
}
|
||||||
args[2] = INT2FIX(0666);
|
else if (!RB_TYPE_P(dst_io, T_FILE)) {
|
||||||
dst_io = rb_class_new_instance(3, args, rb_cFile);
|
VALUE args[3];
|
||||||
stp->dst = dst_io;
|
FilePathValue(dst_io);
|
||||||
stp->close_dst = 1;
|
args[0] = dst_io;
|
||||||
io_dst:
|
args[1] = INT2NUM(O_WRONLY|O_CREAT|O_TRUNC|common_oflags);
|
||||||
|
args[2] = INT2FIX(0666);
|
||||||
|
dst_io = rb_class_new_instance(3, args, rb_cFile);
|
||||||
|
stp->dst = dst_io;
|
||||||
|
stp->close_dst = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dst_io = GetWriteIO(dst_io);
|
||||||
|
stp->dst = dst_io;
|
||||||
|
}
|
||||||
GetOpenFile(dst_io, dst_fptr);
|
GetOpenFile(dst_io, dst_fptr);
|
||||||
rb_io_check_writable(dst_fptr);
|
rb_io_check_writable(dst_fptr);
|
||||||
dst_fd = dst_fptr->fd;
|
dst_fd = dst_fptr->fd;
|
||||||
|
@ -3,6 +3,7 @@ require 'test/unit'
|
|||||||
require 'tmpdir'
|
require 'tmpdir'
|
||||||
require "fcntl"
|
require "fcntl"
|
||||||
require 'io/nonblock'
|
require 'io/nonblock'
|
||||||
|
require 'pathname'
|
||||||
require 'socket'
|
require 'socket'
|
||||||
require 'stringio'
|
require 'stringio'
|
||||||
require 'timeout'
|
require 'timeout'
|
||||||
@ -888,6 +889,17 @@ class TestIO < Test::Unit::TestCase
|
|||||||
dst.close!
|
dst.close!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_copy_stream_pathname_to_pathname
|
||||||
|
bug11199 = '[ruby-dev:49008] [Bug #11199]'
|
||||||
|
mkcdtmpdir {
|
||||||
|
File.open("src", "w") {|f| f << "ok" }
|
||||||
|
src = Pathname.new("src")
|
||||||
|
dst = Pathname.new("dst")
|
||||||
|
IO.copy_stream(src, dst)
|
||||||
|
assert_equal("ok", IO.read("dst"), bug11199)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def test_copy_stream_write_in_binmode
|
def test_copy_stream_write_in_binmode
|
||||||
bug8767 = '[ruby-core:56518] [Bug #8767]'
|
bug8767 = '[ruby-core:56518] [Bug #8767]'
|
||||||
mkcdtmpdir {
|
mkcdtmpdir {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user