ruby-changes:28506
From: nobu <ko1@a...>
Date: Thu, 2 May 2013 17:31:06 +0900 (JST)
Subject: [ruby-changes:28506] nobu:r40558 (trunk): variable.c: move warnings to rb_ivar_get
nobu 2013-05-02 17:30:56 +0900 (Thu, 02 May 2013) New Revision: 40558 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40558 Log: variable.c: move warnings to rb_ivar_get * variable.c (generic_ivar_get, ivar_get): return undef value instead of Qnil with warnings, for uninitialized instance variable. * variable.c (rb_ivar_get): warn for uninitialized instance variable here. Modified files: trunk/variable.c Index: variable.c =================================================================== --- variable.c (revision 40557) +++ variable.c (revision 40558) @@ -908,7 +908,7 @@ rb_generic_ivar_table(VALUE obj) https://github.com/ruby/ruby/blob/trunk/variable.c#L908 } static VALUE -generic_ivar_get(VALUE obj, ID id, int warn) +generic_ivar_get(VALUE obj, ID id, VALUE undef) { st_data_t tbl, val; @@ -919,10 +919,7 @@ generic_ivar_get(VALUE obj, ID id, int w https://github.com/ruby/ruby/blob/trunk/variable.c#L919 } } } - if (warn) { - rb_warning("instance variable %"PRIsVALUE" not initialized", QUOTE_ID(id)); - } - return Qnil; + return undef; } static void @@ -1071,7 +1068,7 @@ rb_copy_generic_ivar(VALUE clone, VALUE https://github.com/ruby/ruby/blob/trunk/variable.c#L1068 } static VALUE -ivar_get(VALUE obj, ID id, int warn) +rb_ivar_lookup(VALUE obj, ID id, VALUE undef) { VALUE val, *ptr; struct st_table *iv_index_tbl; @@ -1099,25 +1096,28 @@ ivar_get(VALUE obj, ID id, int warn) https://github.com/ruby/ruby/blob/trunk/variable.c#L1096 default: generic: if (FL_TEST(obj, FL_EXIVAR) || rb_special_const_p(obj)) - return generic_ivar_get(obj, id, warn); + return generic_ivar_get(obj, id, undef); break; } - if (warn) { - rb_warning("instance variable %"PRIsVALUE" not initialized", QUOTE_ID(id)); - } - return Qnil; + return undef; } VALUE rb_ivar_get(VALUE obj, ID id) { - return ivar_get(obj, id, TRUE); + VALUE iv = rb_ivar_lookup(obj, id, Qundef); + + if (iv == Qundef) { + rb_warning("instance variable %"PRIsVALUE" not initialized", QUOTE_ID(id)); + iv = Qnil; + } + return iv; } VALUE rb_attr_get(VALUE obj, ID id) { - return ivar_get(obj, id, FALSE); + return rb_ivar_lookup(obj, id, Qnil); } VALUE -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/