[前][次][番号順一覧][スレッド一覧]

ruby-changes:61376

From: Jeremy <ko1@a...>
Date: Tue, 26 May 2020 13:38:50 +0900 (JST)
Subject: [ruby-changes:61376] 4e1f2283b4 (master): Make Thread#thread_variable? similar to #thread_variable_get

https://git.ruby-lang.org/ruby.git/commit/?id=4e1f2283b4

From 4e1f2283b432e833bd4e6f7724ba0496760e68e8 Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Mon, 25 May 2020 19:29:32 -0700
Subject: 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]

diff --git a/test/-ext-/symbol/test_inadvertent_creation.rb b/test/-ext-/symbol/test_inadvertent_creation.rb
index 40b3f59..b0508e9 100644
--- a/test/-ext-/symbol/test_inadvertent_creation.rb
+++ b/test/-ext-/symbol/test_inadvertent_creation.rb
@@ -255,7 +255,7 @@ module Test_Symbol https://github.com/ruby/ruby/blob/trunk/test/-ext-/symbol/test_inadvertent_creation.rb#L255
       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
diff --git a/thread.c b/thread.c
index 13fef6b..91a953b 100644
--- a/thread.c
+++ b/thread.c
@@ -3468,7 +3468,7 @@ rb_thread_variable_get(VALUE thread, VALUE key) https://github.com/ruby/ruby/blob/trunk/thread.c#L3468
  */
 
 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) https://github.com/ruby/ruby/blob/trunk/thread.c#L3477
     }
 
     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 https://github.com/ruby/ruby/blob/trunk/thread.c#L3667
 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 {
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]