Segfault with map operation on 1.8p5

Hi all,

The following snippet is a silly thing to do, but I
thought it might be worth mentioning. It segfaults on
1.8p5, but not 1.6.x:

a = [1,2,3,4]
h = {}
a.map{ |e| h[e] = a.shift }

Suse Linux 8.0, btw.

Regards,

Dan

···

Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

[ Segfault with map operation on 1.8p5 ]
Thu, 31 Jul 2003 11:41:33 +0900

The following snippet is a silly thing to do, but I
thought it might be worth mentioning. It segfaults on
1.8p5, but not 1.6.x:

a = [1,2,3,4]
h = {}
a.map{ |e| h[e] = a.shift }

This problem is solved by following patch for ruby 1.8.0 p5.

regards,

···


// SASADA Koichi @ namikilab.tuat.ac.jp
//
// Thanks to unak :slight_smile:

array.c.org Thu Jul 31 03:20:06 2003
+++ array.c Thu Jul 31 03:29:54 2003
@@ -1197,9 +1197,8 @@ rb_ary_collect(ary)
return rb_ary_new4(RARRAY(ary)->len, RARRAY(ary)->ptr);
}

  • len = RARRAY(ary)->len;
    collect = rb_ary_new2(len);
  • for (i=0; i<len; i++) {
  • for (i=0; i<RARRAY(ary)->len; i++) {
    rb_ary_push(collect, rb_yield(RARRAY(ary)->ptr[i]));
    }
    return collect;

Hello,

In message “Re: Segfault with map operation on 1.8p5”

This problem is solved by following patch for ruby 1.8.0 p5.

Hmmm, this?

— array.c 25 Jul 2003 05:36:46 -0000 1.128
+++ array.c 31 Jul 2003 04:03:48 -0000
@@ -1192,3 +1192,3 @@ rb_ary_collect(ary)
{

  • long len, i;
  • long i;
    VALUE collect;
    @@ -1199,5 +1199,4 @@ rb_ary_collect(ary)
  • len = RARRAY(ary)->len;
  • collect = rb_ary_new2(len);
  • for (i=0; i<len; i++) {
  • collect = rb_ary_new();
  • for (i = 0; i < RARRAY(ary)->len; i++) {
    rb_ary_push(collect, rb_yield(RARRAY(ary)->ptr[i]));

    Regards,
···

on Jul.31,2003 12:52:54, ko1@namikilab.tuat.ac.jp wrote:

U.Nakamura usa@osb.att.ne.jp

Hello,

···

In message “Re: Segfault with map operation on 1.8p5” on 03/07/31, “U.Nakamura” usa@osb.att.ne.jp writes:

In message “Re: Segfault with map operation on 1.8p5”
on Jul.31,2003 12:52:54, ko1@namikilab.tuat.ac.jp wrote:

This problem is solved by following patch for ruby 1.8.0 p5.

Hmmm, this?

Thank you guys for finding and fixing a bug.
Usa, could you commit this fix to the CVS?

						matz.