1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2015-10-28 06:36:13 +00:00
parent 72ff61f4a8
commit a4f838c742
4 changed files with 16 additions and 3 deletions

View file

@ -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.

View file

@ -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");

View file

@ -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;

View file

@ -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;