ruby-changes:26796
From: nobu <ko1@a...>
Date: Wed, 16 Jan 2013 18:45:59 +0900 (JST)
Subject: [ruby-changes:26796] nobu:r38848 (trunk): win32ole.rb: use TracePoint
nobu 2013-01-16 18:45:48 +0900 (Wed, 16 Jan 2013) New Revision: 38848 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38848 Log: win32ole.rb: use TracePoint * ext/win32ole/lib/win32ole.rb: use TracePoint to hook all thread creation not only by Thread.new and to get rid of interference with svar scope. [Bug #7681] [ruby-core:51365] Modified files: trunk/ChangeLog trunk/ext/win32ole/lib/win32ole.rb trunk/test/win32ole/test_thread.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 38847) +++ ChangeLog (revision 38848) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Jan 16 18:45:46 2013 Nobuyoshi Nakada <nobu@r...> + + * ext/win32ole/lib/win32ole.rb: use TracePoint to hook all thread + creation not only by Thread.new and to get rid of interference with + svar scope. [Bug #7681] [ruby-core:51365] + Wed Jan 16 09:35:53 2013 Eric Hodel <drbrain@s...> * .document: Removed extra space Index: ext/win32ole/lib/win32ole.rb =================================================================== --- ext/win32ole/lib/win32ole.rb (revision 38847) +++ ext/win32ole/lib/win32ole.rb (revision 38848) @@ -3,20 +3,5 @@ require 'win32ole.so' https://github.com/ruby/ruby/blob/trunk/ext/win32ole/lib/win32ole.rb#L3 # re-define Thread#initialize # bug #2618(ruby-core:27634) -class Thread - alias :org_initialize :initialize - def initialize(*arg, &block) - if block - org_initialize(*arg) { - WIN32OLE.ole_initialize - begin - block.call(*arg) - ensure - WIN32OLE.ole_uninitialize - end - } - else - org_initialize(*arg) - end - end -end +TracePoint.trace(:thread_begin) {WIN32OLE.ole_initialize} +TracePoint.trace(:thread_end) {WIN32OLE.ole_uninitialize} Index: test/win32ole/test_thread.rb =================================================================== --- test/win32ole/test_thread.rb (revision 38847) +++ test/win32ole/test_thread.rb (revision 38848) @@ -9,12 +9,25 @@ if defined?(WIN32OLE) https://github.com/ruby/ruby/blob/trunk/test/win32ole/test_thread.rb#L9 # # test for Bug #2618(ruby-core:27634) # - def test_creating_win32ole_object_in_thread - t = Thread.new do - dict = WIN32OLE.new('Scripting.Dictionary') - assert(true) - end - t.join + def assert_creating_win32ole_object_in_thread(meth) + t = Thread.__send__(meth) { + WIN32OLE.new('Scripting.Dictionary') + } + assert_nothing_raised(WIN32OLERuntimeError, "[Bug #2618] Thread.#{meth}") { + t.join + } + end + + def test_creating_win32ole_object_in_thread_new + assert_creating_win32ole_object_in_thread(:new) + end + + def test_creating_win32ole_object_in_thread_start + assert_creating_win32ole_object_in_thread(:start) + end + + def test_creating_win32ole_object_in_thread_fork + assert_creating_win32ole_object_in_thread(:fork) end end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/