ruby-changes:28752
From: nobu <ko1@a...>
Date: Sat, 18 May 2013 11:03:16 +0900 (JST)
Subject: [ruby-changes:28752] nobu:r40804 (trunk): enumerator.c: append_method
nobu 2013-05-18 11:03:07 +0900 (Sat, 18 May 2013) New Revision: 40804 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40804 Log: enumerator.c: append_method * enumerator.c (append_method): extract from inspect_enumerator(). Modified files: trunk/ChangeLog trunk/enumerator.c Index: ChangeLog =================================================================== --- ChangeLog (revision 40803) +++ ChangeLog (revision 40804) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat May 18 11:03:05 2013 Nobuyoshi Nakada <nobu@r...> + + * enumerator.c (append_method): extract from inspect_enumerator(). + Sat May 18 09:00:32 2013 Tanaka Akira <akr@f...> * ext/socket/mkconstants.rb (INTEGER2VALUE): Use LONG2FIX if possible. Index: enumerator.c =================================================================== --- enumerator.c (revision 40803) +++ enumerator.c (revision 40804) @@ -874,13 +874,14 @@ enumerator_rewind(VALUE obj) https://github.com/ruby/ruby/blob/trunk/enumerator.c#L874 return obj; } +static VALUE append_method(VALUE obj, VALUE str, ID default_method, VALUE default_args); + static VALUE inspect_enumerator(VALUE obj, VALUE dummy, int recur) { struct enumerator *e; const char *cname; - VALUE eobj, eargs, str, method; - int tainted, untrusted; + VALUE eobj, str; TypedData_Get_Struct(obj, struct enumerator, &enumerator_data_type, e); @@ -901,16 +902,26 @@ inspect_enumerator(VALUE obj, VALUE dumm https://github.com/ruby/ruby/blob/trunk/enumerator.c#L902 eobj = e->obj; } - tainted = OBJ_TAINTED(eobj); - untrusted = OBJ_UNTRUSTED(eobj); - /* (1..100).each_cons(2) => "#<Enumerator: 1..100:each_cons(2)>" */ str = rb_sprintf("#<%s: ", cname); - rb_str_concat(str, rb_inspect(eobj)); + rb_str_append(str, rb_inspect(eobj)); + OBJ_INFECT(str, eobj); + append_method(obj, str, e->meth, e->args); + + rb_str_buf_cat2(str, ">"); + + return str; +} + +static VALUE +append_method(VALUE obj, VALUE str, ID default_method, VALUE default_args) +{ + VALUE method, eargs; + method = rb_attr_get(obj, id_method); if (NIL_P(method)) { rb_str_buf_cat2(str, ":"); - rb_str_buf_cat2(str, rb_id2name(e->meth)); + rb_str_buf_cat2(str, rb_id2name(default_method)); } else if (method != Qfalse) { Check_Type(method, T_SYMBOL); @@ -920,7 +931,7 @@ inspect_enumerator(VALUE obj, VALUE dumm https://github.com/ruby/ruby/blob/trunk/enumerator.c#L931 eargs = rb_attr_get(obj, id_arguments); if (NIL_P(eargs)) { - eargs = e->args; + eargs = default_args; } if (eargs != Qfalse) { long argc = RARRAY_LEN(eargs); @@ -934,17 +945,11 @@ inspect_enumerator(VALUE obj, VALUE dumm https://github.com/ruby/ruby/blob/trunk/enumerator.c#L945 rb_str_concat(str, rb_inspect(arg)); rb_str_buf_cat2(str, argc > 0 ? ", " : ")"); - - if (OBJ_TAINTED(arg)) tainted = TRUE; - if (OBJ_UNTRUSTED(arg)) untrusted = TRUE; + OBJ_INFECT(str, arg); } } } - rb_str_buf_cat2(str, ">"); - - if (tainted) OBJ_TAINT(str); - if (untrusted) OBJ_UNTRUST(str); return str; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/