ruby-changes:40241
From: nobu <ko1@a...>
Date: Wed, 28 Oct 2015 15:36:21 +0900 (JST)
Subject: [ruby-changes:40241] nobu:r52322 (trunk): error.c: receiver in NameError
nobu 2015-10-28 15:36:13 +0900 (Wed, 28 Oct 2015) New Revision: 52322 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52322 Log: error.c: receiver in NameError * error.c (rb_name_err_new): store the receiver directly. * error.c (name_err_receiver): return directly stored receiver. [Feature #10881] Modified files: trunk/ChangeLog trunk/error.c trunk/internal.h trunk/variable.c Index: ChangeLog =================================================================== --- ChangeLog (revision 52321) +++ ChangeLog (revision 52322) @@ -1,4 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 -Wed Oct 28 15:24:09 2015 Nobuyoshi Nakada <nobu@r...> +Wed Oct 28 15:36:11 2015 Nobuyoshi Nakada <nobu@r...> + + * error.c (rb_name_err_new): store the receiver directly. + + * error.c (name_err_receiver): return directly stored receiver. + [Feature #10881] * error.c (name_err_mesg_to_str): quote the name if unprintable. Index: variable.c =================================================================== --- variable.c (revision 52321) +++ variable.c (revision 52322) @@ -1224,7 +1224,7 @@ gen_ivtbl_count(const struct gen_ivtbl * https://github.com/ruby/ruby/blob/trunk/variable.c#L1224 return n; } -static VALUE +VALUE rb_ivar_lookup(VALUE obj, ID id, VALUE undef) { VALUE val, *ptr; Index: error.c =================================================================== --- error.c (revision 52321) +++ error.c (revision 52322) @@ -662,6 +662,7 @@ static VALUE rb_eNOERROR; https://github.com/ruby/ruby/blob/trunk/error.c#L662 static ID id_new, id_cause, id_message, id_backtrace; static ID id_name, id_args, id_Errno, id_errno, id_i_path; +static ID id_receiver; extern ID ruby_static_id_status; #define id_bt idBt #define id_bt_locations idBt_locations @@ -1196,6 +1197,7 @@ rb_name_err_new(VALUE mesg, VALUE recv, https://github.com/ruby/ruby/blob/trunk/error.c#L1197 rb_ivar_set(exc, id_mesg, rb_name_err_mesg_new(mesg, recv, method)); rb_ivar_set(exc, id_bt, Qnil); rb_ivar_set(exc, id_name, method); + rb_ivar_set(exc, id_receiver, recv); return exc; } @@ -1297,8 +1299,12 @@ name_err_mesg_load(VALUE klass, VALUE st https://github.com/ruby/ruby/blob/trunk/error.c#L1299 static VALUE name_err_receiver(VALUE self) { - VALUE *ptr, mesg = rb_attr_get(self, id_mesg); + VALUE *ptr, recv, mesg; + recv = rb_ivar_lookup(self, id_receiver, Qundef); + if (recv != Qundef) return recv; + + mesg = rb_attr_get(self, id_mesg); if (!rb_typeddata_is_kind_of(mesg, &name_err_mesg_data_type)) { rb_raise(rb_eArgError, "no receiver is available"); } @@ -1969,6 +1975,7 @@ Init_Exception(void) https://github.com/ruby/ruby/blob/trunk/error.c#L1975 id_backtrace = rb_intern_const("backtrace"); id_name = rb_intern_const("name"); id_args = rb_intern_const("args"); + id_receiver = rb_intern_const("receiver"); id_Errno = rb_intern_const("Errno"); id_errno = rb_intern_const("errno"); id_i_path = rb_intern_const("@path"); Index: internal.h =================================================================== --- internal.h (revision 52321) +++ internal.h (revision 52322) @@ -1163,6 +1163,7 @@ extern rb_encoding OnigEncodingUTF_8; https://github.com/ruby/ruby/blob/trunk/internal.h#L1163 size_t rb_generic_ivar_memsize(VALUE); VALUE rb_search_class_path(VALUE); VALUE rb_attr_delete(VALUE, ID); +VALUE rb_ivar_lookup(VALUE obj, ID id, VALUE undef); /* version.c */ extern VALUE ruby_engine_name; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/