From 3fbc65d47fe8d446dde8fe77d3b76fb81f8ffba1 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 26 Jul 2011 16:05:27 +0000 Subject: [PATCH] * parse.y (rb_check_id): make the given name a symbol or a string. based on the second patch by Jeremy Evans at [ruby-core:38447] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32684 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ include/ruby/ruby.h | 2 +- object.c | 10 +++++----- parse.y | 4 +++- proc.c | 8 ++++---- variable.c | 6 +++--- vm_method.c | 10 +++++----- 7 files changed, 26 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index d4dc2971a4..cc2070a716 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Jul 27 01:05:23 2011 Nobuyoshi Nakada + + * parse.y (rb_check_id): make the given name a symbol or a string. + based on the second patch by Jeremy Evans at [ruby-core:38447] + Wed Jul 27 00:50:00 2011 Kenta Murata * ext/bigdecimal/lib/bigdecimal/util.rb (Rational#to_d): diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 6b106596f3..50b20845f1 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -1098,7 +1098,7 @@ ID rb_intern(const char*); ID rb_intern2(const char*, long); ID rb_intern_str(VALUE str); const char *rb_id2name(ID); -ID rb_check_id(VALUE); +ID rb_check_id(volatile VALUE *); ID rb_to_id(VALUE); VALUE rb_id2str(ID); diff --git a/object.c b/object.c index cad41e686c..6ddae2a592 100644 --- a/object.c +++ b/object.c @@ -1833,7 +1833,7 @@ rb_mod_const_defined(int argc, VALUE *argv, VALUE mod) else { rb_scan_args(argc, argv, "11", &name, &recur); } - if (!(id = rb_check_id(name))) { + if (!(id = rb_check_id(&name))) { if (rb_is_const_name(name)) { return Qfalse; } @@ -1870,7 +1870,7 @@ rb_mod_const_defined(int argc, VALUE *argv, VALUE mod) static VALUE rb_obj_ivar_get(VALUE obj, VALUE iv) { - ID id = rb_check_id(iv); + ID id = rb_check_id(&iv); if (!id) { if (rb_is_instance_name(iv)) { @@ -1938,7 +1938,7 @@ rb_obj_ivar_set(VALUE obj, VALUE iv, VALUE val) static VALUE rb_obj_ivar_defined(VALUE obj, VALUE iv) { - ID id = rb_check_id(iv); + ID id = rb_check_id(&iv); if (!id) { if (rb_is_instance_name(iv)) { @@ -1971,7 +1971,7 @@ rb_obj_ivar_defined(VALUE obj, VALUE iv) static VALUE rb_mod_cvar_get(VALUE obj, VALUE iv) { - ID id = rb_check_id(iv); + ID id = rb_check_id(&iv); if (!id) { if (rb_is_class_name(iv)) { @@ -2034,7 +2034,7 @@ rb_mod_cvar_set(VALUE obj, VALUE iv, VALUE val) static VALUE rb_mod_cvar_defined(VALUE obj, VALUE iv) { - ID id = rb_check_id(iv); + ID id = rb_check_id(&iv); if (!id) { if (rb_is_class_name(iv)) { diff --git a/parse.y b/parse.y index 315723287f..eb5f7fa5e6 100644 --- a/parse.y +++ b/parse.y @@ -10105,10 +10105,11 @@ rb_is_junk_id(ID id) } ID -rb_check_id(VALUE name) +rb_check_id(volatile VALUE *namep) { st_data_t id; VALUE tmp; + VALUE name = *namep; if (SYMBOL_P(name)) { return SYM2ID(name); @@ -10121,6 +10122,7 @@ rb_check_id(VALUE name) RSTRING_PTR(tmp)); } name = tmp; + *namep = name; } if (rb_enc_str_coderange(name) == ENC_CODERANGE_BROKEN) { diff --git a/proc.c b/proc.c index 5bddf94c1a..181c208f90 100644 --- a/proc.c +++ b/proc.c @@ -1198,7 +1198,7 @@ rb_method_name_error(VALUE klass, VALUE str) VALUE rb_obj_method(VALUE obj, VALUE vid) { - ID id = rb_check_id(vid); + ID id = rb_check_id(&vid); if (!id) { rb_method_name_error(CLASS_OF(obj), vid); } @@ -1215,7 +1215,7 @@ rb_obj_method(VALUE obj, VALUE vid) VALUE rb_obj_public_method(VALUE obj, VALUE vid) { - ID id = rb_check_id(vid); + ID id = rb_check_id(&vid); if (!id) { rb_method_name_error(CLASS_OF(obj), vid); } @@ -1256,7 +1256,7 @@ rb_obj_public_method(VALUE obj, VALUE vid) static VALUE rb_mod_instance_method(VALUE mod, VALUE vid) { - ID id = rb_check_id(vid); + ID id = rb_check_id(&vid); if (!id) { rb_method_name_error(mod, vid); } @@ -1273,7 +1273,7 @@ rb_mod_instance_method(VALUE mod, VALUE vid) static VALUE rb_mod_public_instance_method(VALUE mod, VALUE vid) { - ID id = rb_check_id(vid); + ID id = rb_check_id(&vid); if (!id) { rb_method_name_error(mod, vid); } diff --git a/variable.c b/variable.c index 8a34d2e49d..b3842c85c0 100644 --- a/variable.c +++ b/variable.c @@ -1299,7 +1299,7 @@ VALUE rb_obj_remove_instance_variable(VALUE obj, VALUE name) { VALUE val = Qnil; - const ID id = rb_check_id(name); + const ID id = rb_check_id(&name); st_data_t n, v; struct st_table *iv_index_tbl; st_data_t index; @@ -1685,7 +1685,7 @@ rb_public_const_get_at(VALUE klass, ID id) VALUE rb_mod_remove_const(VALUE mod, VALUE name) { - const ID id = rb_check_id(name); + const ID id = rb_check_id(&name); if (!id) { if (rb_is_const_name(name)) { @@ -2206,7 +2206,7 @@ rb_mod_class_variables(VALUE obj) VALUE rb_mod_remove_cvar(VALUE mod, VALUE name) { - const ID id = rb_check_id(name); + const ID id = rb_check_id(&name); st_data_t val, n = id; if (!id) { diff --git a/vm_method.c b/vm_method.c index 6e209f257f..927bbc10f1 100644 --- a/vm_method.c +++ b/vm_method.c @@ -727,7 +727,7 @@ rb_mod_undef_method(int argc, VALUE *argv, VALUE mod) static VALUE rb_mod_method_defined(VALUE mod, VALUE mid) { - ID id = rb_check_id(mid); + ID id = rb_check_id(&mid); if (!id || !rb_method_boundp(mod, id, 1)) { return Qfalse; } @@ -778,7 +778,7 @@ check_definition(VALUE mod, ID mid, rb_method_flag_t noex) static VALUE rb_mod_public_method_defined(VALUE mod, VALUE mid) { - ID id = rb_check_id(mid); + ID id = rb_check_id(&mid); if (!id) return Qfalse; return check_definition(mod, id, NOEX_PUBLIC); } @@ -812,7 +812,7 @@ rb_mod_public_method_defined(VALUE mod, VALUE mid) static VALUE rb_mod_private_method_defined(VALUE mod, VALUE mid) { - ID id = rb_check_id(mid); + ID id = rb_check_id(&mid); if (!id) return Qfalse; return check_definition(mod, id, NOEX_PRIVATE); } @@ -846,7 +846,7 @@ rb_mod_private_method_defined(VALUE mod, VALUE mid) static VALUE rb_mod_protected_method_defined(VALUE mod, VALUE mid) { - ID id = rb_check_id(mid); + ID id = rb_check_id(&mid); if (!id) return Qfalse; return check_definition(mod, id, NOEX_PROTECTED); } @@ -1259,7 +1259,7 @@ obj_respond_to(int argc, VALUE *argv, VALUE obj) ID id; rb_scan_args(argc, argv, "11", &mid, &priv); - if (!(id = rb_check_id(mid))) + if (!(id = rb_check_id(&mid))) return Qfalse; if (basic_obj_respond_to(obj, id, !RTEST(priv))) return Qtrue;