diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-10-28 06:36:13 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-10-28 06:36:13 +0000 |
commit | a4f838c742dc758de8dec0c002e20d22c791b85a (patch) | |
tree | ce5e151c9bea826b4b09c2380e995d640e6c25ef | |
parent | 72ff61f4a8ae7a8bf05b0bd6f91b3b290645627c (diff) |
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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52322 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | error.c | 9 | ||||
-rw-r--r-- | internal.h | 1 | ||||
-rw-r--r-- | variable.c | 2 |
4 files changed, 16 insertions, 3 deletions
@@ -1,4 +1,9 @@ -Wed Oct 28 15:24:09 2015 Nobuyoshi Nakada <nobu@ruby-lang.org> +Wed Oct 28 15:36:11 2015 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * 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. @@ -662,6 +662,7 @@ static VALUE rb_eNOERROR; 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, VALUE method) 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 str) 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) 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"); diff --git a/internal.h b/internal.h index b5f40987f3..290bdb1cc4 100644 --- a/internal.h +++ b/internal.h @@ -1163,6 +1163,7 @@ extern rb_encoding OnigEncodingUTF_8; 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; diff --git a/variable.c b/variable.c index 97c0932e34..7f3b777f6e 100644 --- a/variable.c +++ b/variable.c @@ -1224,7 +1224,7 @@ gen_ivtbl_count(const struct gen_ivtbl *ivtbl) return n; } -static VALUE +VALUE rb_ivar_lookup(VALUE obj, ID id, VALUE undef) { VALUE val, *ptr; |