ruby-changes:36974
From: nobu <ko1@a...>
Date: Mon, 29 Dec 2014 11:18:45 +0900 (JST)
Subject: [ruby-changes:36974] nobu:r49055 (trunk): thread.c: fix dynamic symbol keys
nobu 2014-12-29 11:18:20 +0900 (Mon, 29 Dec 2014) New Revision: 49055 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49055 Log: thread.c: fix dynamic symbol keys * thread.c (rb_thread_variable_get): fix dynamic symbol keys. rb_check_id() returns non-zero only for static symbols, whereas thread local variable keys can be dynamic symbols. [ruby-core:67185] [Bug #10667] Modified files: trunk/ChangeLog trunk/test/-ext-/symbol/test_inadvertent_creation.rb trunk/test/ruby/test_thread.rb trunk/thread.c Index: ChangeLog =================================================================== --- ChangeLog (revision 49054) +++ ChangeLog (revision 49055) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Dec 29 11:18:17 2014 Nobuyoshi Nakada <nobu@r...> + + * thread.c (rb_thread_variable_get): fix dynamic symbol keys. + rb_check_id() returns non-zero only for static symbols, whereas + thread local variable keys can be dynamic symbols. + [ruby-core:67185] [Bug #10667] + Mon Dec 29 10:37:27 2014 Thiago Lewin <thiago_lewin@y...> * io.c (rb_f_select): [DOC] workaround for YARD doc. [Fix GH-799] Index: thread.c =================================================================== --- thread.c (revision 49054) +++ thread.c (revision 49055) @@ -2936,11 +2936,9 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/thread.c#L2936 rb_thread_variable_get(VALUE thread, VALUE key) { VALUE locals; - ID id = rb_check_id(&key); - if (!id) return Qnil; locals = rb_ivar_get(thread, id_locals); - return rb_hash_aref(locals, ID2SYM(id)); + return rb_hash_aref(locals, rb_to_symbol(key)); } /* Index: test/ruby/test_thread.rb =================================================================== --- test/ruby/test_thread.rb (revision 49054) +++ test/ruby/test_thread.rb (revision 49055) @@ -432,6 +432,16 @@ class TestThread < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L432 end end + def test_thread_local_dynamic_symbol + bug10667 = '[ruby-core:67185] [Bug #10667]' + t = Thread.new {}.join + key_str = "foo#{rand}" + key_sym = key_str.to_sym + t.thread_variable_set(key_str, "bar") + assert_equal("bar", t.thread_variable_get(key_str), "#{bug10667}: string key") + assert_equal("bar", t.thread_variable_get(key_sym), "#{bug10667}: symbol key") + end + def test_select_wait assert_nil(IO.select(nil, nil, nil, 0.001)) t = Thread.new do Index: test/-ext-/symbol/test_inadvertent_creation.rb =================================================================== --- test/-ext-/symbol/test_inadvertent_creation.rb (revision 49054) +++ test/-ext-/symbol/test_inadvertent_creation.rb (revision 49055) @@ -202,7 +202,13 @@ module Test_Symbol https://github.com/ruby/ruby/blob/trunk/test/-ext-/symbol/test_inadvertent_creation.rb#L202 Thread.current.thread_variable_set(:test, nil) name = noninterned_name assert_nil(Thread.current.thread_variable_get(name)) - assert_not_interned(name) + assert_not_pinneddown(name) + end + + def test_thread_variable_set + name = noninterned_name + Thread.current.thread_variable_set(name, 42) + assert_not_pinneddown(name) end def test_thread_variable? -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/