From 06d9340f2e1491697625afbf1fe94137e252319c Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 21 Oct 2003 14:42:15 +0000 Subject: * eval.c (ruby_cleanup): call finalizers and exit procs before terminating threads. * eval.c (ruby_cleanup): preserve ruby_errinfo before ruby_finalize_0(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 ++ eval.c | 33 ++-- file.c | 2 +- test/drb/test_drb.rb | 376 +++++---------------------------------------- test/drb/test_drbssl.rb | 65 ++++---- test/drb/test_drbunix.rb | 31 ++-- test/drb/ut_drb.rb | 1 - test/drb/ut_drb_drbssl.rb | 2 +- test/drb/ut_drb_drbunix.rb | 2 +- 9 files changed, 117 insertions(+), 406 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8f432455a2..5fbd7ef384 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Tue Oct 21 23:16:26 2003 Yukihiro Matsumoto + + * eval.c (ruby_cleanup): call finalizers and exit procs before + terminating threads. + + * eval.c (ruby_cleanup): preserve ruby_errinfo before ruby_finalize_0(). + Tue Oct 21 15:57:11 2003 Nobuyoshi Nakada * lib/test/unit/collector/dir.rb (Test::Unit::Collector::Dir#collect_file): @@ -352,6 +359,10 @@ Sun Oct 12 14:45:03 2003 WATANABE Hirofumi * ext/win32ole/extconf.rb: check "windows.h", not "windows". [ruby-talk:84051] +Sat Oct 11 20:41:03 2003 Corinna Vinschen + + * file.c (eaccess): Use access(2) on Cygwin. + Sat Oct 11 17:09:21 2003 WATANABE Hirofumi * lib/rexml/quickpath.rb (REXML::QuickPath::match): diff --git a/eval.c b/eval.c index ac8762bc8f..70061e5fb9 100644 --- a/eval.c +++ b/eval.c @@ -1311,9 +1311,8 @@ ruby_options(argc, argv) void rb_exec_end_proc _((void)); -static int -ruby_finalize_0(ex) - int ex; +static void +ruby_finalize_0() { ruby_errinfo = 0; PUSH_TAG(PROT_NONE); @@ -1322,20 +1321,22 @@ ruby_finalize_0(ex) } POP_TAG(); rb_exec_end_proc(); +} + +static void +ruby_finalize_1() +{ + ruby_errinfo = 0; rb_gc_call_finalizer_at_exit(); trace_func = 0; tracing = 0; - if (ruby_errinfo && rb_obj_is_kind_of(ruby_errinfo, rb_eSystemExit)) { - VALUE st = rb_iv_get(ruby_errinfo, "status"); - return NUM2INT(st); - } - return ex; } void ruby_finalize() { - ruby_finalize_0(EXIT_SUCCESS); + ruby_finalize_0(); + ruby_finalize_1(); } int @@ -1343,8 +1344,10 @@ ruby_cleanup(ex) int ex; { int state; + volatile VALUE err = ruby_errinfo; ruby_safe_level = 0; + ruby_finalize_0(); PUSH_TAG(PROT_NONE); PUSH_ITER(ITER_NOT); if ((state = EXEC_TAG()) == 0) { @@ -1355,10 +1358,16 @@ ruby_cleanup(ex) ex = state; } POP_ITER(); - + ruby_errinfo = err; ex = error_handle(ex); POP_TAG(); - return ruby_finalize_0(ex); + + ruby_finalize_1(); + if (err && rb_obj_is_kind_of(err, rb_eSystemExit)) { + VALUE st = rb_iv_get(err, "status"); + return NUM2INT(st); + } + return ex; } int @@ -3904,6 +3913,8 @@ rb_longjmp(tag, mesg) VALUE at; if (thread_set_raised()) { + printf("%d (c:%p m:%p):", tag, curr_thread, main_thread); + rb_p(mesg); ruby_errinfo = exception_error; JUMP_TAG(TAG_FATAL); } diff --git a/file.c b/file.c index 3a09b4e628..4f78b81aeb 100644 --- a/file.c +++ b/file.c @@ -467,7 +467,7 @@ eaccess(path, mode) const char *path; int mode; { -#if defined(S_IXGRP) && !defined(_WIN32) +#if defined(S_IXGRP) && !defined(_WIN32) && !defined(__CYGWIN__) struct stat st; int euid; diff --git a/test/drb/test_drb.rb b/test/drb/test_drb.rb index 437e2b4560..213c70f95d 100644 --- a/test/drb/test_drb.rb +++ b/test/drb/test_drb.rb @@ -1,225 +1,12 @@ -require 'rubyunit' -require 'runit/cui/testrunner' -require 'rbconfig' -require 'drb/drb' -require 'drb/extservm' -require 'timeout' - -class TestService - @@scripts = %w(ut_drb.rb ut_array.rb ut_port.rb ut_large.rb ut_safe1.rb ut_eval.rb) - - def initialize(uri=nil, config={}) - ruby = Config::CONFIG["RUBY_INSTALL_NAME"] - @manager = DRb::ExtServManager.new - @@scripts.each do |nm| - DRb::ExtServManager.command[nm] = "#{ruby} #{nm}" - end - @server = DRb::DRbServer.new(uri, @manager, config) - end - attr_reader :manager, :server -end - -class Onecky - include DRbUndumped - def initialize(n) - @num = n - end - - def to_i - @num.to_i - end - - def sleep(n) - Kernel.sleep(n) - to_i - end -end - -class FailOnecky < Onecky - class OneckyError < RuntimeError; end - def to_i - raise(OneckyError, @num.to_s) - end -end - -class XArray < Array - def initialize(ary) - ary.each do |x| - self.push(x) - end - end -end - -class DRbCoreTest < RUNIT::TestCase - def setup - @ext = $manager.service('ut_drb.rb') - @there = @ext.front - end - - def teardown - @ext.stop_service - end - - def test_00_DRbObject - ro = DRbObject.new(nil, 'druby://localhost:12345') - assert_equal('druby://localhost:12345', ro.__drburi) - assert_equal(nil, ro.__drbref) - - ro = DRbObject.new_with_uri('druby://localhost:12345') - assert_equal('druby://localhost:12345', ro.__drburi) - assert_equal(nil, ro.__drbref) - - ro = DRbObject.new_with_uri('druby://localhost:12345?foobar') - assert_equal('druby://localhost:12345', ro.__drburi) - assert_equal(DRb::DRbURIOption.new('foobar'), ro.__drbref) - end - - def test_01 - assert_equal("hello", @there.hello) - onecky = Onecky.new('3') - assert_equal(6, @there.sample(onecky, 1, 2)) - ary = @there.to_a - assert_kind_of(DRb::DRbObject, ary) - end - - def test_01_02_loop - onecky = Onecky.new('3') - 50.times do - assert_equal(6, @there.sample(onecky, 1, 2)) - ary = @there.to_a - assert_kind_of(DRb::DRbObject, ary) - end - end - - def test_02_unknown - obj = @there.unknown_class - assert_kind_of(DRb::DRbUnknown, obj) - assert_equal('Unknown2', obj.name) - - obj = @there.unknown_module - assert_kind_of(DRb::DRbUnknown, obj) - if RUBY_VERSION >= '1.8' - assert_equal('DRbEx::', obj.name) - else - assert_equal('DRbEx', obj.name) - end - - assert_exception(DRb::DRbUnknownError) do - @there.unknown_error - end - - onecky = FailOnecky.new('3') - - assert_exception(FailOnecky::OneckyError) do - @there.sample(onecky, 1, 2) - end - end - - def test_03 - assert_equal(8, @there.sum(1, 1, 1, 1, 1, 1, 1, 1)) - assert_exception(ArgumentError) do - @there.sum(1, 1, 1, 1, 1, 1, 1, 1, 1) - end - assert_exception(DRb::DRbConnError) do - @there.sum('1' * 2048) - end - end - - def test_04 - assert_respond_to('sum', @there) - assert(!(@there.respond_to? "foobar")) - end - - def test_05_eq - a = @there.to_a[0] - b = @there.to_a[0] - assert(a.id != b.id) - assert(a != b) - assert(a.hash != b.hash) - assert(! a.eql?(b)) - require 'drb/eq' - assert(a == b) - assert_equal(a, b) - assert(a == @there) - assert_equal(a.hash, b.hash) - assert_equal(a.hash, @there.hash) - assert(a.eql?(b)) - assert(a.eql?(@there)) - end - - def test_06_timeout - ten = Onecky.new(10) - assert_exception(TimeoutError) do - @there.do_timeout(ten) - end - assert_exception(TimeoutError) do - @there.do_timeout(ten) - end - end - - def test_07_public_private - assert_no_exception() { - begin - @there.method_missing(:eval) - rescue NameError - assert_match($!.message, /^private method `eval'/) - end - } - assert_no_exception() { - begin - @there.method_missing(:undefined_method_test) - rescue NameError - assert_match($!.message, /^undefined method `undefined_method_test'/) - end - } - assert_exception(SecurityError) do - @there.method_missing(:__send__, :to_s) - end - end - - def test_08_here - ro = DRbObject.new(nil, DRb.uri) - assert_kind_of(String, ro.to_s) - - ro = DRbObject.new_with_uri(DRb.uri) - assert_kind_of(String, ro.to_s) - end - - def uri_concat_option(uri, opt) - "#{uri}?#{opt}" - end +require "#{File.dirname(File.expand_path(__FILE__))}/drbtest" - def test_09_option - uri = uri_concat_option(@there.__drburi, "foo") - ro = DRbObject.new_with_uri(uri) - assert_equal(ro.__drburi, @there.__drburi) - assert_equal(3, ro.size) - - uri = uri_concat_option(@there.__drburi, "") - ro = DRbObject.new_with_uri(uri) - assert_equal(ro.__drburi, @there.__drburi) - assert_equal(DRb::DRbURIOption.new(''), ro.__drbref) - - uri = uri_concat_option(@there.__drburi, "hello?world") - ro = DRbObject.new_with_uri(uri) - assert_equal(DRb::DRbURIOption.new('hello?world'), ro.__drbref) - - uri = uri_concat_option(@there.__drburi, "?hello?world") - ro = DRbObject.new_with_uri(uri) - assert_equal(DRb::DRbURIOption.new('?hello?world'), ro.__drbref) - end - - def test_10_yield_undumped - @there.xarray2_hash.each do |k, v| - assert_kind_of(String, k) - assert_kind_of(DRbObject, v) - end - end +class TestDRbCore < Test::Unit::TestCase + include DRbCore end -class DRbYieldTest < RUNIT::TestCase +class TestDRbYield < Test::Unit::TestCase def setup - @ext = $manager.service('ut_drb.rb') + @ext = DRbService.manager.service('ut_drb.rb') @there = @ext.front end @@ -282,20 +69,20 @@ class DRbYieldTest < RUNIT::TestCase def test_04_many_to_one s = nil - @there.echo_yield_0 {|s|} - assert_equal(nil, s) - @there.echo_yield(nil) {|s|} - assert_equal(nil, s) - @there.echo_yield(1) {|s|} - assert_equal(1, s) - @there.echo_yield(1, 2) {|s|} + @there.echo_yield_0 {|*s|} + assert_equal([], s) + @there.echo_yield(nil) {|*s|} + assert_equal([nil], s) + @there.echo_yield(1) {|*s|} + assert_equal([1], s) + @there.echo_yield(1, 2) {|*s|} assert_equal([1, 2], s) - @there.echo_yield(1, 2, 3) {|s|} + @there.echo_yield(1, 2, 3) {|*s|} assert_equal([1, 2, 3], s) - @there.echo_yield([], []) {|s|} + @there.echo_yield([], []) {|*s|} assert_equal([[], []], s) - @there.echo_yield([]) {|s|} - assert_equal([], s) + @there.echo_yield([]) {|*s|} + assert_equal([[]], s) end def test_05_array_subclass @@ -306,7 +93,7 @@ class DRbYieldTest < RUNIT::TestCase end end -class RubyYieldTest < DRbYieldTest +class TestRubyYield < TestDRbYield def echo_yield(*arg) yield(*arg) end @@ -338,7 +125,7 @@ class RubyYieldTest < DRbYieldTest end end -class Ruby18YieldTest < RubyYieldTest +class TestRuby18Yield < TestRubyYield class YieldTest18 def echo_yield(*arg, &proc) proc.call(*arg) @@ -368,87 +155,13 @@ class Ruby18YieldTest < RubyYieldTest end end -class DRbAryTest < RUNIT::TestCase - def setup - @ext = $manager.service('ut_array.rb') - @there = @ext.front - end - - def teardown - @ext.stop_service - end - - def test_01 - assert_kind_of(DRb::DRbObject, @there) - end - - def test_02_collect - ary = @there.collect do |x| x + x end - assert_kind_of(Array, ary) - assert_equal([2, 4, 'IIIIII', 8, 'fivefive', 12], ary) - end - - def test_03_redo - ary = [] - count = 0 - @there.each do |x| - count += 1 - ary.push x - redo if count == 3 - end - assert_equal([1, 2, 'III', 'III', 4, 'five', 6], ary) - end - - def test_04_retry - retried = false - ary = [] - @there.each do |x| - ary.push x - if x == 4 && !retried - retried = true - retry - end - end - assert_equal([1, 2, 'III', 4, 1, 2, 'III', 4, 'five', 6], ary) - end - - def test_05_break - ary = [] - @there.each do |x| - ary.push x - break if x == 4 - end - assert_equal([1, 2, 'III', 4], ary) - end - - def test_06_next - ary = [] - @there.each do |x| - next if String === x - ary.push x - end - assert_equal([1, 2, 4, 6], ary) - end - - if RUBY_VERSION >= '1.8' - class_eval <= '1.8' - RUNIT::CUI::TestRunner.run(Ruby18YieldTest.suite) - end - RUNIT::CUI::TestRunner.run(DRbYieldTest.suite) - RUNIT::CUI::TestRunner.run(DRbAryTest.suite) - RUNIT::CUI::TestRunner.run(DRbMServerTest.suite) - RUNIT::CUI::TestRunner.run(DRbSafe1Test.suite) - RUNIT::CUI::TestRunner.run(DRbReusePortTest.suite) - RUNIT::CUI::TestRunner.run(DRbLargeTest.suite) -end - diff --git a/test/drb/test_drbssl.rb b/test/drb/test_drbssl.rb index 249e90aa99..6e2e0b1746 100644 --- a/test/drb/test_drbssl.rb +++ b/test/drb/test_drbssl.rb @@ -1,13 +1,34 @@ -require 'test_drb' +require "#{File.dirname(File.expand_path(__FILE__))}/drbtest" require 'drb/ssl' -class TestService - @@scripts = %w(ut_drb_drbssl.rb ut_array_drbssl.rb) +class DRbSSLService < DRbService + %w(ut_drb_drbssl.rb ut_array_drbssl.rb).each do |nm| + DRb::ExtServManager.command[nm] = "#{@@ruby} #{@@dir}/#{nm}" + end + config = Hash.new + + config[:SSLVerifyMode] = OpenSSL::SSL::VERIFY_PEER + config[:SSLVerifyCallback] = lambda{ |ok,x509_store| + true + } + begin + data = open("sample.key"){|io| io.read } + config[:SSLPrivateKey] = OpenSSL::PKey::RSA.new(data) + data = open("sample.crt"){|io| io.read } + config[:SSLCertificate] = OpenSSL::X509::Certificate.new(data) + rescue + # $stderr.puts "Switching to use self-signed certificate" + config[:SSLCertName] = + [ ["C","JP"], ["O","Foo.DRuby.Org"], ["CN", "Sample"] ] + end + + @server = DRb::DRbServer.new(ARGV.shift || 'drbssl://:0', @@manager, config) end -class DRbXCoreTest < DRbCoreTest +class TestDRbSSLCore < Test::Unit::TestCase + include DRbCore def setup - @ext = $manager.service('ut_drb_drbssl.rb') + @ext = DRbSSLService.manager.service('ut_drb_drbssl.rb') @there = @ext.front end @@ -22,10 +43,10 @@ class DRbXCoreTest < DRbCoreTest def test_06_timeout ten = Onecky.new(3) - assert_exception(TimeoutError) do + assert_raises(TimeoutError) do @there.do_timeout(ten) end - assert_exception(TimeoutError) do + assert_raises(TimeoutError) do @there.do_timeout(ten) end sleep 3 @@ -33,34 +54,10 @@ class DRbXCoreTest < DRbCoreTest end -class DRbXAryTest < DRbAryTest +class TestDRbSSLAry < Test::Unit::TestCase + include DRbAry def setup - @ext = $manager.service('ut_array_drbssl.rb') + @ext = DRbSSLService.manager.service('ut_array_drbssl.rb') @there = @ext.front end end - -if __FILE__ == $0 - config = Hash.new - - config[:SSLVerifyMode] = OpenSSL::SSL::VERIFY_PEER - config[:SSLVerifyCallback] = lambda{ |ok,x509_store| - true - } - begin - data = open("sample.key"){|io| io.read } - config[:SSLPrivateKey] = OpenSSL::PKey::RSA.new(data) - data = open("sample.crt"){|io| io.read } - config[:SSLCertificate] = OpenSSL::X509::Certificate.new(data) - rescue - $stderr.puts "Switching to use self-signed certificate" - config[:SSLCertName] = - [ ["C","JP"], ["O","Foo.DRuby.Org"], ["CN", "Sample"] ] - end - - $testservice = TestService.new(ARGV.shift || 'drbssl://:0', config) - $manager = $testservice.manager - RUNIT::CUI::TestRunner.run(DRbXCoreTest.suite) - RUNIT::CUI::TestRunner.run(DRbXAryTest.suite) - # exit! -end diff --git a/test/drb/test_drbunix.rb b/test/drb/test_drbunix.rb index d1fa63dd77..1aaaffe359 100644 --- a/test/drb/test_drbunix.rb +++ b/test/drb/test_drbunix.rb @@ -1,12 +1,17 @@ -require 'test_drb' +require "#{File.dirname(File.expand_path(__FILE__))}/drbtest" +require 'drb/unix' -class TestService - @@scripts = %w(ut_drb_drbunix.rb ut_array_drbunix.rb) +class DRbUNIXService < DRbService + %w(ut_drb_drbunix.rb ut_array_drbunix.rb).each do |nm| + DRb::ExtServManager.command[nm] = "#{@@ruby} #{@@dir}/#{nm}" + end + @server = DRb::DRbServer.new(ARGV.shift || 'drbunix:', @@manager, {}) end -class DRbXCoreTest < DRbCoreTest +class TestDRbUNIXCore < Test::Unit::TestCase + include DRbCore def setup - @ext = $manager.service('ut_drb_drbunix.rb') + @ext = DRbUNIXService.manager.service('ut_drb_drbunix.rb') @there = @ext.front end @@ -21,26 +26,20 @@ class DRbXCoreTest < DRbCoreTest def test_06_timeout ten = Onecky.new(3) - assert_exception(TimeoutError) do + assert_raises(TimeoutError) do @there.do_timeout(ten) end - assert_exception(TimeoutError) do + assert_raises(TimeoutError) do @there.do_timeout(ten) end sleep 3 end end -class DRbXAryTest < DRbAryTest +class TestDRbUNIXAry < Test::Unit::TestCase + include DRbAry def setup - @ext = $manager.service('ut_array_drbunix.rb') + @ext = DRbUNIXService.manager.service('ut_array_drbunix.rb') @there = @ext.front end end - -if __FILE__ == $0 - $testservice = TestService.new(ARGV.shift || 'drbunix:') - $manager = $testservice.manager - RUNIT::CUI::TestRunner.run(DRbXCoreTest.suite) - RUNIT::CUI::TestRunner.run(DRbXAryTest.suite) -end diff --git a/test/drb/ut_drb.rb b/test/drb/ut_drb.rb index 7a6409a783..2a121b0de3 100644 --- a/test/drb/ut_drb.rb +++ b/test/drb/ut_drb.rb @@ -134,4 +134,3 @@ if __FILE__ == $0 es = DRb::ExtServ.new(ARGV.shift, ARGV.shift) DRb.thread.join end - diff --git a/test/drb/ut_drb_drbssl.rb b/test/drb/ut_drb_drbssl.rb index cc5aea9733..b09864aebe 100644 --- a/test/drb/ut_drb_drbssl.rb +++ b/test/drb/ut_drb_drbssl.rb @@ -1,4 +1,4 @@ -require 'ut_drb' +require "#{File.dirname(File.expand_path(__FILE__))}/ut_drb" require 'drb/ssl' if __FILE__ == $0 diff --git a/test/drb/ut_drb_drbunix.rb b/test/drb/ut_drb_drbunix.rb index 7e1f6a2e5a..ae0674ef37 100644 --- a/test/drb/ut_drb_drbunix.rb +++ b/test/drb/ut_drb_drbunix.rb @@ -1,4 +1,4 @@ -require 'ut_drb' +require "#{File.dirname(File.expand_path(__FILE__))}/ut_drb" if __FILE__ == $0 def ARGV.shift -- cgit v1.2.3