summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authorJeremy Evans <[email protected]>2024-07-05 08:15:47 -0700
committerBenoit Daloze <[email protected]>2024-07-06 12:07:32 +0200
commit7f1fe5f091db3b05c3970e7b7a7c602922729642 (patch)
tree46556fa497c22cb407f2071bf707670f45e2766d /thread.c
parente240fc9c3c154349e3b93716db82b06541e07cf8 (diff)
Raise a TypeError for Thread#thread_variable{?,_get} for non-symbol
Previously, a TypeError was not raised if there were no thread variables, because the conversion to symbol was done after that check. Convert to symbol before checking for whether thread variables are set to make the behavior consistent. Fixes [Bug #20606]
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/thread.c b/thread.c
index 56f1399d41..45aa0565ca 100644
--- a/thread.c
+++ b/thread.c
@@ -3756,12 +3756,13 @@ static VALUE
rb_thread_variable_get(VALUE thread, VALUE key)
{
VALUE locals;
+ VALUE symbol = rb_to_symbol(key);
if (LIKELY(!THREAD_LOCAL_STORAGE_INITIALISED_P(thread))) {
return Qnil;
}
locals = rb_thread_local_storage(thread);
- return rb_hash_aref(locals, rb_to_symbol(key));
+ return rb_hash_aref(locals, symbol);
}
/*
@@ -3912,13 +3913,14 @@ static VALUE
rb_thread_variable_p(VALUE thread, VALUE key)
{
VALUE locals;
+ VALUE symbol = rb_to_symbol(key);
if (LIKELY(!THREAD_LOCAL_STORAGE_INITIALISED_P(thread))) {
return Qfalse;
}
locals = rb_thread_local_storage(thread);
- return RBOOL(rb_hash_lookup(locals, rb_to_symbol(key)) != Qnil);
+ return RBOOL(rb_hash_lookup(locals, symbol) != Qnil);
}
/*