ruby-changes:2064
From: ko1@a...
Date: 29 Sep 2007 04:05:05 +0900
Subject: [ruby-changes:2064] ko1 - Ruby:r13555 (trunk): * cont.c: Thread local storage should be fiber local.
ko1 2007-09-29 04:04:45 +0900 (Sat, 29 Sep 2007) New Revision: 13555 Modified files: trunk/ChangeLog trunk/bootstraptest/test_knownbug.rb trunk/cont.c trunk/test/ruby/test_fiber.rb trunk/version.h Log: * cont.c: Thread local storage should be fiber local. * bootstraptest/test_knownbug.rb, test/ruby/test_fiber.rb: move a fixed test. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/version.h?r1=13555&r2=13554 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_fiber.rb?r1=13555&r2=13554 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/cont.c?r1=13555&r2=13554 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13555&r2=13554 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/bootstraptest/test_knownbug.rb?r1=13555&r2=13554 Index: ChangeLog =================================================================== --- ChangeLog (revision 13554) +++ ChangeLog (revision 13555) @@ -1,3 +1,10 @@ +Sat Sep 29 03:53:26 2007 Koichi Sasada <ko1@a...> + + * 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 <matz@r...> * insnhelper.ci (vm_call_method): allow send! to call protected Index: bootstraptest/test_knownbug.rb =================================================================== --- bootstraptest/test_knownbug.rb (revision 13554) +++ bootstraptest/test_knownbug.rb (revision 13555) @@ -13,31 +13,3 @@ 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] -} Index: cont.c =================================================================== --- cont.c (revision 13554) +++ cont.c (revision 13555) @@ -86,6 +86,9 @@ 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 @@ /* 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 @@ th->cfp->proc = 0; th->cfp->block_iseq = 0; th->tag = 0; + th->local_storage = st_init_numtable(); th->first_proc = proc; Index: version.h =================================================================== --- version.h (revision 13554) +++ version.h (revision 13555) @@ -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[]; Index: test/ruby/test_fiber.rb =================================================================== --- test/ruby/test_fiber.rb (revision 13554) +++ test/ruby/test_fiber.rb (revision 13555) @@ -131,5 +131,34 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml