diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-04-04 05:37:21 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-04-04 05:37:21 +0000 |
commit | 80748440654f93d40a97d0f4fb287f5d268c7cfd (patch) | |
tree | aedc888d820184526efa990a26affb7688658bce /thread.c | |
parent | f00035a4f7842b9cccbb43fc65d567ca2630d742 (diff) | |
download | ruby-80748440654f93d40a97d0f4fb287f5d268c7cfd.tar.gz |
thread.c: avoid inadvertent symbol creation
* thread.c (rb_thread_aref): avoid inadvertent symbol creation.
(rb_thread_variable_get): ditto.
(rb_thread_key_p): ditto.
(rb_thread_variable_p): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40096 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r-- | thread.c | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -2784,9 +2784,11 @@ rb_thread_local_aref(VALUE thread, ID id) */ static VALUE -rb_thread_aref(VALUE thread, VALUE id) +rb_thread_aref(VALUE thread, VALUE key) { - return rb_thread_local_aref(thread, rb_to_id(id)); + ID id = rb_check_id(&key); + if (!id) return Qnil; + return rb_thread_local_aref(thread, id); } VALUE @@ -2862,10 +2864,11 @@ rb_thread_aset(VALUE self, VALUE id, VALUE val) */ static VALUE -rb_thread_variable_get(VALUE thread, VALUE id) +rb_thread_variable_get(VALUE thread, VALUE key) { VALUE locals; rb_thread_t *th; + ID id = rb_check_id(&key); GetThreadPtr(thread, th); @@ -2873,8 +2876,9 @@ rb_thread_variable_get(VALUE thread, VALUE id) rb_raise(rb_eSecurityError, "Insecure: can't access thread locals"); } + if (!id) return Qnil; locals = rb_iv_get(thread, "locals"); - return rb_hash_aref(locals, ID2SYM(rb_to_id(id))); + return rb_hash_aref(locals, ID2SYM(id)); } /* @@ -2922,11 +2926,11 @@ static VALUE rb_thread_key_p(VALUE self, VALUE key) { rb_thread_t *th; - ID id = rb_to_id(key); + ID id = rb_check_id(&key); GetThreadPtr(self, th); - if (!th->local_storage) { + if (!id || !th->local_storage) { return Qfalse; } if (st_lookup(th->local_storage, id, 0)) { @@ -3043,13 +3047,16 @@ static VALUE rb_thread_variable_p(VALUE thread, VALUE key) { VALUE locals; + ID id = rb_check_id(&key); + + if (!id) return Qfalse; locals = rb_iv_get(thread, "locals"); if (!RHASH(locals)->ntbl) return Qfalse; - if (st_lookup(RHASH(locals)->ntbl, ID2SYM(rb_to_id(key)), 0)) { + if (st_lookup(RHASH(locals)->ntbl, ID2SYM(id), 0)) { return Qtrue; } |