Skip to content

Commit

Permalink
error.c: receiver in NameError
Browse files Browse the repository at this point in the history
* error.c (rb_name_err_new): store the receiver directly.
* error.c (name_err_receiver): return directly stored receiver.
  [Feature ruby#10881]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52322 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Oct 28, 2015
1 parent 72ff61f commit a4f838c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
7 changes: 6 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
9 changes: 8 additions & 1 deletion error.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a4f838c

Please sign in to comment.