From: "Masahiro Kanai (CanI)" Date: 2009-09-30T01:04:17+09:00 Subject: [ruby-dev:39406] Re: Removing constant-able macros inside of the loop. 金井です。 2009年9月29日10:08 Yukihiro Matsumoto : > まつもと ゆきひろです > > In message "Re: [ruby-dev:39392] Re: Removing constant-able macros inside > of the loop." > on Mon, 28 Sep 2009 23:31:45 +0900, "Masahiro Kanai (CanI)" > writes: > > |再チェックした結果、rb_str_{start, end}_with, rb_ary_timesが > |rb_check_string_typeを実行する可能性がありましたが、 > |rb_ary_timesにおいては、RSTRING_PTR()の位置を工夫することで > |対応が可能でした。(既に対応されてました。) > | > | > |修正後のパッチは、以下の通りです。 > > 試してみようと思いますが、残念ながらfoldされていてパッチが壊 > れてます。私が手で修正することはもちろん可能ですが、今後のた > めにも、ぜひfoldしないようにして再投稿していただけるとありが > たいです。 申し訳ありませんでした。 設定を確認して、再添付しました。 > あと、ChangeLogエントリもいただけるとすごくよいですが、こち > らは必須ではありません。 過去のChangeLogや、以下のページのChangeLogの項目を参考にしながら書いてみました。 拙い文章ですが・・・ * array.c (rb_ary_{times, shuffle_bang, sample}): removing constant-able macros inside of the loop. a patch from Masahiro Kanai (CanI) at [ruby-dev:number]. It was found out and fixed at Security and Programming camp 2009. * string.c (rb_str_{times, split_m}): ditto. * struct.c (rb_struct_{getmember, set, aref_id, aset_id}, {make, inspect}_struct, recursive_{equal, hash, eql}): ditto. パッチは、以下です。 --- array.c (revision 25052) +++ array.c (working copy) @@ -2708,8 +2708,8 @@ static VALUE rb_ary_times(VALUE ary, VALUE times) { - VALUE ary2, tmp; - long i, len; + VALUE ary2, tmp, *ptr, *ptr2; + long i, t, len; tmp = rb_check_string_type(times); if (!NIL_P(tmp)) { @@ -2732,8 +2732,11 @@ ary2 = ary_new(rb_obj_class(ary), len); ARY_SET_LEN(ary2, len); - for (i=0; i= 0) { regs = RMATCH_REGS(rb_backref_get()); if (start == end && BEG(0) == END(0)) { - if (!RSTRING_PTR(str)) { + if (!ptr) { rb_ary_push(result, rb_str_new("", 0)); break; } else if (last_null == 1) { rb_ary_push(result, rb_str_subseq(str, beg, - rb_enc_fast_mbclen(RSTRING_PTR(str)+beg, - RSTRING_END(str), + rb_enc_fast_mbclen(ptr+beg, + ptr+len, enc))); beg = start; } else { - if (RSTRING_PTR(str)+start == RSTRING_END(str)) + if (ptr+start == ptr+len) start++; else - start += rb_enc_fast_mbclen(RSTRING_PTR(str)+start,RSTRING_END(str),enc); + start += rb_enc_fast_mbclen(ptr+start,ptr+len,enc); last_null = 1; continue; } --- struct.c (revision 25052) +++ struct.c (working copy) @@ -98,14 +98,17 @@ VALUE rb_struct_getmember(VALUE obj, ID id) { - VALUE members, slot; - long i; + VALUE members, slot, *ptr, *ptr_members; + long i, len; + ptr = RSTRUCT_PTR(obj); members = rb_struct_members(obj); + ptr_members = RARRAY_PTR(members); slot = ID2SYM(id); - for (i=0; i"); OBJ_INFECT(str, s); @@ -588,14 +600,16 @@ static VALUE rb_struct_aref_id(VALUE s, ID id) { - VALUE members; + VALUE *ptr, members, *ptr_members; long i, len; + ptr = RSTRUCT_PTR(s); members = rb_struct_members(s); + ptr_members = RARRAY_PTR(members); len = RARRAY_LEN(members); for (i=0; i