* 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
This commit is contained in:
matz 2003-10-21 14:42:15 +00:00
Родитель 8af34b7b33
Коммит 06d9340f2e
9 изменённых файлов: 119 добавлений и 408 удалений

Просмотреть файл

@ -1,3 +1,10 @@
Tue Oct 21 23:16:26 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <nobu@ruby-lang.org>
* 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 <eban@ruby-lang.org>
* ext/win32ole/extconf.rb: check "windows.h", not "windows".
[ruby-talk:84051]
Sat Oct 11 20:41:03 2003 Corinna Vinschen <corinna@vinschen.de>
* file.c (eaccess): Use access(2) on Cygwin.
Sat Oct 11 17:09:21 2003 WATANABE Hirofumi <eban@ruby-lang.org>
* lib/rexml/quickpath.rb (REXML::QuickPath::match):

33
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);
}

2
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;

Просмотреть файл

@ -1,225 +1,12 @@
require 'rubyunit'
require 'runit/cui/testrunner'
require 'rbconfig'
require 'drb/drb'
require 'drb/extservm'
require 'timeout'
require "#{File.dirname(File.expand_path(__FILE__))}/drbtest"
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
class TestDRbCore < Test::Unit::TestCase
include DRbCore
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
class TestDRbYield < Test::Unit::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
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
end
class DRbYieldTest < RUNIT::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|}
assert_equal([1, 2], s)
@there.echo_yield(1, 2, 3) {|s|}
assert_equal([1, 2, 3], s)
@there.echo_yield([], []) {|s|}
assert_equal([[], []], s)
@there.echo_yield([]) {|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|}
assert_equal([1, 2, 3], 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 <<EOS
def test_07_break_18
ary = []
result = @there.each do |x|
ary.push x
break(:done) if x == 4
end
assert_equal([1, 2, 'III', 4], ary)
assert_equal(:done, result)
end
EOS
end
class TestDRbAry < Test::Unit::TestCase
include DRbAry
end
class DRbMServerTest < RUNIT::TestCase
class TestDRbMServer < Test::Unit::TestCase
def setup
@ext = $manager.service('ut_drb.rb')
@ext = DRbService.manager.service('ut_drb.rb')
@there = @ext.front
@server = (1..3).collect do |n|
DRb::DRbServer.new(nil, Onecky.new(n.to_s))
@ -467,27 +180,27 @@ class DRbMServerTest < RUNIT::TestCase
end
end
class DRbReusePortTest < DRbAryTest
class TestDRbReusePort < TestDRbAry
def setup
sleep 1
@ext = $manager.service('ut_port.rb')
@ext = DRbService.manager.service('ut_port.rb')
@there = @ext.front
end
end
class DRbSafe1Test < DRbAryTest
class TestDRbSafe1 < TestDRbAry
def setup
sleep 1
@ext = $manager.service('ut_safe1.rb')
@ext = DRbService.manager.service('ut_safe1.rb')
@there = @ext.front
end
end
class DRbEvalTest < RUNIT::TestCase
class TestDRbEval < Test::Unit::TestCase
def setup
super
sleep 1
@ext = $manager.service('ut_eval.rb')
@ext = DRbService.manager.service('ut_eval.rb')
@there = @ext.front
end
@ -496,30 +209,30 @@ class DRbEvalTest < RUNIT::TestCase
end
def test_01_safe1_eval
assert_exception(SecurityError) do
assert_raises(SecurityError) do
@there.method_missing(:instance_eval, 'ENV.inspect')
end
assert_exception(SecurityError) do
assert_raises(SecurityError) do
@there.method_missing(:send, :eval, 'ENV.inspect')
end
remote_class = @there.remote_class
assert_exception(SecurityError) do
assert_raises(SecurityError) do
remote_class.class_eval('ENV.inspect')
end
assert_exception(SecurityError) do
assert_raises(SecurityError) do
remote_class.module_eval('ENV.inspect')
end
end
end
class DRbLargeTest < RUNIT::TestCase
class TestDRbLarge < Test::Unit::TestCase
def setup
sleep 1
@ext = $manager.service('ut_large.rb')
@ext = DRbService.manager.service('ut_large.rb')
@there = @ext.front
end
@ -544,7 +257,7 @@ class DRbLargeTest < RUNIT::TestCase
end
def test_04_many_arg
assert_exception(ArgumentError) {
assert_raises(ArgumentError) {
@there.arg_test(1, 2, 3, 4, 5, 6, 7, 8, 9, 0)
}
end
@ -560,22 +273,3 @@ class DRbLargeTest < RUNIT::TestCase
assert_kind_of(StandardError, exception)
end
end
if __FILE__ == $0
$testservice = TestService.new
$manager = $testservice.manager
RUNIT::CUI::TestRunner.run(DRbCoreTest.suite)
RUNIT::CUI::TestRunner.run(DRbEvalTest.suite)
RUNIT::CUI::TestRunner.run(RubyYieldTest.suite)
if RUBY_VERSION >= '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

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -134,4 +134,3 @@ if __FILE__ == $0
es = DRb::ExtServ.new(ARGV.shift, ARGV.shift)
DRb.thread.join
end

Просмотреть файл

@ -1,4 +1,4 @@
require 'ut_drb'
require "#{File.dirname(File.expand_path(__FILE__))}/ut_drb"
require 'drb/ssl'
if __FILE__ == $0

Просмотреть файл

@ -1,4 +1,4 @@
require 'ut_drb'
require "#{File.dirname(File.expand_path(__FILE__))}/ut_drb"
if __FILE__ == $0
def ARGV.shift