summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--error.c9
-rw-r--r--internal.h1
-rw-r--r--variable.c2
4 files changed, 16 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 94da742012..05b58fc527 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/error.c b/error.c
index 0a84937d78..1db0e74a09 100644
--- a/error.c
+++ b/error.c
@@ -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;