mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Make Thread#thread_variable? similar to #thread_variable_get
Don't use rb_check_id, which only works for pinned symbols. Switch inadvertent creation test for thread_variable? to only check for pinned symbols, same as thread_variable_get and thread_variable_set. Make key variable name in thread_local_set match thread_local_get and thread_variable?. Fixes [Bug #16906]
This commit is contained in:
parent
faab5cbeb7
commit
4e1f2283b4
Notes:
git
2020-05-26 13:38:58 +09:00
2 changed files with 4 additions and 7 deletions
|
@ -255,7 +255,7 @@ module Test_Symbol
|
|||
Thread.current.thread_variable_set(:test, nil)
|
||||
name = noninterned_name
|
||||
assert_not_send([Thread.current, :thread_variable?, name])
|
||||
assert_not_interned(name)
|
||||
assert_not_pinneddown(name)
|
||||
end
|
||||
|
||||
def test_enumerable_inject_op
|
||||
|
|
9
thread.c
9
thread.c
|
@ -3468,7 +3468,7 @@ rb_thread_variable_get(VALUE thread, VALUE key)
|
|||
*/
|
||||
|
||||
static VALUE
|
||||
rb_thread_variable_set(VALUE thread, VALUE id, VALUE val)
|
||||
rb_thread_variable_set(VALUE thread, VALUE key, VALUE val)
|
||||
{
|
||||
VALUE locals;
|
||||
|
||||
|
@ -3477,7 +3477,7 @@ rb_thread_variable_set(VALUE thread, VALUE id, VALUE val)
|
|||
}
|
||||
|
||||
locals = rb_thread_local_storage(thread);
|
||||
return rb_hash_aset(locals, rb_to_symbol(id), val);
|
||||
return rb_hash_aset(locals, rb_to_symbol(key), val);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -3667,16 +3667,13 @@ static VALUE
|
|||
rb_thread_variable_p(VALUE thread, VALUE key)
|
||||
{
|
||||
VALUE locals;
|
||||
ID id = rb_check_id(&key);
|
||||
|
||||
if (!id) return Qfalse;
|
||||
|
||||
if (LIKELY(!THREAD_LOCAL_STORAGE_INITIALISED_P(thread))) {
|
||||
return Qfalse;
|
||||
}
|
||||
locals = rb_thread_local_storage(thread);
|
||||
|
||||
if (rb_hash_lookup(locals, ID2SYM(id)) != Qnil) {
|
||||
if (rb_hash_lookup(locals, rb_to_symbol(key)) != Qnil) {
|
||||
return Qtrue;
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Reference in a new issue