[前][次][番号順一覧][スレッド一覧]

ruby-changes:5649

From: shyouhei <ko1@a...>
Date: Sat, 14 Jun 2008 16:46:45 +0900 (JST)
Subject: [ruby-changes:5649] Ruby:r17156 (ruby_1_8_5): merge revision(s) 15464:

shyouhei	2008-06-14 16:46:36 +0900 (Sat, 14 Jun 2008)

  New Revision: 17156

  Modified files:
    branches/ruby_1_8_5/ChangeLog
    branches/ruby_1_8_5/lib/timeout.rb
    branches/ruby_1_8_5/version.h

  Log:
    merge revision(s) 15464:
    * lib/timeout.rb (Timeout::timeout): made sensitive to location on the
      stack.  [ruby-core:15458]


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_5/lib/timeout.rb?r1=17156&r2=17155&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_5/version.h?r1=17156&r2=17155&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_5/ChangeLog?r1=17156&r2=17155&diff_format=u

Index: ruby_1_8_5/ChangeLog
===================================================================
--- ruby_1_8_5/ChangeLog	(revision 17155)
+++ ruby_1_8_5/ChangeLog	(revision 17156)
@@ -1,3 +1,8 @@
+Sat Jun 14 16:12:17 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/timeout.rb (Timeout::timeout): made sensitive to location on the
+	  stack.  [ruby-core:15458]
+
 Fri Jun 13 13:10:12 2008  Yukihiro Matsumoto  <matz@r...>
 
 	* ext/dl/ptr.c (dlmem_each_i): typo fixed.  a patch from IKOMA
Index: ruby_1_8_5/version.h
===================================================================
--- ruby_1_8_5/version.h	(revision 17155)
+++ ruby_1_8_5/version.h	(revision 17156)
@@ -1,15 +1,15 @@
 #define RUBY_VERSION "1.8.5"
-#define RUBY_RELEASE_DATE "2008-06-13"
+#define RUBY_RELEASE_DATE "2008-06-14"
 #define RUBY_VERSION_CODE 185
-#define RUBY_RELEASE_CODE 20080613
-#define RUBY_PATCHLEVEL 174
+#define RUBY_RELEASE_CODE 20080614
+#define RUBY_PATCHLEVEL 175
 
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 8
 #define RUBY_VERSION_TEENY 5
 #define RUBY_RELEASE_YEAR 2008
 #define RUBY_RELEASE_MONTH 6
-#define RUBY_RELEASE_DAY 13
+#define RUBY_RELEASE_DAY 14
 
 #ifdef RUBY_EXTERN
 RUBY_EXTERN const char ruby_version[];
Index: ruby_1_8_5/lib/timeout.rb
===================================================================
--- ruby_1_8_5/lib/timeout.rb	(revision 17155)
+++ ruby_1_8_5/lib/timeout.rb	(revision 17156)
@@ -32,9 +32,14 @@
   ##
   # Raised by Timeout#timeout when the block times out.
 
-  class Error<Interrupt
+  class Error < Interrupt
   end
+  class ExitException < ::Exception # :nodoc:
+  end
 
+  THIS_FILE = /\A#{Regexp.quote(__FILE__)}:/o
+  CALLER_OFFSET = ((c = caller[0]) && THIS_FILE =~ c) ? 1 : 0
+
   ##
   # Executes the method's block. If the block execution terminates before +sec+
   # seconds has passed, it returns true. If not, it terminates the execution
@@ -44,9 +49,10 @@
   # Timeout' into your classes so they have a #timeout method, as well as a
   # module method, so you can call it directly as Timeout.timeout().
 
-  def timeout(sec, exception=Error)
+  def timeout(sec, klass = nil)
     return yield if sec == nil or sec.zero?
     raise ThreadError, "timeout within critical session" if Thread.critical
+    exception = klass || Class.new(ExitException)
     begin
       x = Thread.current
       y = Thread.start {
@@ -55,6 +61,17 @@
       }
       yield sec
       #    return true
+    rescue exception => e
+      rej = /\A#{Regexp.quote(__FILE__)}:#{__LINE__-4}\z/o
+      (bt = e.backtrace).reject! {|m| rej =~ m}
+      level = -caller(CALLER_OFFSET).size
+      while THIS_FILE =~ bt[level]
+        bt.delete_at(level)
+        level += 1
+      end
+      raise if klass            # if exception class is specified, it
+                                # would be expected outside.
+      raise Error, e.message, e.backtrace
     ensure
       y.kill if y and y.alive?
     end
@@ -72,7 +89,7 @@
 # Defined for backwards compatibility with earlier versions of timeout.rb, see
 # Timeout#timeout.
 
-def timeout(n, e=Timeout::Error, &block) # :nodoc:
+def timeout(n, e = nil, &block) # :nodoc:
   Timeout::timeout(n, e, &block)
 end
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]