ruby-changes:49205
From: nobu <ko1@a...>
Date: Mon, 18 Dec 2017 16:15:13 +0900 (JST)
Subject: [ruby-changes:49205] nobu:r61320 (trunk): io.c: opening external command
nobu 2017-12-18 16:15:07 +0900 (Mon, 18 Dec 2017) New Revision: 61320 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61320 Log: io.c: opening external command * io.c (rb_io_open_generic): try to open the named file as usual, if klass is not IO nor File, so that Errno::ENOENT will be raised probably. calling on File will be same in the future. From: Nobuyoshi Nakada <nobu@r...> Modified files: trunk/io.c trunk/test/ruby/test_io.rb Index: test/ruby/test_io.rb =================================================================== --- test/ruby/test_io.rb (revision 61319) +++ test/ruby/test_io.rb (revision 61320) @@ -2185,16 +2185,17 @@ class TestIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L2185 end def test_read_command + assert_equal("foo\n", IO.read("|echo foo")) assert_warn(/invoke external command/) do File.read("|#{EnvUtil.rubybin} -e puts") end assert_warn(/invoke external command/) do File.binread("|#{EnvUtil.rubybin} -e puts") end - assert_raise_with_message(ArgumentError, /invoke external command/) do + assert_raise(Errno::ENOENT) do Class.new(IO).read("|#{EnvUtil.rubybin} -e puts") end - assert_raise_with_message(ArgumentError, /invoke external command/) do + assert_raise(Errno::ENOENT) do Class.new(IO).binread("|#{EnvUtil.rubybin} -e puts") end end Index: io.c =================================================================== --- io.c (revision 61319) +++ io.c (revision 61320) @@ -7088,17 +7088,11 @@ rb_io_open_generic(VALUE klass, VALUE fi https://github.com/ruby/ruby/blob/trunk/io.c#L7088 const convconfig_t *convconfig, mode_t perm) { VALUE cmd; - if (!NIL_P(cmd = check_pipe_command(filename))) { - if (klass != rb_cIO) { - ID func = rb_frame_this_func(); - VALUE fname = rb_id2str(func); - static const char MSG[] = "IO.%"PRIsVALUE" called on %"PRIsVALUE" to invoke external command"; - if (klass == rb_cFile) { - rb_warn(MSG, fname, klass); - } - else { - rb_raise(rb_eArgError, MSG, fname, klass); - } + const int warn = klass == rb_cFile; + if ((warn || klass == rb_cIO) && !NIL_P(cmd = check_pipe_command(filename))) { + if (warn) { + rb_warn("IO.%"PRIsVALUE" called on File to invoke external command", + rb_id2str(rb_frame_this_func())); } return pipe_open_s(cmd, rb_io_oflags_modestr(oflags), fmode, convconfig); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/