diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-12-29 02:18:20 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-12-29 02:18:20 +0000 |
commit | 401c8bb00be23a6485a068add70e01419673a91e (patch) | |
tree | 695e66395b494972a653d54dfbfbc29903fbc110 | |
parent | 7fd45e90cb165ae1274f8bdd10c76ef8cfab580b (diff) | |
download | ruby-401c8bb00be23a6485a068add70e01419673a91e.tar.gz |
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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49055 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | test/-ext-/symbol/test_inadvertent_creation.rb | 8 | ||||
-rw-r--r-- | test/ruby/test_thread.rb | 10 | ||||
-rw-r--r-- | thread.c | 4 |
4 files changed, 25 insertions, 4 deletions
@@ -1,3 +1,10 @@ +Mon Dec 29 11:18:17 2014 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * 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@yahoo.com.br> * io.c (rb_f_select): [DOC] workaround for YARD doc. [Fix GH-799] diff --git a/test/-ext-/symbol/test_inadvertent_creation.rb b/test/-ext-/symbol/test_inadvertent_creation.rb index abcb5d9ccb..b180d08b04 100644 --- a/test/-ext-/symbol/test_inadvertent_creation.rb +++ b/test/-ext-/symbol/test_inadvertent_creation.rb @@ -202,7 +202,13 @@ module Test_Symbol 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? diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index fba4737009..87d5f0f79e 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -432,6 +432,16 @@ class TestThread < Test::Unit::TestCase 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 @@ -2936,11 +2936,9 @@ static VALUE 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)); } /* |