From edb751ca4d2b7513fa1bdd4df067fd59c98680a2 Mon Sep 17 00:00:00 2001 From: ko1 Date: Fri, 28 Sep 2007 19:04:45 +0000 Subject: * cont.c: Thread local storage should be fiber local. * bootstraptest/test_knownbug.rb, test/ruby/test_fiber.rb: move a fixed test. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@13555 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ bootstraptest/test_knownbug.rb | 28 ---------------------------- cont.c | 5 +++++ test/ruby/test_fiber.rb | 29 +++++++++++++++++++++++++++++ version.h | 6 +++--- 5 files changed, 44 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index b68432b4d..f9f99cd96 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sat Sep 29 03:53:26 2007 Koichi Sasada + + * cont.c: Thread local storage should be fiber local. + + * bootstraptest/test_knownbug.rb, test/ruby/test_fiber.rb: + move a fixed test. + Fri Sep 28 23:15:31 2007 Yukihiro Matsumoto * insnhelper.ci (vm_call_method): allow send! to call protected diff --git a/bootstraptest/test_knownbug.rb b/bootstraptest/test_knownbug.rb index 20533fa1b..259ebc21f 100644 --- a/bootstraptest/test_knownbug.rb +++ b/bootstraptest/test_knownbug.rb @@ -13,31 +13,3 @@ assert_finish 1, %q{ w.write "a" }, '[ruby-dev:31866]' -assert_equal "[[nil, 1, 3, 3, 1, nil, nil], [nil, 2, 2, nil]]", %q{ - def tvar(var, val) - old = Thread.current[var] - begin - Thread.current[var] = val - yield - ensure - Thread.current[var] = old - end - end - ary1 = [] - ary2 = [] - fb = Fiber.new { - ary2 << Thread.current[:v]; tvar(:v, 2) { - ary2 << Thread.current[:v]; Fiber.yield - ary2 << Thread.current[:v]; } - ary2 << Thread.current[:v]; Fiber.yield - ary2 << Thread.current[:v] - } - ary1 << Thread.current[:v]; tvar(:v,1) { - ary1 << Thread.current[:v]; tvar(:v,3) { - ary1 << Thread.current[:v]; fb.resume - ary1 << Thread.current[:v]; } - ary1 << Thread.current[:v]; } - ary1 << Thread.current[:v]; fb.resume - ary1 << Thread.current[:v]; - [ary1, ary2] -} diff --git a/cont.c b/cont.c index 1f1912bc8..36baa41ba 100644 --- a/cont.c +++ b/cont.c @@ -86,6 +86,9 @@ cont_free(void *ptr) RUBY_FREE_UNLESS_NULL(cont->machine_register_stack); #endif RUBY_FREE_UNLESS_NULL(cont->vm_stack); + if (cont->saved_thread.local_storage) { + st_free_table(cont->saved_thread.local_storage); + } ruby_xfree(ptr); } RUBY_FREE_LEAVE("cont"); @@ -205,6 +208,7 @@ cont_restore_1(rb_context_t *cont) /* fiber */ th->stack = sth->stack; th->stack_size = sth->stack_size; + th->local_storage = sth->local_storage; th->fiber = cont->self; } else { @@ -500,6 +504,7 @@ fiber_alloc(VALUE klass, VALUE proc) th->cfp->proc = 0; th->cfp->block_iseq = 0; th->tag = 0; + th->local_storage = st_init_numtable(); th->first_proc = proc; diff --git a/test/ruby/test_fiber.rb b/test/ruby/test_fiber.rb index 2756e6b21..fc9a49919 100644 --- a/test/ruby/test_fiber.rb +++ b/test/ruby/test_fiber.rb @@ -131,5 +131,34 @@ class TestFiber < Test::Unit::TestCase assert_equal(:ok, f1.transfer) assert_equal([:baz], ary) end + + def test_tls + # + def tvar(var, val) + old = Thread.current[var] + begin + Thread.current[var] = val + yield + ensure + Thread.current[var] = old + end + end + + fb = Fiber.new { + assert_equal(nil, Thread.current[:v]); tvar(:v, :x) { + assert_equal(:x, Thread.current[:v]); Fiber.yield + assert_equal(:x, Thread.current[:v]); } + assert_equal(nil, Thread.current[:v]); Fiber.yield + raise # unreachable + } + + assert_equal(nil, Thread.current[:v]); tvar(:v,1) { + assert_equal(1, Thread.current[:v]); tvar(:v,3) { + assert_equal(3, Thread.current[:v]); fb.resume + assert_equal(3, Thread.current[:v]); } + assert_equal(1, Thread.current[:v]); } + assert_equal(nil, Thread.current[:v]); fb.resume + assert_equal(nil, Thread.current[:v]); + end end diff --git a/version.h b/version.h index dd9f7bd59..d1a0b7948 100644 --- a/version.h +++ b/version.h @@ -1,7 +1,7 @@ #define RUBY_VERSION "1.9.0" -#define RUBY_RELEASE_DATE "2007-09-28" +#define RUBY_RELEASE_DATE "2007-09-29" #define RUBY_VERSION_CODE 190 -#define RUBY_RELEASE_CODE 20070928 +#define RUBY_RELEASE_CODE 20070929 #define RUBY_PATCHLEVEL 0 #define RUBY_VERSION_MAJOR 1 @@ -9,7 +9,7 @@ #define RUBY_VERSION_TEENY 0 #define RUBY_RELEASE_YEAR 2007 #define RUBY_RELEASE_MONTH 9 -#define RUBY_RELEASE_DAY 28 +#define RUBY_RELEASE_DAY 29 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[]; -- cgit