mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 08:33:58 +02:00
* io.c (rb_io_s_pipe): Close pipes if io_encoding_set() raises an
exception. (io_encoding_set_v): New function. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2ad2007307
commit
be4d1fd953
4 changed files with 115 additions and 65 deletions
|
@ -1087,13 +1087,17 @@ class TestIO < Test::Unit::TestCase
|
|||
|
||||
def test_dup
|
||||
ruby do |f|
|
||||
f2 = f.dup
|
||||
f.puts "foo"
|
||||
f2.puts "bar"
|
||||
f.close_write
|
||||
f2.close_write
|
||||
assert_equal("foo\nbar\n", f.read)
|
||||
assert_equal("", f2.read)
|
||||
begin
|
||||
f2 = f.dup
|
||||
f.puts "foo"
|
||||
f2.puts "bar"
|
||||
f.close_write
|
||||
f2.close_write
|
||||
assert_equal("foo\nbar\n", f.read)
|
||||
assert_equal("", f2.read)
|
||||
ensure
|
||||
f2.close
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1396,18 +1400,22 @@ class TestIO < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_pid
|
||||
r, w = IO.pipe
|
||||
assert_equal(nil, r.pid)
|
||||
assert_equal(nil, w.pid)
|
||||
IO.pipe {|r, w|
|
||||
assert_equal(nil, r.pid)
|
||||
assert_equal(nil, w.pid)
|
||||
}
|
||||
|
||||
pipe = IO.popen(EnvUtil.rubybin, "r+")
|
||||
pid1 = pipe.pid
|
||||
pipe.puts "p $$"
|
||||
pipe.close_write
|
||||
pid2 = pipe.read.chomp.to_i
|
||||
assert_equal(pid2, pid1)
|
||||
assert_equal(pid2, pipe.pid)
|
||||
pipe.close
|
||||
begin
|
||||
pipe = IO.popen(EnvUtil.rubybin, "r+")
|
||||
pid1 = pipe.pid
|
||||
pipe.puts "p $$"
|
||||
pipe.close_write
|
||||
pid2 = pipe.read.chomp.to_i
|
||||
assert_equal(pid2, pid1)
|
||||
assert_equal(pid2, pipe.pid)
|
||||
ensure
|
||||
pipe.close
|
||||
end
|
||||
assert_raise(IOError) { pipe.pid }
|
||||
end
|
||||
|
||||
|
@ -2382,6 +2390,7 @@ End
|
|||
t.close
|
||||
1.times do
|
||||
io = open(path,"w")
|
||||
io.instance_variable_set(:@test_flush_in_finalizer2, true)
|
||||
io.print "hoge"
|
||||
end
|
||||
assert_nothing_raised(TypeError, bug3910) do
|
||||
|
@ -2389,6 +2398,12 @@ End
|
|||
end
|
||||
t.close!
|
||||
}
|
||||
ensure
|
||||
ObjectSpace.each_object(File) {|f|
|
||||
if f.instance_variables.include?(:@test_flush_in_finalizer2)
|
||||
f.close
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_readlines_limit_0
|
||||
|
@ -2999,41 +3014,41 @@ End
|
|||
bug8669 = '[ruby-core:56121] [Bug #8669]'
|
||||
|
||||
str = ""
|
||||
r, = IO.pipe
|
||||
t = Thread.new { r.read(nil, str) }
|
||||
sleep 0.1 until t.stop?
|
||||
t.raise
|
||||
sleep 0.1 while t.alive?
|
||||
assert_nothing_raised(RuntimeError, bug8669) { str.clear }
|
||||
ensure
|
||||
t.kill
|
||||
IO.pipe {|r,|
|
||||
t = Thread.new { r.read(nil, str) }
|
||||
sleep 0.1 until t.stop?
|
||||
t.raise
|
||||
sleep 0.1 while t.alive?
|
||||
assert_nothing_raised(RuntimeError, bug8669) { str.clear }
|
||||
assert_raise(RuntimeError) { t.join }
|
||||
}
|
||||
end
|
||||
|
||||
def test_readpartial_unlocktmp_ensure
|
||||
bug8669 = '[ruby-core:56121] [Bug #8669]'
|
||||
|
||||
str = ""
|
||||
r, = IO.pipe
|
||||
t = Thread.new { r.readpartial(4096, str) }
|
||||
sleep 0.1 until t.stop?
|
||||
t.raise
|
||||
sleep 0.1 while t.alive?
|
||||
assert_nothing_raised(RuntimeError, bug8669) { str.clear }
|
||||
ensure
|
||||
t.kill
|
||||
IO.pipe {|r, w|
|
||||
t = Thread.new { r.readpartial(4096, str) }
|
||||
sleep 0.1 until t.stop?
|
||||
t.raise
|
||||
sleep 0.1 while t.alive?
|
||||
assert_nothing_raised(RuntimeError, bug8669) { str.clear }
|
||||
assert_raise(RuntimeError) { t.join }
|
||||
}
|
||||
end
|
||||
|
||||
def test_sysread_unlocktmp_ensure
|
||||
bug8669 = '[ruby-core:56121] [Bug #8669]'
|
||||
|
||||
str = ""
|
||||
r, = IO.pipe
|
||||
t = Thread.new { r.sysread(4096, str) }
|
||||
sleep 0.1 until t.stop?
|
||||
t.raise
|
||||
sleep 0.1 while t.alive?
|
||||
assert_nothing_raised(RuntimeError, bug8669) { str.clear }
|
||||
ensure
|
||||
t.kill
|
||||
IO.pipe {|r, w|
|
||||
t = Thread.new { r.sysread(4096, str) }
|
||||
sleep 0.1 until t.stop?
|
||||
t.raise
|
||||
sleep 0.1 while t.alive?
|
||||
assert_nothing_raised(RuntimeError, bug8669) { str.clear }
|
||||
assert_raise(RuntimeError) { t.join }
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2142,32 +2142,34 @@ EOT
|
|||
|
||||
def test_textmode_paragraph_nonasciicompat
|
||||
bug3534 = ['[ruby-dev:41803]', '[Bug #3534]']
|
||||
r, w = IO.pipe
|
||||
[Encoding::UTF_32BE, Encoding::UTF_32LE,
|
||||
Encoding::UTF_16BE, Encoding::UTF_16LE,
|
||||
Encoding::UTF_8].each do |e|
|
||||
r.set_encoding(Encoding::US_ASCII, e)
|
||||
wthr = Thread.new{ w.print(bug3534[0], "\n\n\n\n", bug3534[1], "\n") }
|
||||
assert_equal((bug3534[0]+"\n\n").encode(e), r.gets(""), bug3534[0])
|
||||
assert_equal((bug3534[1]+"\n").encode(e), r.gets(), bug3534[1])
|
||||
wthr.join
|
||||
end
|
||||
IO.pipe {|r, w|
|
||||
[Encoding::UTF_32BE, Encoding::UTF_32LE,
|
||||
Encoding::UTF_16BE, Encoding::UTF_16LE,
|
||||
Encoding::UTF_8].each do |e|
|
||||
r.set_encoding(Encoding::US_ASCII, e)
|
||||
wthr = Thread.new{ w.print(bug3534[0], "\n\n\n\n", bug3534[1], "\n") }
|
||||
assert_equal((bug3534[0]+"\n\n").encode(e), r.gets(""), bug3534[0])
|
||||
assert_equal((bug3534[1]+"\n").encode(e), r.gets(), bug3534[1])
|
||||
wthr.join
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_binmode_paragraph_nonasciicompat
|
||||
bug3534 = ['[ruby-dev:41803]', '[Bug #3534]']
|
||||
r, w = IO.pipe
|
||||
r.binmode
|
||||
w.binmode
|
||||
[Encoding::UTF_32BE, Encoding::UTF_32LE,
|
||||
Encoding::UTF_16BE, Encoding::UTF_16LE,
|
||||
Encoding::UTF_8].each do |e|
|
||||
r.set_encoding(Encoding::US_ASCII, e)
|
||||
wthr = Thread.new{ w.print(bug3534[0], "\n\n\n\n", bug3534[1], "\n") }
|
||||
assert_equal((bug3534[0]+"\n\n").encode(e), r.gets(""), bug3534[0])
|
||||
assert_equal((bug3534[1]+"\n").encode(e), r.gets(), bug3534[1])
|
||||
wthr.join
|
||||
end
|
||||
IO.pipe {|r, w|
|
||||
r.binmode
|
||||
w.binmode
|
||||
[Encoding::UTF_32BE, Encoding::UTF_32LE,
|
||||
Encoding::UTF_16BE, Encoding::UTF_16LE,
|
||||
Encoding::UTF_8].each do |e|
|
||||
r.set_encoding(Encoding::US_ASCII, e)
|
||||
wthr = Thread.new{ w.print(bug3534[0], "\n\n\n\n", bug3534[1], "\n") }
|
||||
assert_equal((bug3534[0]+"\n\n").encode(e), r.gets(""), bug3534[0])
|
||||
assert_equal((bug3534[1]+"\n").encode(e), r.gets(), bug3534[1])
|
||||
wthr.join
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_puts_widechar
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue