ruby-changes:64543
From: Yusuke <ko1@a...>
Date: Thu, 24 Dec 2020 14:34:54 +0900 (JST)
Subject: [ruby-changes:64543] 8e1c0b2f93 (master): dir.c: chdir conflict should raise only when called in different thread
https://git.ruby-lang.org/ruby.git/commit/?id=8e1c0b2f93 From 8e1c0b2f93abe23f42bd7eba0a3f0d3f3669e486 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh <mame@r...> Date: Thu, 24 Dec 2020 13:43:22 +0900 Subject: dir.c: chdir conflict should raise only when called in different thread ... and keep it as a warning (like 2.7) when it is called in the same thread. [Bug #15661] diff --git a/dir.c b/dir.c index 49e6818..bedbdd9 100644 --- a/dir.c +++ b/dir.c @@ -1064,8 +1064,10 @@ dir_s_chdir(int argc, VALUE *argv, VALUE obj) https://github.com/ruby/ruby/blob/trunk/dir.c#L1064 } if (chdir_blocking > 0) { - if (!rb_block_given_p() || rb_thread_current() != chdir_thread) + if (rb_thread_current() != chdir_thread) rb_raise(rb_eRuntimeError, "conflicting chdir during another chdir block"); + if (!rb_block_given_p()) + rb_warn("conflicting chdir during another chdir block"); } if (rb_block_given_p()) { diff --git a/test/ruby/test_dir.rb b/test/ruby/test_dir.rb index fb8d009..e5bcbea 100644 --- a/test/ruby/test_dir.rb +++ b/test/ruby/test_dir.rb @@ -97,9 +97,22 @@ class TestDir < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_dir.rb#L97 assert_raise(ArgumentError) { Dir.chdir } ENV["HOME"] = pwd Dir.chdir do - assert_equal(pwd, Dir.pwd) - assert_raise(RuntimeError) { Dir.chdir(@root) } - assert_equal(pwd, Dir.pwd) + assert_warning(/conflicting chdir during another chdir block/) { Dir.chdir(pwd) } + + assert_warning(/conflicting chdir during another chdir block/) { Dir.chdir(@root) } + assert_equal(@root, Dir.pwd) + + assert_warning(/conflicting chdir during another chdir block/) { Dir.chdir(pwd) } + + assert_raise(RuntimeError) { Thread.new { Thread.current.report_on_exception = false; Dir.chdir(@root) }.join } + assert_raise(RuntimeError) { Thread.new { Thread.current.report_on_exception = false; Dir.chdir(@root) { } }.join } + + assert_warning(/conflicting chdir during another chdir block/) { Dir.chdir(pwd) } + + assert_warning(/conflicting chdir during another chdir block/) { Dir.chdir(@root) } + assert_equal(@root, Dir.pwd) + + assert_warning(/conflicting chdir during another chdir block/) { Dir.chdir(pwd) } Dir.chdir(@root) do assert_equal(@root, Dir.pwd) end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/