timeout.rb: same object across fiber

* lib/timeout.rb (Timeout::ExitException.catch): do not freeze the
  exception for tag, so that the same object can be passed to the
  target fiber without duplication to attach backtrace at raise.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48467 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-11-17 03:42:49 +00:00
parent 0884d0b944
commit 1133596e6b

View File

@ -31,17 +31,16 @@ module Timeout
def self.catch(*args) def self.catch(*args)
exc = new(*args) exc = new(*args)
exc.instance_variable_set(:@thread, Thread.current) exc.instance_variable_set(:@thread, Thread.current)
exc.freeze
::Kernel.catch(exc) {yield exc} ::Kernel.catch(exc) {yield exc}
end end
def exception(*) def exception(*)
# TODO: use Fiber.current to see if self can be thrown
if self.thread == Thread.current if self.thread == Thread.current
bt = caller bt = caller
begin begin
throw(self, bt) throw(self, bt)
rescue UncaughtThrowError rescue UncaughtThrowError
raise Error, message, backtrace
end end
end end
self self