diff --git a/ChangeLog b/ChangeLog index 8ded192543..10776b05d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sat Jan 3 21:17:58 2015 Nobuyoshi Nakada + + * 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] + Thu Jan 1 08:29:55 2015 Nobuyoshi Nakada * cygwin/GNUmakefile.in (EXTOBJS): override to add resource files 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 diff --git a/thread.c b/thread.c index 9ceb441f8e..5d8ac7eb04 100644 --- a/thread.c +++ b/thread.c @@ -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)); } /* diff --git a/version.h b/version.h index ee1861d259..add31dddbf 100644 --- a/version.h +++ b/version.h @@ -1,10 +1,10 @@ #define RUBY_VERSION "2.2.0" -#define RUBY_RELEASE_DATE "2015-01-01" -#define RUBY_PATCHLEVEL 5 +#define RUBY_RELEASE_DATE "2015-01-03" +#define RUBY_PATCHLEVEL 6 #define RUBY_RELEASE_YEAR 2015 #define RUBY_RELEASE_MONTH 1 -#define RUBY_RELEASE_DAY 1 +#define RUBY_RELEASE_DAY 3 #include "ruby/version.h"