?????????????

??????????????????????????
????????????????????????
??????????????????????????
??????????????????????????
?????

???????
??????????????seg fault????????
??????return??????ruby?????????
?????seg fault?????????????????
????????return ??????????
??1?
?ary.length=3,000,000
?result=calc6(ary, etc)
?p result[0]  # => segmentation fault
??2?
?ary.length=1,000,000 #??????????OK???
?result=calc6(ary, etc)
?p result[0]  # => value?            <= ?
   p result[-1]  # => [index, value]  <= ??????

???????
seg fault????????return???????????
???
???
?result=calc6(??)
?p result.length  # => 0

?????????????????????????
rhg???????????????????volatile?
?????????????????????????
?????????...
??????????????????????
???????????????????
???? ?????? ???

 
2007?04?08? 16:23 ? "Nobuyoshi Nakada" <nobu / ruby-lang.org>????:
>??????
>
>At Sun, 08 Apr 2007 13:35:28 +0900 (JST),
>ysk wrote in [ruby-ext:02319]:
>> VALUE?????????????
>> rb_gc_mark???????????Ruby??
>> ???????????????
>
>rb_gc_mark()?mark?????????????????
>
>?????result?????????????ptr?????????
>?????????????
>
>static VALUE
>si_calc6(self, ary1d, x0, y0, a)
>    VALUE self;
>    VALUE ary1d;
>    VALUE x0;
>    VALUE y0;
>    VALUE a;
>{
>    unsigned int i;
>    /* ???c??????? */
>    int x0c = NUM2INT(x0);
>    int y0c = NUM2INT(y0);
>    double ac = NUM2DBL(a);
>    long length = RARRAY(ary1d)->len;
>    VALUE result = rb_ary_new2(length);
>    VALUE *items = RARRAY_PTR(result);
>    VALUE klass = RBASIC(result)->klass;
>
>    VALUE item;
>    VALUE t;
>    VALUE xt;
>    double y;
>
>    RBASIC(result)->klass = 0;
>    for (i = 0; i < length; i++){
>        t = INT2FIX(i + x0c);
>        y = NUM2DBL(rb_ary_entry(ary1d, i));
>        xt = rb_float_new(y0c - (y * ac));
>        item = rb_ary_new3(2, t, xt);
>        items[i] = item;
>    }
>    RBASIC(result)->klass = klass;
>
>    return result;
>}
>
>-- 
>--- ????Bug????
>--- ?????Bug?????
>    ?? ??
>
>